2
\$\begingroup\$

I am attempting to create a table for placing images in LaTeX. The first column is the (image) index, the second and third columns are images from different folder. For example, in the row with index = 1, the two images from the path Images/1/1.png and Images/2/1.png are placed in the second and third column locations. In the row with index = 2, the two images from the path Images/1/2.png and Images/2/2.png are placed in the second and third column locations. Just like this:

Index Image Frames Input Image Frames Output
1 Images/1/1.png Images/2/1.png
2 Images/1/2.png Images/2/2.png
\newcounter{it} \setcounter{it}{0}
\newtoks\tabtoks
\newcommand\addtabtoks[1]{\tabtoks\expandafter{\the\tabtoks#1}}
\newcommand*\resettabtoks{\tabtoks{}}
\newcommand*\printtabtoks{\the\tabtoks}
\resettabtoks
\newcounter{counterB} \setcounter{counterB}{0}
\loop\ifnum\theit<6
 
 \addtabtoks{
 \addtocounter{counterB}{1} % increment
 \thecounterB
 &
 \begin{minipage}{.45\textwidth}
 \includegraphics[width=\linewidth]{Images/1/\thecounterB.png}
\end{minipage}
 &
 \begin{minipage}{.45\textwidth}
 \includegraphics[width=\linewidth]{Images/2/\thecounterB.png}
\end{minipage} \\ \hline
 }
 \stepcounter{it}
\repeat
\begin{table}[ht!]
\centering
\begin{tabular}{ | c | c | c | }
\hline
Index & Image Frames Input & Image Frames Output \\ \hline
\printtabtoks
\end{tabular}
\caption{The experimental results}\label{tbl:TheExperimentalResults}
\end{table}

The output looks like this:

Output

All suggestions are welcome.

Reference:

asked Aug 24, 2021 at 23:57
\$\endgroup\$

1 Answer 1

2
\$\begingroup\$

Instead of keeping track of row numbers manually, you could use the nicematrix package which keeps track of these numbers for you:

\documentclass{article}
\usepackage{nicematrix}
\usepackage{graphicx}
\begin{document}
\noindent%
\begin{NiceTabular}[width=\textwidth,first-row,hvlines]{
 >{\arabic{iRow}}c
 >{\includegraphics[width=\linewidth]{Images/1/\arabic{iRow}.png}}X
 >{\includegraphics[width=\linewidth]{Images/2/\arabic{iRow}.png}}X
 }
\hline
\multicolumn{1}{|c}{Index} & 
\multicolumn{1}{|c}{Input} & \multicolumn{1}{|c|}{Output}\\
& & \\
& & \\
\end{NiceTabular}
\end{document}
answered Aug 25, 2021 at 10:28
\$\endgroup\$

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.