I would like to include a table with 2 columns including images and text (image descriptions) in PDF report compiled with R markdown. In doing so, I have the following requi
For your latex approach:
vertical alignment: of column 2 not working correctly
you get your desired alignment by combining a p column (instead of the m column you used) and a top aligned image. For the top aligned image add \usepackage[export]{adjustbox}
to your header includes and ,valign=t
to the image options
image path: can not include abbreviated image paths
Using image paths is easy with \graphicspath{{./older/Subfolder/}}
in your header includes
other comments:
using [H]
as floating specifier is usually not a good idea. This basically guarantees a suboptimal image placement. Instead use [htbp]
to ensure that latex find the best possible locatiosn for your image.
don't use \toprule
within the table, that's what \midrule
is made for
don't use \hline
when you load the booktabs
package which provides alternatives with superior spacing
\documentclass{article}
\usepackage{booktabs}
\usepackage{graphicx}
\usepackage{array}
\usepackage[export]{adjustbox}
\newcolumntype{L}[1]{>{\raggedright\arraybackslash}p{#1}}
\graphicspath{{./older/Subfolder/}}
\begin{document}
\begin{table}[htbp]
\centering
\caption{My caption}
\label{foo}
\begin{tabular}{@{} L{6cm} L{8.5cm} @{}}
\toprule
Image & Description \\
\midrule
\includegraphics[width=60mm,valign=t]{example-image-duck} &
\textbf{Lorem ipsum dolor sit amet} [@R-base] \linebreak mauris mauris sollicitudin malesuada amet.\\
\midrule
\includegraphics[width=60mm,valign=t]{example-image-duck} &
\textbf{Lorem ipsum dolor} [@R-bookdown]\linebreak sit amet, mauris mauris sollicitudin malesuada amet. \\
\bottomrule
\end{tabular}
\end{table}
\ref{foo}
\end{document}