3

I have a table of pictures with labels beside each row. I'd like to to have those labels be vertically aligned with their corresponding image. Every solution I've found and tried has failed. See MWE below

\documentclass{article}
\usepackage{tabularx}
\usepackage{array}
\usepackage{graphicx}
\usepackage{multirow}

\begin{document}
% set width for all the figures    
\newlength{\recircfigwidth}
\setlength{\recircfigwidth}{3cm}

\begin{figure*}
    \renewcommand{\tabularxcolumn}[1]{m{#1}}
   \centering
\begin{tabular}{m{1cm}|ccc}
\multirow{2}{*}{\(\phi\ [^\circ]\)} & \multicolumn{3}{c}{Swirl Strength [\%]} \\ \cline{2-4} 
                          & 100           & 150          & 200          \\ \hline
15  & 
\includegraphics[width=\recircfigwidth]{example-image} & 
\includegraphics[width=\recircfigwidth]{example-image} &
\includegraphics[width=\recircfigwidth]{example-image} \\
12.5 &\includegraphics[width=\recircfigwidth]{example-image} &
\includegraphics[width=\recircfigwidth]{example-image} &
\includegraphics[width=\recircfigwidth]{example-image} \\
10 &\includegraphics[width=\recircfigwidth]{example-image} &
\includegraphics[width=\recircfigwidth]{example-image} &
\includegraphics[width=\recircfigwidth]{example-image}             
\end{tabular}

   \caption{Caption for the whole figure}
    \label{fig:fig1} % I can do without the label too
\end{figure*}

\end{document}

enter image description here

  • Aligned with the vertical center of the row of images? – egreg Jul 3 at 20:18
  • @egreg Yes, I've updated to question to be more explicit. Would that also not be the middle of the cells? Or is cell height independent of the image height (somehow...)? – u2berggeist Jul 3 at 20:20
  • m is not doing what you think it does, it is aligning the vertical centre of the text in the first column with the reference point of the row which is the baseline of the images. – David Carlisle Jul 3 at 20:26
5

You can use adjustbox. I define a \fixedincludegraphics command that states the width once and for all, but also allows further keys; for this application, valign=c.

I also removed the vertical rule that does nothing good.

\documentclass{article}
\usepackage{booktabs}
\usepackage{array}
\usepackage{graphicx}
\usepackage[export]{adjustbox}

% set width for all the figures    
\newlength{\recircfigwidth}
\setlength{\recircfigwidth}{3cm}
\newcommand{\fixedincludegraphics}[2][]{%
  \includegraphics[width=\recircfigwidth,#1]{#2}%
}

\begin{document}

\begin{figure*}
\centering

\begin{tabular}{@{}cccc@{}}
\toprule
\(\phi\) (\(^\circ\)) & \multicolumn{3}{c}{Swirl Strength (\%)} \\
\cmidrule(l){2-4} 
& 100           & 150          & 200          \\
\midrule
15  & 
\fixedincludegraphics[valign=c]{example-image} & 
\fixedincludegraphics[valign=c]{example-image} &
\fixedincludegraphics[valign=c]{example-image} \\
\addlinespace
12.5 &
\fixedincludegraphics[valign=c]{example-image} &
\fixedincludegraphics[valign=c]{example-image} &
\fixedincludegraphics[valign=c]{example-image} \\
\addlinespace
10 &
\fixedincludegraphics[valign=c]{example-image} &
\fixedincludegraphics[valign=c]{example-image} &
\fixedincludegraphics[valign=c]{example-image}             
\end{tabular}

\caption{Caption for the whole figure}
    \label{fig:fig1} % I can do without the label too
\end{figure*}

\end{document}

enter image description here

  • 1
    Wouldn't it make sense to also add the valign=c option into the definition of \fixedincludegraphics in order to avoid repeatedly having to add valign=c? – leandriis Jul 3 at 20:42
  • @leandriis The \fixedincludegraphics command is probably also useful in other contexts. – egreg Jul 3 at 20:55
  • So you mention adjustbox as the (seemingly) primary operator in the solution, but it doesn't actually appear in the solution (apart from the package import). Is it simply used automatically by the \includegraphics command, or is it doing soemthing somewhere else? – u2berggeist Jul 3 at 21:00
  • 2
    @u2berggeist adjustbox provides the valign key, that's not available with the default graphicx package. – egreg Jul 3 at 21:03
3

You can do it this way:

    \documentclass{article}
    \usepackage{tabularx}
    \usepackage{array}
    \usepackage{graphicx}
    \usepackage{multirow, makecell}

    \begin{document}
    % set width for all the figures
    \newlength{\recircfigwidth}
    \setlength{\recircfigwidth}{3cm}

    \begin{figure*}
        \renewcommand{\tabularxcolumn}[1]{ >{\centering\arraybackslash}m{#1}}
       \centering
    \begin{tabularx}{\linewidth}{m{1cm}|XXX}
    \multirow{2}{*}{\(\phi\ [^\circ]\)} & \multicolumn{3}{c}{Swirl Strength [\%]} \\ \cline{2-4}
                              & 100 & 150 & 200 \\ \hline
    15 & \includegraphics[width=\recircfigwidth]{example-image} &
    \includegraphics[width=\recircfigwidth]{example-image} &
    \includegraphics[width=\recircfigwidth]{example-image} \\
    12.5 &\includegraphics[width=\recircfigwidth]{example-image} &
    \includegraphics[width=\recircfigwidth]{example-image} &
    \includegraphics[width=\recircfigwidth]{example-image} \\
    10 &\includegraphics[width=\recircfigwidth]{example-image} &
    \includegraphics[width=\recircfigwidth]{example-image} &
    \includegraphics[width=\recircfigwidth]{example-image}
    \end{tabularx}

       \caption{Caption for the whole figure}
        \label{fig:fig1} % I can do without the label too
    \end{figure*}

    \end{document} 

enter image description here

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.