How to align picture top left in a table?
The adjustbox is what's needed:
\begin{tabular}{ll}
Some text & \adjustbox{valign=t}{\includegraphics[height=3cm,width=4cm]{p}}\\
...
\end{tabular}
With valign=t
the picture is lowered in such a way that its final height is similar to the height of the surrounding text (the rest will stick below).
If you want that the top of the figure is on the baseline, use valign=T
.
As the author of adjustbox comments, calling
\usepackage[export]{adjustbox}
the options provided by the package can go directly in the argument of \includegraphics
, so
\begin{tabular}{ll}
Some text & \includegraphics[valign=T,height=3cm,width=4cm]{p}}\\
...
\end{tabular}
is good as well. Change the other options for your case.
A similar approach without adjustbox
is to use \raisebox
:
\documentclass{article}
\usepackage{graphicx}
\setlength{\parindent}{0pt}% Just for this example
\begin{document}
Some text \includegraphics[height=3\baselineskip]{example-image} (bottom-aligned with baseline)
\medskip
Some text \raisebox{-\height}{%
\includegraphics[height=3\baselineskip]{example-image}} (top-aligned with baseline)
\medskip
Some text \raisebox{\dimexpr-\height+\baselineskip}{%
\includegraphics[height=3\baselineskip]{example-image}} (top-aligned with ``baselineskip'')
\end{document}
If the image is used inside a tabular
, one may consider using \raisebox{..}[0pt][0pt]{...}
to remove the depth/height of the object. This allows the object to overlap with content above/below it, depending on the usage.