0

I'm trying to do some automatically generated LaTeX documents and I'm wondering how can I split subfigures (with captions a, b, c, etc.) over many pages automatically. This is my code and the only thing which I would like to improve is to show figure caption (here Title) but only for the last row on each page, not after each row. How can I do that?

\documentclass[11pt]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc} % ensure your document is UTF-8
\usepackage[spanish]{babel}

\usepackage[demo]{graphicx} % demo option just for testing
\usepackage{caption}
\usepackage{subcaption}
\usepackage{float}
\usepackage[showframe]{geometry}
\usepackage{float}

\begin{document}
    
\centering
\begin{figure}[htb]
\begin{subfigure}[t]{.32\textwidth}
    \includegraphics[width=\textwidth]{images/1.png}
    \caption{Image 1.}
    \label{fig:1}
\end{subfigure}
    \hfill
\begin{subfigure}[t]{.32\textwidth}
    \includegraphics[width=\textwidth]{images/1.png}
    \caption{Image 2.}
    \label{fig:2}
\end{subfigure}
    \hfill
\begin{subfigure}[t]{.32\textwidth}
    \includegraphics[width=\textwidth]{images/1.png}
    \caption{Image 3.}
    \label{fig:1}
\end{subfigure}
\caption{Title}
\end{figure}

\begin{figure}[H]\ContinuedFloat
\begin{subfigure}[t]{.32\textwidth}
    \includegraphics[width=\textwidth]{images/1.png}
    \caption{Image 1.}
    \label{fig:1}
\end{subfigure}
    \hfill
\begin{subfigure}[t]{.32\textwidth}
    \includegraphics[width=\textwidth]{images/1.png}
    \caption{Image 2.}
    \label{fig:2}
\end{subfigure}
    \hfill
\begin{subfigure}[t]{.32\textwidth}
    \includegraphics[width=\textwidth]{images/1.png}
    \caption{Image 3.}
    \label{fig:1}
\end{subfigure}
\caption{Title}
\end{figure}

\begin{figure}[H]\ContinuedFloat
\begin{subfigure}[t]{.32\textwidth}
    \includegraphics[width=\textwidth]{images/1.png}
    \caption{Image 1.}
    \label{fig:1}
\end{subfigure}
    \hfill
\begin{subfigure}[t]{.32\textwidth}
    \includegraphics[width=\textwidth]{images/1.png}
    \caption{Image 2.}
    \label{fig:2}
\end{subfigure}
    \hfill
\begin{subfigure}[t]{.32\textwidth}
    \includegraphics[width=\textwidth]{images/1.png}
    \caption{Image 3.}
    \label{fig:1}
\end{subfigure}
\caption{Title}
\end{figure}

\begin{figure}[H]\ContinuedFloat
\begin{subfigure}[t]{.32\textwidth}
    \includegraphics[width=\textwidth]{images/1.png}
    \caption{Image 1.}
    \label{fig:1}
\end{subfigure}
    \hfill
\begin{subfigure}[t]{.32\textwidth}
    \includegraphics[width=\textwidth]{images/1.png}
    \caption{Image 2.}
    \label{fig:2}
\end{subfigure}
    \hfill
\begin{subfigure}[t]{.32\textwidth}
    \includegraphics[width=\textwidth]{images/1.png}
    \caption{Image 3.}
    \label{fig:1}
\end{subfigure}
\caption{Title}
\end{figure}

   


\end{document}
3

2 Answers 2

0

I'm not sure if it helps You and it is not automatically at all but better than Your variant:

\documentclass[11pt]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc} % ensure your document is UTF-8
\usepackage[spanish]{babel}

\usepackage[demo]{graphicx} % demo option just for testing
\usepackage{caption}
\usepackage{subcaption}
\usepackage{float}
\usepackage[showframe]{geometry}
\usepackage{float}
\newcommand{\treeimg}[7]{%
\begin{figure}[htb]
\begin{subfigure}[t]{.32\textwidth}
    \includegraphics[width=\textwidth]{images/#1}
    \caption{#2}
    \label{fig:1}
\end{subfigure}
    \hfill
\begin{subfigure}[t]{.32\textwidth}
    \includegraphics[width=\textwidth]{images/#3}
    \caption{#4}
    \label{fig:2}
\end{subfigure}
    \hfill
\begin{subfigure}[t]{.32\textwidth}
    \includegraphics[width=\textwidth]{images/#5}
    \caption{#6}
    \label{fig:1}
\end{subfigure}
\caption{#7}
\end{figure}}

\begin{document}
\treeimg{1.jpg}{captionof1.jpg}{1.jpg}{captionof2.jpg}{1.jpg}{captionof3.jpg}{caption}
\treeimg{1.jpg}{captionof1.jpg}{1.jpg}{captionof2.jpg}{1.jpg}{captionof3.jpg}{caption}
\treeimg{1.jpg}{captionof1.jpg}{1.jpg}{captionof2.jpg}{1.jpg}{captionof3.jpg}{caption}
\treeimg{1.jpg}{captionof1.jpg}{1.jpg}{captionof2.jpg}{1.jpg}{captionof3.jpg}{caption}
\end{document}

enter image description here

0

Your best bet is to make the first float [bp] and the rest [tbp!]. This will fill up to \bottomfraction of the first page and possibly all of the second page.

\documentclass[11pt]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc} % ensure your document is UTF-8
\usepackage[spanish]{babel}

\usepackage[demo]{graphicx} % demo option just for testing
\usepackage{caption}
\usepackage{subcaption}
\usepackage[showframe]{geometry}
%\usepackage{float}% friends don't let frineds use [H]

\let\bottomfraction=\topfraction
\let\floatpagefraction=\topfraction

\usepackage{lipsum}

\begin{document}

\begin{figure}[bp]
\begin{subfigure}[t]{.32\textwidth}
    \includegraphics[width=\textwidth]{images/1.png}
    \caption{Image 1.}
    \label{fig:1}
\end{subfigure}
    \hfill
\begin{subfigure}[t]{.32\textwidth}
    \includegraphics[width=\textwidth]{images/1.png}
    \caption{Image 2.}
    \label{fig:2}
\end{subfigure}
    \hfill
\begin{subfigure}[t]{.32\textwidth}
    \includegraphics[width=\textwidth]{images/1.png}
    \caption{Image 3.}
    \label{fig:1}
\end{subfigure}
\caption{Title}
\end{figure}

\begin{figure}[tbp!]\ContinuedFloat
\begin{subfigure}[t]{.32\textwidth}
    \includegraphics[width=\textwidth]{images/1.png}
    \caption{Image 1.}
    \label{fig:4}
\end{subfigure}
    \hfill
\begin{subfigure}[t]{.32\textwidth}
    \includegraphics[width=\textwidth]{images/1.png}
    \caption{Image 2.}
    \label{fig:5}
\end{subfigure}
    \hfill
\begin{subfigure}[t]{.32\textwidth}
    \includegraphics[width=\textwidth]{images/1.png}
    \caption{Image 3.}
    \label{fig:6}
\end{subfigure}
\caption{Title}
\end{figure}

\begin{figure}[tbp!]\ContinuedFloat
\begin{subfigure}[t]{.32\textwidth}
    \includegraphics[width=\textwidth]{images/1.png}
    \caption{Image 1.}
    \label{fig:7}
\end{subfigure}
    \hfill
\begin{subfigure}[t]{.32\textwidth}
    \includegraphics[width=\textwidth]{images/1.png}
    \caption{Image 2.}
    \label{fig:8}
\end{subfigure}
    \hfill
\begin{subfigure}[t]{.32\textwidth}
    \includegraphics[width=\textwidth]{images/1.png}
    \caption{Image 3.}
    \label{fig:9}
\end{subfigure}
\caption{Title}
\end{figure}

\begin{figure}[tp!]\ContinuedFloat
\begin{subfigure}[t]{.32\textwidth}
    \includegraphics[width=\textwidth]{images/1.png}
    \caption{Image 1.}
    \label{fig:10}
\end{subfigure}
    \hfill
\begin{subfigure}[t]{.32\textwidth}
    \includegraphics[width=\textwidth]{images/1.png}
    \caption{Image 2.}
    \label{fig:11}
\end{subfigure}
    \hfill
\begin{subfigure}[t]{.32\textwidth}
    \includegraphics[width=\textwidth]{images/1.png}
    \caption{Image 3.}
    \label{fig:12}
\end{subfigure}
\caption{Title}
\end{figure}

\lipsum[1-6]

\end{document}
0

Not the answer you're looking for? Browse other questions tagged .