Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I need to create a table with 1 row and 2 columns where the first cell has an inner table and the second a photo where I specify the width and let the system take care of the height. My difficulty is that I cannot get the inner table to line up at the top of the cell. To illustrate, here is the result I want:

enter image description here

and this is what I get

enter image description here

Also, this is the link to the original picture used in the example

I have tried all sorts of methods, from using \parbox and \vspace controls but after two days of reading manuals, googling and experimenting I'm admitting defeat and am now asking for help.

Here is the code which produced the badly formatted table.

\documentclass[twoside]{article}
\usepackage{graphicx}
\usepackage{calc}

\begin{document}
\noindent
\begin{tabular} {
    |@{}p{0.5\linewidth}@{}|
    p{0.5\linewidth-2\tabcolsep}|
}
    \hline
    \begin{tabular} {
        |p{0.5\linewidth-2\tabcolsep}|
        p{0.5\linewidth-2\tabcolsep}|
    }
        Serial Number & K77C 15229\\ \hline
        Reading & 18901 \\ \hline
        Date & 08/10/2012 \\ \hline
    \end{tabular}
    & 
    \includegraphics[width=\linewidth]{pics/DSC_3543.jpg} \\
    \hline
\end{tabular}
\end{document}

If I put \vspace{0mm} in front of \includgraphics, the inner tables appears at the top, as desired, but then extra white space appears above the photo. Putting a negative number (e.g. \vspace{-6mm}) produces the desired effect but then the number would need to change if the inner table had 4 or 5 rows. Since these need to be generated in the hundreds, it's not practical to have to manually adjust each one.

I feel as if I'm missing something simple. Thanks to anyone who can help!

share|improve this question

1 Answer 1

up vote 5 down vote accepted

The adjustbox package is your friend. Moreover the inner tabular should receive the [t] placement option:

\documentclass[twoside]{article}
\usepackage{graphicx}
\usepackage{calc,adjustbox}

\begin{document}
\noindent
\begin{tabular} {
    |@{}p{0.5\linewidth}@{}|
    @{}p{0.5\linewidth-\arrayrulewidth}@{}|
  }
  \hline
  \begin{tabular}[t] {
      p{0.5\linewidth-2\tabcolsep}|
      p{0.5\linewidth-2\tabcolsep}
  }
    Serial Number & K77C 15229\\ \hline
      Reading & 18901 \\ \hline
      Date & 08/10/2012 \\ \hline
  \end{tabular}
  &
  \adjustbox{valign=t}{\includegraphics[width=\linewidth]{DSC_3543.jpg}} \\
  \hline
\end{tabular}             
\end{document}

I've also fixed some of the computations, so that you'll not have padding left and right of the image.

enter image description here

share|improve this answer
    
adjustbox, not adjustwidth... :) –  Werner Oct 21 '12 at 15:19
    
Wow! Great answer! Not only did you answer my question, but improved my limited understanding of measurements! Thanks. –  Peter Colman Oct 21 '12 at 15:36
    
PS @egreg - I would vote your answer up but I don't have enough "reputation" to do that :) –  Peter Colman Oct 21 '12 at 15:52
    
@user21172 You can accept the answer after seeing if nothing better comes along; also this increases one's reputation. –  egreg Oct 21 '12 at 15:55

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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