向使用RMarkdown创建的PDF添加横幅

zed5wv10  于 2023-10-13  发布在  其他
关注(0)|答案(2)|浏览(104)

我试图使用图像作为RMarkdown创建的PDF顶部的横幅。我有一个Tex文件,它使用的代码来自here。修改后的Tex文件(Banner.Tex)如下所示

\usepackage{fancyhdr}
\pagestyle{fancy}
\usepackage{tikz}
\fancyhead{%
  \begin{tikzpicture}[remember picture, overlay, outer sep=0pt, inner sep=0pt]
   \node at (0,4) {\includegraphics{ImageFromForm.png}};
     \end{tikzpicture}
}
\fancypagestyle{plain}[fancy]{}
\renewcommand{\headrulewidth}{0pt}
\setlength{\headheight}{4cm}

RMarkdown脚本看起来像-

---
title: Test Document
output: 
  pdf_document:
    keep_tex: true
header-includes:
   - \include{Banner} 
---

    ## R Markdown
    
    This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see <http://rmarkdown.rstudio.com>.
```{r cars}
summary(cars)

ImageFromForm.png(来自Tex文件)打印,但存在重叠(如下)。它看起来不是把它拉伸到页面宽度,而是再次打印出来。我不理解代码中的节点。有人能给我指个路吗?任何帮助都是值得推荐的。谢谢x1c 0d1x
gorkyyrv

gorkyyrv1#

两个问题:

  • 你不应该在文档开始之前使用\include。使用\input代替
---
title: Test Document
output: 
  pdf_document:
    keep_tex: true
header-includes:
   - \input{Banner} 
---

    ## R Markdown
    
    This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see <http://rmarkdown.rstudio.com>.
```{r cars}
summary(cars)

* 使用`\fancyhead{...}`可以同时设置左、中、右标题。如果您只想包含一次图像,请选择要修改的图像。例如,对于中心的Header:

\usepackage{fancyhdr}
\pagestyle{fancy}
\usepackage{tikz}
\fancyhead[c]{%
\begin{tikzpicture}[remember picture, overlay, outer sep=0pt, inner sep=0pt]
\node at (0,4) {\includegraphics{example-image-duck}};
\end{tikzpicture}
}
\fancypagestyle{plain}[fancy]{}
\renewcommand{\headrulewidth}{0pt}
\setlength{\headheight}{4cm}


![](https://i.stack.imgur.com/GWR0U.png)
qv7cva1a

qv7cva1a2#

感谢您发送编修。我还可以通过在标题中指定- \usepackage{wallpaper} - \ULCornerWallPaper{1}{ImageFromForm.png}来实现这一点。我只想在第一页的横幅,所以我使用\newpage和\ClearWallPaper稍后在文档中摆脱横幅。
谢谢你对节点的解释。非常有帮助!

相关问题