rmarkdown format letter 如何对齐名字和签名

rmarkdown format letter how to align names and signatures

我正在使用 rmarkdown 生成包含 2 个签名位置的正式信件。我希望名称和位置位于文档的左右边缘,但左对齐。名称和位置的长度不同,因此 \hfill\hspace{110pt} 无法完成这项工作。在名称上方,签名应居中对齐。我正在使用 table 来执行此操作,例如

    ---
title: ""
output: pdf_document
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)

df<-data.frame(name=c("Tom Short", "Gagagagagagaga Long"), position=c("CEO", "Chief Technology Evangelist and Much Much More"))

```


\
\


![](JohnHancocksSignature.png){width=25%} \hfill ![](JohnHancocksSignature.png){width=25%} 

\
\begingroup
\noindent
\begin{tabular}{@{}lll@{}}
Nina Static & \hspace{110pt} & `r df$name[1]` \
Chief Static & \hspace{110pt} & `r  df$position[1]`\
\end{tabular}
\endgroup

\
\
\
\
\
\
![](JohnHancocksSignature.png){width=25%} \hfill ![](JohnHancocksSignature.png){width=25%} 


\begingroup
\noindent
\begin{tabular}{@{}lll@{}}
Nina Static & \hspace{110pt} & `r df$name[2]` \
Chief Static & \hspace{110pt} & `r  df$position[2]`\
\end{tabular}
\endgroup

我想要的是姓名和职位在下方左对齐,签名在上方居中,就像这样

你可以试试这个。

为您的照片找到更好的 \hspace...

---
title: "Untitled"
header-includes:
- \usepackage{graphicx}
output: pdf_document
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)

df<-data.frame(name=c("Tom Short", "Gagagagagagaga Long"), position=c("CEO", "Chief Technology Evangelist and Much Much More"))

```


\
\


\includegraphics[height=2.5cm]{your_pic.png} \hspace{4.5cm} \includegraphics[height=2.5cm]{your_pic.png}

\
\begingroup
\noindent
\begin{tabular}{@{}lll@{}}
Nina Static & \hspace{110pt} & `r df$name[1]` \
Chief Static & \hspace{110pt} & `r  df$position[1]`\
\end{tabular}
\endgroup

\
\
\
\
\
\
\includegraphics[height=2.5cm]{your_pic.png} \hspace{4.6cm}  \includegraphics[height=2.5cm]{your_pic.png}


\begingroup
\noindent
\begin{tabular}{@{}lll@{}}
Nina Static & \hspace{110pt} & `r df$name[2]` \
Chief Static & \hspace{110pt} & `r  df$position[2]`\
\end{tabular}
\endgroup

您可以像这样使用 varwidth 包:

---
title: ""
output: 
  pdf_document:
    keep_tex: true
header-includes:
  - \usepackage{varwidth}
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)

df<-data.frame(name=c("Tom Short", "Gagagagagagaga Long"), position=c("CEO", "Chief Technology Evangelist and Much Much More"))

```


\begin{varwidth}{.5\linewidth}
\centering\includegraphics[width=3cm]{example-image-duck}
\medskip

\begin{varwidth}{\linewidth}
Nina Static

Chief static
\end{varwidth}
\end{varwidth}
\hfill
\begin{varwidth}{.5\linewidth}
\centering\includegraphics[width=3cm]{example-image-duck}
\medskip

\begin{varwidth}{\linewidth}
`r df$name[1]`

`r  df$position[1]`
\end{varwidth}
\end{varwidth}

\begin{varwidth}{.5\linewidth}
\centering\includegraphics[width=3cm]{example-image-duck}
\medskip

\begin{varwidth}{\linewidth}
Nina Static

Chief static
\end{varwidth}
\end{varwidth}
\hfill
\begin{varwidth}{.5\linewidth}
\centering\includegraphics[width=3cm]{example-image-duck}
\medskip

\begin{varwidth}{\linewidth}
`r df$name[2]`

`r  df$position[2]`
\end{varwidth}
\end{varwidth}