rmarkdown format letter how to align names and signatures
I am using rmarkdown to generate formal letters that include 2 signature positions. I would like the names and positions to be at the left and right margin of the document but with left aligned. The names and positions are of different lengths so \hfill
and \hspace{110pt}
does not do the job. Above the name the signature should be centre aligned. I am using a table to do this like
---
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
What I would like is that the names and positions are left aligned each underneath the other and the signature centered above like this
You could use the varwidth
package like this:
---
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}
You can try this.
Find out a better \hspace
for your pics...
---
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