[Tex/LaTex] size figures according to tabular column width

floatsincludegraphicstables

I'm putting together a multi-panel figure which will also eventually get some row and column labels. In order to do this, I think the best approach for the skeleton of the structure is to \includegraphics inside a tabular environment.

At the moment I have something like this (consider this a 'pseudo-MWE'):

\begin{figure}[p]
  \begin{tabular}{cccc}
    \includegraphics[width=0.24\textwidth]{image1.pdf} &%
    \includegraphics[width=0.24\textwidth]{image2.pdf} &%
    \includegraphics[width=0.24\textwidth]{image3.pdf} &%
    \includegraphics[width=0.24\textwidth]{image4.pdf} \\%
  \end{tabular}
\end{figure}

I'm wondering if there is some way to express the overall dimensions (i.e. the table width) in the tabular environment, at present it spans the \textwidth as I'd like it to; but also be able to express the individual image dimensions in terms of the cell width without specifying it explicitly as above?

Ideally I'd end up with each column of the table equating to roughly 0.25*\textwidth, and then the images to fit themselves accordingly, as if I was calling something like:

\includegraphics[width=\columnwidth]{myimage.pdf}...

Best Answer

You could use tabularx:

\documentclass{article}
\usepackage{tabularx}
\usepackage{graphicx}
\begin{document}
\begin{figure}[p]
  \setkeys{Gin}{width=\linewidth}
  \begin{tabularx}{\textwidth}{XXXX}
    \includegraphics{example-image} &
    \includegraphics{example-image} &
    \includegraphics{example-image} &
    \includegraphics{example-image} \\
  \end{tabularx}
\end{figure}
\end{document}
Related Question