2

I would like a very simple table, a paragraph in the left column, and an image in the right with a label under the image. For some strange reason, LaTeX is putting a bunch of white space before the paragraph, and I can't figure out why:

\noindent\begin{tabular}{|p{4in} p{1in}|}
\hline
Note: The strange word which occurs three times on the form above (including alone on the far right column) has been explained to me by a French speaker as the Latin word "idem" meaning "the same" or as we would say colloquially in English, ``ditto.''& \includegraphics[width=1in]{img/ch06-Ditto.png} ``ditto''\\
\hline
\end{tabular}

The result appears like this:

enter image description here

Anyone know why it appears to have added a extra blank line into the top of the left column?

3
  • 1
    it is unrelated to the table, the image is simply placed on the same baseline as the first line of text. Feb 23 at 21:29
  • 2
    To align the first line of text with the top of the image, add \usepackage[export]{adjustbox} to the preamble and use \includegraphics[width=1in, valign=t].
    – leandriis
    Feb 23 at 21:30
  • See also: How to top align text and image in table?
    – leandriis
    Feb 23 at 21:44
3

This stems from the image being set on the baseline of the first line, which makes it stick out (vertically) above the line.

To avoid this, "raise" the image into place:

enter image description here

\documentclass{article}

\usepackage{graphicx}

\begin{document}

\noindent\begin{tabular}{ | p{4in} p{1in} | }
  \hline
  Note: The strange word which occurs three times on the form above (including alone on 
  the far right column) has been explained to me by a French speaker as the Latin 
  word ``idem'' meaning ``the same'' or as we would say colloquially in English, ``ditto.''
  & {\centering\begin{tabular}[t]{ @{} c @{} }
    \raisebox{\dimexpr-\height+.6\normalbaselineskip}{\includegraphics[width=0.5in]{example-image}} \\ 
    ``ditto''
  \end{tabular}\par} \\
  \hline
\end{tabular}

\end{document}

Note that I've set the right-hand column inside its own tabular. This allows you some freedom for breaking the lines how you want them, rather than forcing a line-break as a label for your image.

2
  • Thanks, that is perfect. That is so strange. I would think that all the contents of one cell of a table would be independent of the contents of the others. I never ever would have thought about comparing one line in one cell, to a line in another cell. Has anyone defined a tables package that work similarly to any word processor, any spreadsheet or any HTML table? (I am guessing not . . . )
    – AgilePro
    Feb 23 at 21:50
  • 1
    @AgilePro: This is specific to the first line of a cell since it's used as an anchor for the tabular.
    – Werner
    Feb 23 at 21:59
1

No need to guess:

\documentclass{article}
\usepackage{graphicx}

\begin{document}

\noindent
\begin{tabular}{|p{4in} p{1in}|}
\hline
Note: The strange word which occurs three times on the form above 
(including alone on the far right column) has been explained to me 
by a French speaker as the Latin word ``idem'' meaning ``the same''
or as we would say colloquially in English, ``ditto.''
& \centering
\vspace{-\ht\strutbox}\includegraphics[width=1in,height=0.4in]{example-image} ``ditto''
\tabularnewline
\hline
\end{tabular}

\end{document}

enter image description here

The \vspace will set the baseline of the (top aligned) parbox in the second column, but we need to back up by the height of the strut that LaTeX adds automatically.

In the code I added height to emulate your picture; of course you'll have to remove it.

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.