0

I need to make a table with images, 9 rows and 4 columns. The first column will contain text, and the remaining 3 columns will contain the images. The following screenshot shows the desired layout.

Depending on the image sizes, the table may need to span more than 1 page.

Added piece of information: It’s important that the third image column be (about) 50% wider than the first two.

enter image description here

18
  • 1
    How should we know if any approach we would suggest is easier than whatever solutions you already found? Commented Dec 29, 2024 at 17:15
  • 1
    Welcome // "I found a few ways but i'm looking for much simpler" sounds like the song "50 ways to leave your lover". Code tells us more. Please add. For the images I suggest to follow sam's link and use the provided example-images. Commented Dec 29, 2024 at 17:22
  • 2
    Or just tell us the size of the images so we can substitute. Commented Dec 29, 2024 at 17:24
  • 2
    This question is similar to: Centering Images and text inside a table. If you believe it’s different, please edit the question, make it clear how it’s different and/or how the answers on that question are not helpful for your problem. Commented Dec 30, 2024 at 11:41
  • 1
    @Mico If the column width and not the vertical centering is the problem you would be right. But this is currently not clear. For me the obvious problem was the verticl centering. So the description of the problem should be improved. Commented Jan 1, 2025 at 9:39

2 Answers 2

5

Here's a solution that employs the xltabular package and eponymous environment. Basically, xltabular combines the capabilities of longtable (allow page breaks in the table) and tabularx (set a target for the table's overall width; determine widths of X-type columns as residuals). Note that, per your comment, I've set the usable width of the third data column to be 50% larger than that of the other two.

Be sure to load the graphicx package without the demo option in your real document.

enter image description here

\documentclass{article} % or some other suitable document class
%\usepackage[a4paper,margin=2.5cm]{geometry} % set page parameters as needed
\usepackage[demo]{graphicx} % remove 'demo' option in real document

\usepackage{xltabular} % for 'xltabular' env. 
\renewcommand\tabularxcolumn[1]{m{#1}} % vertical centering
  % Define a variable-width X-type column, cell contents centered horizontally:
\newcolumntype{Y}[1]{>{\hsize=#1\hsize\centering\arraybackslash}X} 
\usepackage{booktabs} % for well-spaced horizontal rules

\begin{document}

\begingroup % limit the scope of the next two instructions
\renewcommand\tabcolsep{4pt} % default: 6pt
\setkeys{Gin}{width=\hsize,height=\hsize,keepaspectratio}

\begin{xltabular}{\textwidth}{@{} c Y{0.8571} Y{0.8571} Y{1.2858} @{}} 
   % 6/7+6/7+9/7 = 21/7 = 3; 9/7 = 1.5*6/7; 0.8571=6/7; 1.2858=9/7.

%% headers and footers

\toprule
Sample & Front view & Back view & Cross-sectional view \\
\midrule
\endhead

\bottomrule
\endfoot

%% body of table

A & 
\includegraphics{a} &
\includegraphics{b} &
\includegraphics[height=0.6667\hsize]{c} \\
\addlinespace
N & 
\includegraphics{d} &
\includegraphics{e} &
\includegraphics[height=0.6667\hsize]{f} \\
\addlinespace
C & 
\includegraphics{g} &
\includegraphics{h} &
\includegraphics[height=0.6667\hsize]{i} \\
\addlinespace
ANAN & 
\includegraphics{j} &
\includegraphics{k} &
\includegraphics[height=0.6667\hsize]{l} \\
\addlinespace
NANA & 
\includegraphics{m} &
\includegraphics{n} &
\includegraphics[height=0.6667\hsize]{o} \\

\end{xltabular}
\endgroup

\end{document}
4
  • does '\caption{}' work in this solution? while i add caption according to xltabular I come up with errors. Any ideas why? Commented Jan 6, 2025 at 21:52
  • @bubabenson - Using \caption should definitely work with xltabular. (The syntax is the same as for longtable.) However, because my psychic divination abilities are worthless, I can't give meaningful further advice unless you tell me which error mesages you're getting. Commented Jan 6, 2025 at 22:28
  • Forgot to use ` \\ ` after ` \caption{} ` Commented Jan 7, 2025 at 19:42
  • @bubabenson - Glad to learn that you found the glitch in your code. Commented Jan 7, 2025 at 21:27
3

Like in your other question, I'd use tabularray. This makes it not only easy to centre the images, but also to adjust the relative column widths:

\documentclass{article}

\usepackage{geometry}
\usepackage{tabularray}
\usepackage[export]{adjustbox}

\begin{document}

\begin{longtblr}{
  colspec={QXXX[2]},
  cells={halign=c},
  vlines,
  hlines
}
sda & Front & Back & Side \\
AAAA   & 
\includegraphics[width=\linewidth,valign=c]{example-grid-100x100pt} & 
\includegraphics[width=\linewidth,valign=c]{example-grid-100x100pt} & 
\includegraphics[width=\linewidth,valign=c]{example-image-duck} \\
\end{longtblr}

\end{document}

enter image description here

8
  • +1. How might one set the parameters of the third image so that its height is the same as those of the first two? Commented Jan 2, 2025 at 12:34
  • @Mico If they have the same heights, one can't see that they are vertically centred. And looking at their companion question tex.stackexchange.com/q/733830/36296 vertical centring seems to be important to them Commented Jan 2, 2025 at 12:38
  • Doesn't the vertical centering objective apply mainly to the contents of column 1 vs. the contents of columns 2/3/4? Commented Jan 2, 2025 at 12:41
  • @Mico Col 1 will be the most obvious one, but the ability to centre all columns won't hurt. Commented Jan 2, 2025 at 12:46
  • 1
    i would question the claim that the OP doesn't want (or ask for) equal image heights. To my eye, the image heights in the OP's posting are very nearly the same in each row, and I doubt that that's coincidence. Commented Jan 2, 2025 at 13:19

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.