3

I'm trying to make an alphabet chart similar to this one here: Valid XHTML

I've got a set of images prenamed with pic1.png, pic2.png. I've been able to get a forloop working to get a set of the images to appear in the document, but when I try to stick that in a tabular, things don't quite go as planned. For the code below, I just wanted to test out putting the image and then the text on each row before I started looking at more difficult solutions like the chart:

\begin{table}[H]
    \caption[Letterforms]{Letterforms}
    \begin{tabular}{ c c }
        \toprule
        Letter & Spelling \\
        \foreach \x/\picname in {4/pic1.png,8/pic2.png,15/pic3.png}
        { \lipsum[\x]
            \midrule
            \includegraphics[width=1in]{\picname} & \x \\
        }
    \bottomrule
    \end{tabular}
\end{table}

Basically, I just need each image to appear above some text in a centered grid. I'm doing this for different documents with a different number of images each time, so I'd prefer a dynamic solution if at all possible. I'm also using the kaobook template, if that is helpful.

Willie Wong
  • 24,733
  • 8
  • 74
  • 106
Mark Adams
  • 33
  • 2
  • 2
    https://tex.stackexchange.com/questions/367979/latex-foreach-in-tabular-environment may be helpful. (Basically, you should build the "data" that goes into your table separately first, before sticking it into the tabular.) – Willie Wong Mar 23 '21 at 16:49
  • 2
    Welcome to TeX.se. Instead of posting code fragments, it's more helpful to put the fragment(s) into a complete compilable document that people can play with. – Alan Munn Mar 23 '21 at 16:50

1 Answers1

2

May I suggest a solution with subcaption embedded in a foreach loop. I have made 12 png (name: 1.png, 2.png etc.) containing the letters A to L. Once you run the code a 4x4 (or adjustable) figure is drawn an labeled.

\documentclass{article}

\usepackage{subcaption} \usepackage{tikz} \usepackage{lipsum}

\begin{document}

\begin{figure*}     

\foreach \w/\x/\y/\z in {1/2/3/4,5/6/7/8,9/10/11/12}{
\begin{subfigure}[b]{.2\textwidth}\centering
    \includegraphics[width=3cm,height=3cm]{\w.png}
    \centering \caption{No. \w}\label{fig:Label1}
\end{subfigure}
\hspace*{\fill}
\begin{subfigure}[b]{.2\textwidth}\centering
    \includegraphics[width=3cm,height=3cm]{{\x}.png}
    \centering \caption{No. \x}\label{fig:Label1}
\end{subfigure}
\hspace*{\fill}
\begin{subfigure}[b]{.2\textwidth}\centering
    \includegraphics[width=3cm,height=3cm]{{\y}.png}
    \centering \caption{No. \y}\label{fig:Label1}
\end{subfigure}
\hspace*{\fill}
\begin{subfigure}[b]{.2\textwidth}\centering
\includegraphics[width=3cm,height=3cm]{{\z}.png}
\centering \caption{No. \z}\label{fig:Label1}
\end{subfigure}
\par\bigskip
}
    \caption{\lipsum[1]}        
\end{figure*}

\end{document}

enter image description here

Roland
  • 6,655