# Yet another images in tables question alignment. Want text to start at top of cell. Not centered

I want to have a table with image in one cell and text in other cells.

I know about the issue of alignment at center of cells. So I use the trick of

     \raisebox{-.5\height}{\includegraphics[...]


But this does not do what I want. The text in the other cells in the table all start from the middle of the cell, leaving lots of empty space above.

I want the text to start from the top of the other cells. But do not know how to do it. i.e. I want text and images to all start from top of cell.

A picture is worth a 1,000 words, so here is a MWE

\documentclass[12pt]{article}%
\usepackage{graphicx}

\begin{document}

\begin{tabular}{|p{1.5in}|p{3in}|p{1.5in}|}\hline
{AAAAAAAAAAAA AAAAAAAAA}&
\raisebox{-.5\height}{\includegraphics[width=3in]{example-image-a}}&
BBBBBBBBBBB BBBB BBBBBBBBB BBBBBBBBB\\\hline
AAAAAAAAAAAA AAAAAAAAA&
\raisebox{-.5\height}{\includegraphics[width=3in]{example-image-a}}&
BBBBBBBBBBB BBBBBB BBBBBBBBB BBBBBBB\\\hline
\end{tabular}

\end{document}


If I do not use \raisebox then it looks like this

\documentclass[12pt]{article}%
\usepackage{graphicx}
\begin{document}
\begin{tabular}{|p{1.5in}|p{3in}|p{1.5in}|}\hline
{AAAAAAAAAAAA AAAAAAAAA}&
\includegraphics[width=3in]{example-image-a}&
BBBBBBBBBBB BBBB BBBBBBBBB BBBBBBBBB\\\hline
AAAAAAAAAAAA AAAAAAAAA&
\includegraphics[width=3in]{example-image-a}&
BBBBBBBBBBB BBBBBB BBBBBBBBB BBBBBBB\\\hline
\end{tabular}
\end{document}


Which is worst.

Any advice on how to do this?

Update

I tried the suggestion in comment to use \vspace{0pt} before \includegraphics which works, but only for tabular. I need it to work also for longtable. I did not think it will make a difference, so my MWE only used tabular.

Here is MWE for longtable

\documentclass[12pt]{article}%
\usepackage{graphicx}
\usepackage{longtable}
\begin{document}
\begin{longtable}{|p{1.5in}|p{3in}|p{1.5in}|}\hline
AAAAAAAAAAAA AAAAAAAAA&
\vspace{0pt}\includegraphics[width=3in]{example-image-a}&
BBBBBBBBBBB BBBB BBBBBBBBB BBBBBBBBB\\\hline
AAAAAAAAAAAA AAAAAAAAA&
\vspace{0pt}\includegraphics[width=3in]{example-image-a}&
BBBBBBBBBBB BBBBBB BBBBBBBBB BBBBBBB\\\hline
\end{longtable}


Which gives

But it works OK for tabular.

\documentclass[12pt]{article}%
\usepackage{graphicx}
\usepackage{longtable}
\begin{document}
\begin{tabular}{|p{1.5in}|p{3in}|p{1.5in}|}\hline
AAAAAAAAAAAA AAAAAAAAA&
\vspace{0pt}\includegraphics[width=3in]{example-image-a}&
BBBBBBBBBBB BBBB BBBBBBBBB BBBBBBBBB\\\hline
AAAAAAAAAAAA AAAAAAAAA&
\vspace{0pt}\includegraphics[width=3in]{example-image-a}&
BBBBBBBBBBB BBBBBB BBBBBBBBB BBBBBBB\\\hline
\end{tabular}
\end{document}


So I need a solution that works for longtable and not just tabular as I use longtable much more.

TL 2019

• Use \height in the raisebox argument , or add \vspace{0pt} before the graphic (and no raisebox) – Ulrike Fischer May 4 '19 at 7:29
• if you don't raise it aligns at the bottom, if you lower by half the height it aligns in the centre, so if you lower by the full height it aligns... – David Carlisle May 4 '19 at 7:58
• With longtable you need \vspace{0pt}\par as longtable quits vmode internally at the begin of the cell. – Ulrike Fischer May 4 '19 at 16:16

With the valign=t option (from the adjustbox package) you can achieve the desired layout also in a longtable environment:

\documentclass[12pt]{article}%
\usepackage{graphicx}
\usepackage{longtable}
\begin{document}
\begin{longtable}{|p{1.5in}|p{3in}|p{1.5in}|}\hline
AAAAAAAAAAAA AAAAAAAAA&
\vspace{0pt}\includegraphics[width=3in,valign=t]{example-image-a}&
BBBBBBBBBBB BBBB BBBBBBBBB BBBBBBBBB\\\hline
AAAAAAAAAAAA AAAAAAAAA&
\vspace{0pt}\includegraphics[width=3in,valign=t]{example-image-a}&
BBBBBBBBBBB BBBBBB BBBBBBBBB BBBBBBB\\\hline
\end{longtable}
\end{document}


as supplement to @leandris answer, with some off-topic suggestions (which can be helpful):

\documentclass[12pt]{article}%
\usepackage{longtable}
\usepackage{etoolbox}           % for Gin's key patches

\begin{document}
\begingroup
\expandafter\patchcmd\csname Gin@ii\endcsname   % needed etoolbox
{\setkeys {Gin}{#1}}
{\setkeys {Gin}
{width=\dimexpr\linewidth-\tabcolsep,  % standard graphicx settings
valign=t, margin=0pt 6pt 0pt 6pt}     % settings from adjustbox
}{}{}
\begin{longtable}{|p{1.5in}|p{3in}|p{1.5in}|}
\hline
AAAA AAA AA AAA AA AAAAA AA
&   \includegraphics{example-image-a}
&   BBBBBBBBBBB BBBB BBBBBBBBB BBBBBBBBB            \\
\hline
AAAA AAA AA AAA AA AAAAA AA
&   \includegraphics{example-image-b}
&   BBBBBBBBBBB BBBB BBBBBBBBB BBBBBBBBB            \\
\hline
AAAA AAA AA AAA AA AAAAA AA
&   \includegraphics{example-image-c}
&   BBBBBBBBBBB BBBB BBBBBBBBB BBBBBBBBB            \\
\hline
\end{longtable}
\endgroup
\end{document}
`

note: your table is wider than text width!