在R markdown pdf文档的右上角插入徽标

Dan*_*l_D 17 pdf yaml r knitr r-markdown

我开始使用R markdown,我想logo.png在每页的右上角创建一个包含公司图像的新报告.

有没有办法在YAML部分编码,或者需要在R块部分完成?

tmp*_*345 23

您可以使用includesyaml中的选项指定乳胶头的自定义添加.yaml部分看起来像

---
output: 
    pdf_document:
      keep_tex: true
      includes:
          in_header: header.tex
---
Run Code Online (Sandbox Code Playgroud)

并且您需要保存一个单独的文件header.tex,使用以下定义您的公司徽标,如下所示:

\usepackage{fancyhdr}
\pagestyle{fancy}
\rhead{\includegraphics[width = .05\textwidth]{logo.png}}
Run Code Online (Sandbox Code Playgroud)

在这里,我使用fancyhdr乳胶包添加徽标,但还有其他潜在的解决方案.请参阅此处了解更多选项.

  • 我建议你不要使用完整路径,特别是在Windows下.将所有内容放在同一目录中,并始终在所有位置使用相对路径. (3认同)

Dan*_*l_D 19

好的,我找到了解决方案:

---
title:
header-includes: 
   \usepackage{graphicx}
   \usepackage{fancyhdr}
   \pagestyle{fancy}
   \setlength\headheight{28pt}
   \fancyhead[L]{\includegraphics[width=5cm]{GPIM_Logo_300x85.png}}
   \fancyfoot[LE,RO]{GPIM}
output: pdf_document
---
Run Code Online (Sandbox Code Playgroud)

  • `header-includes:\ usepackage {fancyhdr}\usepackage {graphicx}\usepackage {eurosym}\usepackage {booktabs,xcolor}\pagestyle {fancy}\fancyhf {}\addtolength {\ headheight} {1.0cm}\rhead {MainSky压力测试报告 - \今天}\lhead {\ includegraphics [width = 6cm] {path&logo}}\rfoot {Page\thepage}\fancypagestyle {plain} {\ pagestyle {fancy}}输出:pdf_document` (7认同)
  • 这看起来很不错,但它并没有将图像添加到我的第一页; 有人知道如何强制吗? (3认同)

小智 14

我已尝试过在这里和其他论坛中提出的许多解决方案,其中没有一个有效.我终于找到了适合我的解决方案.

---
title: 'Fancy Title Here'
author: "Diego"
date: "today"
output:
  pdf_document:
    toc: yes
header-includes:
    - \usepackage{fancyhdr}
---
\addtolength{\headheight}{1.0cm} % make more space for the header
\pagestyle{fancyplain} % use fancy for all pages except chapter start
\rhead{\includegraphics[height=1.2cm]{C:/Path/to/logo/logo}} % right logo
\renewcommand{\headrulewidth}{0pt} % remove rule below header
Run Code Online (Sandbox Code Playgroud)

我希望以与帮助我相同的方式帮助某人.

  • 试过这个,标志出现,但它出现在每一页上。我只需要在第一页 (2认同)