【问题标题】:Right-aligning an image to the page border in a r-markdown PDF document将图像右对齐到 r-markdown PDF 文档中的页面边框
【发布时间】:2017-12-08 22:55:27
【问题描述】:

我希望为通过 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
---

【问题讨论】:

    标签: r latex r-markdown


    【解决方案1】:

    你可以在你的 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
    

    结果:

    【讨论】:

    • 感谢您的回答,克里斯。但是,我确实想要标题上方的图片。我发现在\includegraphics 之前添加\hspace*{2cm} 就可以了。
    • 答案是您可以用来在标题页上右对齐图像的功能的一个最小示例
    【解决方案2】:

    我必须在\includegraphics 之前添加\hspace*{2cm} 才能将它移到我想要的最右边。我使用反复试验将其移动到页面的边缘。我从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
    ---
    

    【讨论】:

      猜你喜欢
      • 2016-12-09
      • 1970-01-01
      • 1970-01-01
      • 2014-10-18
      • 1970-01-01
      • 2017-01-03
      • 2017-10-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多