4

Here I come again,

Following the indications on this url I managed to get almost exactly what I want. However the problem is that the first multirow cell (with text "5 and 6") is not vertically centered.

Any help is very much appreciated.

Setup is Miktex 2.9, updated packages from CTAN as of today, Texniccenter 2a3 on win7x32. Profile is Latex->PDF.

Best regards and thanks in advance

\documentclass{article}
\usepackage{multirow,array,tabularx,booktabs}

\begin{document}
\newcolumntype{Z}{>{\centering\arraybackslash}X}
\newcolumntype{Y}{>{\small\raggedright\arraybackslash}X}
\renewcommand{\tabularxcolumn}[1]{>{\arraybackslash}m{#1}}
\begin{table}[htbp]
\begin{tabularx}{\textwidth}{|Z|Z|Z|}
\hline\hline Number&Image 1&Image 2\\\hline\hline
1&\includegraphics[width=0.2\columnwidth]{images/1.png}&\includegraphics[width=0.2\columnwidth]{images/1a.png}\\\hline
2&\includegraphics[width=0.2\columnwidth]{images/2.png}&\includegraphics[width=0.2\columnwidth]{images/2a.png}\\\hline
3&\includegraphics[width=0.2\columnwidth]{images/3.png}&\includegraphics[width=0.2\columnwidth]{images/3a.png}\\\hline
\multirow{2}{*}{5 and 6}&\multirow{2}{*}{\includegraphics[width=0.2\columnwidth]{images/56.png}}&\includegraphics[width=0.2\columnwidth]{images/5.png}\\\cline{3-3}
& & \includegraphics[width=0.2\columnwidth]{images/6.png}\\\hline
\end{tabularx}
\caption{Images}
\label{tab:figuretable}
\end{table}

\end{document}
Jose R
  • 265
  • Examples which we can't compile (because of the missing images) are already not very useful. But if even you can't compile your example (because of the missing graphicx package) ... Try to make examples that every one can compile (e.g. replace graphics by \rule{width}{height}), and test them before copy&paste. – Ulrike Fischer Feb 08 '12 at 13:17
  • @UlrikeFischer Thank you for the tips. I didn't get the missing graphicx package part, I've been including graphics in my documents without the needing to explicitly declare it and the images load just fine. – Jose R Feb 08 '12 at 14:32
  • If you compile exactly the example you gave above you should get errors. If not your system has been manipulated. But it is quite possible that you don't have to load graphicx explicitly in a larger document. E.g. another package could do it internally. Nevertheless: Never assume that an example does what you think it does, always test it. – Ulrike Fischer Feb 08 '12 at 14:39
  • @UlrikeFischer Thank you very much for the tips, from now on I will include graphicx package. I did test the example before posting the question and it yielded a page without errors and produced a pdf page output. – Jose R Feb 08 '12 at 15:05
  • If this example really compiles without errors then one of the standard packages (or the class) you load have been changed - something you should never, never do. This is very bad practice. – Ulrike Fischer Feb 08 '12 at 15:12
  • @UlrikeFischer I haven't modified neither packages nor classes at all. Straight from the repository. – Jose R Feb 08 '12 at 15:37
  • Compile the above example exactly as it is and then put the log-file somewhere on the net for inspection. – Ulrike Fischer Feb 08 '12 at 15:39
  • @UlrikeFischer Sorry, work as been crazy (much like me :)). I stand corrected Ulrike you were right, I couldn't compile it without that package. Tried the example in a fresh file and it didn't execute. Must've been another package which was loading it. – Jose R Feb 24 '12 at 20:13

2 Answers2

4

You don't need multirow, for this application: just put the double image in an inner tabular environment. The width of an X column is available as \hsize.

\documentclass{article}
\usepackage{array,tabularx,booktabs}
\usepackage[demo]{graphicx}
\usepackage[export]{adjustbox}
\begin{document}
\newcolumntype{Z}{>{\centering\arraybackslash}X}
\newcolumntype{Y}{>{\small\raggedright\arraybackslash}X}
\renewcommand{\tabularxcolumn}[1]{>{\arraybackslash}m{#1}}
\begin{table}[htbp]
\begin{tabularx}{\textwidth}{ZZZ}
\toprule
Number&Image 1&Image 2\\
\midrule
1
  &\includegraphics[width=0.2\columnwidth]{images/1.png}
  &\includegraphics[width=0.2\columnwidth]{images/1a.png}\\
\midrule
2
  &\includegraphics[width=0.2\columnwidth]{images/2.png}
  &\includegraphics[width=0.2\columnwidth]{images/2a.png}\\
\midrule
3
  &\includegraphics[width=0.2\columnwidth]{images/3.png}
  &\includegraphics[width=0.2\columnwidth]{images/3a.png}\\
\midrule
5 and 6
  &\includegraphics[width=0.2\columnwidth]{images/56.png}
  &\begin{tabular}{@{}>{\centering\arraybackslash}p{\hsize}@{}}
   \includegraphics[width=0.2\columnwidth]{images/5.png}\\
   \midrule
   \includegraphics[width=0.2\columnwidth]{images/6.png}
   \end{tabular}\\
\bottomrule
\end{tabularx}
\caption{Images}
\label{tab:figuretable}
\end{table}

\end{document}

I've used the rules as in booktabs; if you really prefer boxed tables, change them back to \hline.

David Carlisle
  • 757,742
egreg
  • 1,121,712
3

multirow has a final (after the width, before the contents) optional "fixup" argument that allows you to raise or lower the contents, so you can visually achieve the centering you want, even if not fully automatic.

David Carlisle
  • 757,742
  • Thank you very much for your answer, it works however this is not as automatic as you stated. That's why I'm marking @egreg's answer as accepted. – Jose R Feb 08 '12 at 15:03