[Tex/LaTex] Long list of tabular figures inside minipage goes off page

boxesluatexminipagetablestabularx

Using the follow MWE, I'm able to create a beautiful lists of photos on the left and a caption on the right (similarly, I could also use the sidecaption package or floats directly).

MWE [LuaLaTeX]:

\documentclass[letterpaper]{report}

\usepackage[demo]{graphicx}
\usepackage{fontspec}
\usepackage{savetrees}

\begin{document}
    \begin{figure}[H]
        \begin{minipage}{\textwidth}
            \begin{tabular}{p{8cm}p{6cm}}
                \vspace{0cm}
                \includegraphics[width=8cm]{name} & Some text on the side.
            \end{tabular}
        \end{minipage}
    \end{figure}
\end{document}

The issue is that when multiple photos or long (height) photos are added to the tabular environment, the photos go off of the page instead of a new page being created and going into the new page.

MWE [LuaLaTeX]:

\documentclass[letterpaper]{report}

\usepackage[demo]{graphicx}
\usepackage{fontspec}
\usepackage{savetrees}

\begin{document}
    \begin{figure}[H]
        \begin{minipage}{\textwidth}
            \begin{tabular}{p{8cm}p{6cm}}
                \vspace{0cm}
                \includegraphics[width=8cm]{name} & Some text on the side.
            \end{tabular}
            \begin{tabular}{p{8cm}p{6cm}}
                \vspace{0cm}
                \includegraphics[width=8cm]{name} & Some text on the side.
            \end{tabular}
            \begin{tabular}{p{8cm}p{6cm}}
                \vspace{0cm}
                \includegraphics[width=8cm]{name} & Some text on the side.
            \end{tabular}
            \begin{tabular}{p{8cm}p{6cm}}
                \vspace{0cm}
                \includegraphics[width=8cm]{name} & Some text on the side.
            \end{tabular}
            \begin{tabular}{p{8cm}p{6cm}}
                \vspace{0cm}
                \includegraphics[width=8cm]{name} & Some text on the side.
            \end{tabular}
            \begin{tabular}{p{8cm}p{6cm}}
                \vspace{0cm}
                \includegraphics[width=8cm]{name} & Some text on the side.
            \end{tabular}
            \begin{tabular}{p{8cm}p{6cm}}
                \vspace{0cm}
                \includegraphics[width=8cm]{name} & Some text on the side.
            \end{tabular}
            \begin{tabular}{p{8cm}p{6cm}}
                \vspace{0cm}
                \includegraphics[width=8cm]{name} & Some text on the side.
            \end{tabular}
        \end{minipage}
    \end{figure}
\end{document}

I noticed that outside of the minipage and tabular environments, everything works perfectly, but this isn't an option because I need a caption on the right side of the images and also need to ensure that LaTeX doesn't move pictures around randomly. Ideally I can keep everything inside the minipage and tabular enviornments.

MWE [LuaLaTeX]:

\documentclass[letterpaper]{report}

\usepackage[demo]{graphicx}
\usepackage{fontspec}
\usepackage{savetrees}

\begin{document}
    \flushleft
    \includegraphics[width=8cm]{name} \\
    \includegraphics[width=8cm]{name} \\
    \includegraphics[width=8cm]{name} \\
    \includegraphics[width=8cm]{name} \\
    \includegraphics[width=8cm]{name} \\
    \includegraphics[width=8cm]{name} \\
    \includegraphics[width=8cm]{name} \\
    \includegraphics[width=8cm]{name} \\
\end{document} 

I have hundreds of images that need to be formatted as in the first MWE, so applying \newpage manually is not an option.

Is there a way to automatically move the images to new pages where necessary like it does in the last MWE?

Best Answer

You can use a separate figure for each image and to make sure the order is not altered you need only to specify the location options for each figure environment [!htb]. Also use \vspace{-0.25cm} to align text and figures correctly. No need for a minipage at all. See this modified code:

\documentclass[letterpaper]{report}
\usepackage[demo]{graphicx}
\usepackage{savetrees}
\usepackage[demo]{graphicx}
\usepackage{fontspec}

\begin{document}
    \begin{figure}[!htb]
            \begin{tabular}{p{8cm}p{6cm}}
                \vspace{-0.25cm}
                \includegraphics[width=8cm]{name1} & Some text on the side1.
            \end{tabular}
   \end{figure}
   \begin{figure}[!htb]
            \begin{tabular}{p{8cm}p{6cm}}
                \vspace{-0.25cm}
                \includegraphics[width=8cm]{name 2} & Some text on the side 2.
            \end{tabular}
            \end{figure}
   \begin{figure}[!htb]
            \begin{tabular}{p{8cm}p{6cm}}
                \vspace{-0.25cm}
                \includegraphics[width=8cm]{name 3} & Some text on the side 3.
            \end{tabular}
            \end{figure}
   \begin{figure}[!htb]
            \begin{tabular}{p{8cm}p{6cm}}
                \vspace{-0.25cm}
                \includegraphics[width=8cm]{name 4} & Some text on the side 4.
            \end{tabular}
            \end{figure}
   \begin{figure}[!htb]
            \begin{tabular}{p{8cm}p{6cm}}
                \vspace{-0.25cm}
                \includegraphics[width=8cm]{name 5} & Some text on the side 5.
            \end{tabular}
            \end{figure}
   \begin{figure}[!htb]
            \begin{tabular}{p{8cm}p{6cm}}
                \vspace{-0.25cm}
                \includegraphics[width=8cm]{name 6} & Some text on the side 6.
            \end{tabular}
            \end{figure}
   \begin{figure}[!htb]
            \begin{tabular}{p{8cm}p{6cm}}
                \vspace{-0.25cm}
                \includegraphics[width=8cm]{name 7} & Some text on the side 7.
            \end{tabular}
            \end{figure}
   \begin{figure}[!htb]
            \begin{tabular}{p{8cm}p{6cm}}
                \vspace{-0.25cm}
                \includegraphics[width=8cm]{name 8} & Some text on the side 8.
            \end{tabular}
    \end{figure}
\end{document}

The output as you want:

enter image description here

enter image description here

Related Question