在r-markdown PDF文档中将图像右对齐到页面边框

时间:2017-12-08 22:55:27

标签: r latex r-markdown

我希望为通过rmarkdown呈现的PDF文档创建一个封面,其中包含一个图像cover.png,我已经右对齐页面边框。在我下面的YAML中,我目前以页面为中心。如何将其移至右侧?

---
title: \vspace{3cm} \fontsize{1.5cm}{2cm}\selectfont Report Title
header-includes:
- \usepackage{titling}
- \pretitle{\begin{center}\includegraphics[width=20cm]{cover.png}\\[\bigskipamount]}
- \posttitle{\end{center}}
- \pagenumbering{gobble}
output:
  pdf_document:
    latex_engine: xelatex
mainfont: Calibri
editor_options:
  chunk_output_type: console
---

2 个答案:

答案 0 :(得分:0)

您可以在Rmd文档中包含原始乳胶,将原始图片放置在您想要的位置。例如:

---
title: Dogs are the best
output:
  pdf_document:
header-includes: 
  - \usepackage{graphicx}
---

```{r include = FALSE}
library(httr)
dog <- "https://www.cesarsway.com/sites/newcesarsway/files/styles/large_article_preview/public/Common-dog-behaviors-explained.jpg"
GET(dog, write_disk("dog.jpg", overwrite = TRUE))
```

\begin{figure}
  \raggedleft
  \begin{minipage}{5cm}
  \includegraphics[width = 5cm]{dog.jpg}
  \end{minipage}
\end{figure}

\pagebreak

## Introduction

Dogs dogs dogs

结果是:

enter image description here

答案 1 :(得分:0)

我必须在\hspace*{2cm}之前添加\includegraphics,以便将其移动到我想要的最右边。我使用反复试验将其移动到页面的边缘。我从here得到了答案。

---
title: \vspace{3cm} \fontsize{1.5cm}{2cm}\selectfont Report Title
header-includes:
- \usepackage{titling}
- \pretitle{\begin{center}\hspace*{2cm}\includegraphics[width=20cm]{cover.png}\\[\bigskipamount]}
- \posttitle{\end{center}}
- \pagenumbering{gobble}
output:
  pdf_document:
    latex_engine: xelatex
mainfont: Calibri
editor_options:
  chunk_output_type: console
---