在Rmarkdown生成的PDF首页添加脚注与Logo时遇问题求助
解决方案
正确实现代码(同时支持Logo+作者脚注+无重叠)
--- title: "My report" date: November 4th, 2022 documentclass: report keep_tex: true header-includes: - \usepackage{titling} - \usepackage{graphicx} # 定制标题区域:插入Logo + 标题格式 - \pretitle{\begin{center} \includegraphics[width=2in, height=2in]{logo.png}\\[1em] \LARGE} - \posttitle{\end{center}\vspace{1em}} # 定制作者区域:带脚注 + 格式 + 间距 - \preauthor{\begin{center}\large} - \author{Author 1\protect\footnote{Writing, Research, Editing}} - \postauthor{\end{center}\vspace{1em}} # 定制日期区域格式 - \predate{\begin{center}\large} - \postdate{\end{center}} output: pdf_document --- 正文测试内容。
关键修复点说明
解决LaTeX编译错误:
在\author中使用\protect\footnote而非markdown脚注语法。因为LaTeX宏(如\author)展开时会解析内部命令,\protect可以避免脚注命令被错误拆分,解决Argument of \reserved@a has an extra }的编译报错。解决内容重叠问题:
通过\\[1em](Logo与标题间)和\vspace{1em}(标题与作者、作者与日期间)手动添加垂直间距,确保各元素排版不重叠。同时用titling包的pre*/post*系列命令统一标题区域的对齐和字号格式。Logo插入逻辑:
借助titling包的\pretitle在标题前插入Logo,graphicx包提供图片支持,通过width/height控制Logo尺寸,\\[1em]调整Logo与标题的间距。
无Logo场景简化代码
如果不需要Logo,仅保留作者脚注和排版修复,可简化为:
--- title: "My report" date: November 4th, 2022 documentclass: report keep_tex: true header-includes: - \usepackage{titling} - \preauthor{\begin{center}\large} - \author{Author 1\protect\footnote{Writing, Research, Editing}} - \postauthor{\end{center}\vspace{1em}} - \predate{\begin{center}\large} - \postdate{\end{center}} output: pdf_document --- 正文测试内容。
内容的提问来源于stack exchange,提问作者raphael_ldl
相关产品推荐
相关产品推荐

