Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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?

share|improve this question
2  
Welcome to TeX.SX! A figure environment will never be split across pages. –  egreg Aug 28 at 22:45
    
Are there alternatives for keeping the figure's H functionality? –  Shaku Aug 28 at 23:03

3 Answers 3

up vote 4 down vote accepted

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

share|improve this answer
    
You are an absolute genius and lifesaver! Thanks a ton. This works perfectly. –  Shaku Aug 29 at 2:01
1  
This would be a lot more efficient if you simply omitted the figure environments –  David Carlisle Aug 29 at 8:44
1  
The figure environment has the advantage of evenly distributing the figures vertically in a page. Besides, no need for explicitly inserting new lines or paragraphs. –  AboAmmar Aug 29 at 12:27
1  
@AboAmmar that's not really an advantage, it's a lot less efficient (and if the list is too long you're likely to get a "too many floats" error, and it's a lot more markup than a blank line that is all that's needed to insert a paragrap[h break. –  David Carlisle Aug 30 at 7:30

the \begin{minipage}{\textwidth} is not doing anything as the figure environment is already effectively a minipage. minipages and floats never break over a page.

You could use a longtable for a multipage table or simply place each image and text in a paragraph outside any table or float:

\includegraphics[width=8cm]{name1} \parbox[t]{6cm}{some text}

\includegraphics[width=8cm]{name2} \parbox[t]{6cm}{some more text}

\includegraphics[width=8cm]{name3} \parbox[t]{6cm}{yet more text}

seems to be all you need. Possibly with \raisebox around the images to adjust the alignment.

share|improve this answer
    
I tried the longtable approach, but the same issue persisted. Is there another way that you're talking about? –  Shaku Aug 28 at 22:59
    
Also, the reason that I have it inside a minipage/figure is so that LaTeX won't randomly move things around. Without them, LaTeX throws the images out of order. –  Shaku Aug 28 at 23:01
1  
@Shaku No. the minipage in that position does nothing –  David Carlisle Aug 29 at 8:40
    
@Shaku if you used longtable and it did not break over a page then you used it incorrectly, it is hard to say what you did wrong if you do not give an example. –  David Carlisle Aug 29 at 8:41
1  
@Shaku, of course, if you put a longtable inside a table environment it doesn't work: a table is effectively a minipage and is an unbreakable box. –  David Carlisle Aug 30 at 7:31

A figure environment is never split across pages.

If you want that something doesn't float, don't make it into a floating environment. Also, anything repetitive should be compressed into a new command.

\documentclass{report}
\usepackage[textwidth=15cm]{geometry} % 6+1+8=15
\usepackage[demo]{graphicx}
\usepackage{adjustbox}

\usepackage{lipsum} % just for the example


\newcommand{\figureitem}[2]{%
  \par\addvspace{\topsep}
  \noindent
  \adjustbox{valign=t}{\includegraphics[width=8cm]{#1}}%
  \hspace{1cm}%
  \parbox[t]{6cm}{#2}%
  \par\addvspace{\topsep}
}

\begin{document}

\lipsum[2]

\figureitem{name1}{Some text on the side 1}

\figureitem{name2}{Some text on the side 2}

\figureitem{name3}{Some text on the side 3 that should split across lines, to show the effect}

\figureitem{name4}{Some text on the side 4}

\figureitem{name5}{Some text on the side 5 that should split across lines, to show the effect}

\figureitem{name6}{Some text on the side 6}

\figureitem{name7}{Some text on the side 7 that should split across lines, to show the effect}

\figureitem{name8}{Some text on the side 8}

\end{document}

enter image description here

share|improve this answer
    
Thanks for this! The command helps clean the document up quite a bit. –  Shaku Aug 30 at 1:45

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.