4

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}

Mathematica graphics

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}

Mathematica graphics

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

Mathematica graphics

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}

Mathematica graphics

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
5

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}  
\usepackage[export]{adjustbox}  
\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}

enter image description here

|improve this answer|||||
5

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

\documentclass[12pt]{article}%
\usepackage{longtable}
\usepackage[export]{adjustbox}  % it load graphicx too
\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}

enter image description here

note: your table is wider than text width!

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.