0

Figures go over the margins, how can I make them obey the A4 paper margins and if there's no space available make them move to next page?

MWE:

\usepackage[main=english]{babel}
\usepackage[margin=3cm,left=3cm,top=2cm,bottom=4cm]{geometry}
\usepackage{subfig}
\usepackage{float}
\usepackage{graphicx}
\graphicspath{{"/Volumes/X/Dados/teste Latex/meas 2020/"}{"/Volumes/X/Dados/teste Latex/meas 2019/"}}
\begin{document}
\section{Individual graphs}
\begin{figure}[H]
\subfloat[PRT03]{\includegraphics[width=0.3\textwidth]{"22 NFA511 191219 PRT02 meas"}}\\
\hspace{0.5cm}
\subfloat[PRT04]{\includegraphics[width=0.3\textwidth]{"22 NFA511 191219 PRT02 meas"}}\\
\hspace{0.5cm}
\subfloat[PRT04]{\includegraphics[width=0.3\textwidth]{"22 NFA511 191219 PRT02 meas"}}\\
\hspace{0.5cm}
\subfloat[PRT04]{\includegraphics[width=0.3\textwidth]{"22 NFA511 191219 PRT02 meas"}}\\
\hspace{0.5cm}
\subfloat[PRT04]{\includegraphics[width=0.3\textwidth]{"22 NFA511 191219 PRT02 meas"}}\\
\subfloat[PRT04]{\includegraphics[width=0.3\textwidth]{"22 NFA511 191219 PRT02 meas"}}\\
\subfloat[PRT04]{\includegraphics[width=0.3\textwidth]{"22 NFA511 191219 PRT02 meas"}}\\
\subfloat[PRT04]{\includegraphics[width=0.3\textwidth]{"22 NFA511 191219 PRT02 meas"}}\\
\subfloat[PRT04]{\includegraphics[width=0.3\textwidth]{"22 NFA511 191219 PRT02 meas"}}\\
\subfloat[PRT05]{\includegraphics[width=0.3\textwidth]{Tiger-80}}
\hspace{0.5cm}
\end{figure}
\end{document}



David Carlisle
  • 757,742
  • 1
    you are making them all 30% of the page width and forcing a newline with \\ after each so they are all in the left third of the page. Delete all the \\ ? – David Carlisle Feb 08 '20 at 13:15
  • problem remains after deleting all the \. I add 20 new figures and they go past margin – Luís Jervell Feb 08 '20 at 13:15
  • you have not provided any thing that lets us see the issue or test answers. Try to make a small complete document (you can use example-image as the image, which is available for tests) that shows the problem. – David Carlisle Feb 08 '20 at 13:16
  • 3
    Oh "20 new figures" ??? a figure environment is an unbreakable box, even if you get 3 per line, can you fit more than 6 or 9 on a page??? – David Carlisle Feb 08 '20 at 13:17
  • I didn't know the figure environment is an unbreakable box. Then I have to write \end {figure} before it goes past the margin and every time I add new images have to redo instructions to avoid them go past the margin. – Luís Jervell Feb 08 '20 at 13:33
  • 2
    The \ContinuedFloat command from the caption package might be useful. – leandriis Feb 08 '20 at 15:50
  • 1
    Also, instead of [H] you should use [hp]. – John Kormylo Feb 08 '20 at 16:02

1 Answers1

1

An example of collection of the 20 pictures in sequence of two figure floats. In it is used

  • \ContinuedFloat for keep the same figure number in bot floats
  • \renewcommand{\textfraction}{0.08} for enabling that float can occupy 92% of text area on page
  • images are rearranged into groups of three images per row
  • used is Gin key (\setkeys{Gin}{width=0.3\linewidth}) for setting of images width in one float (enable shorter code)
  • answer is based on this answer
\documentclass{article}
\usepackage[hmargin=3cm, top=2cm,bottom=4cm]{geometry}
\usepackage{subfig}
\usepackage{float}
\usepackage{graphicx}
\usepackage{caption}
\renewcommand{\textfraction}{0.08}  % <--- fraction of the text on page with figures
                                    % (default is 0.3, i.e. 30% text area should be text)

%\graphicspath{{"/Volumes/X/Dados/teste Latex/meas 2020/"}{"/Volumes/X/Dados/teste Latex/meas 2019/"}}
\begin{document}
\section{Individual graphs}
\begin{figure}[H]
\setkeys{Gin}{width=0.3\linewidth}
\centering
\subfloat[PRT03]{\includegraphics{example-image-duck}}
\hfil
\subfloat[PRT04]{\includegraphics{example-image-duck}}
\hfil
\subfloat[PRT04]{\includegraphics{example-image-duck}}

\subfloat[PRT04]{\includegraphics{example-image-duck}}
\hfil
\subfloat[PRT04]{\includegraphics{example-image-duck}}
\hfil
\subfloat[PRT04]{\includegraphics{example-image-duck}}

\subfloat[PRT04]{\includegraphics{example-image-duck}}
\hfil
\subfloat[PRT04]{\includegraphics{example-image-duck}}
\hfil
\subfloat[PRT04]{\includegraphics{example-image-duck}}

\subfloat[PRT04]{\includegraphics{example-image-duck}}
\hfil
\subfloat[PRT04]{\includegraphics{example-image-duck}}
\hfil
\subfloat[PRT04]{\includegraphics{example-image-duck}}

\subfloat[PRT04]{\includegraphics{example-image-duck}}
\hfil
\subfloat[PRT04]{\includegraphics{example-image-duck}}
\hfil
\subfloat[PRT04]{\includegraphics{example-image-duck}}
    \caption[Collected Graphs]{Collected Graphs (cont. on the next page)}
    \label{fig:graphs}
\end{figure}%
\begin{figure}[H]\ContinuedFloat
\setkeys{Gin}{width=0.3\linewidth}
\centering
\subfloat[PRT04]{\includegraphics{example-image-duck}}
\hfil
\subfloat[PRT04]{\includegraphics{example-image-duck}}
\hfil
\subfloat[PRT04]{\includegraphics{example-image-duck}}

\subfloat[PRT04]{\includegraphics{example-image-duck}}
\hfil
\subfloat[PRT05]{\includegraphics{example-image-duck}}
    \caption[]{Collected Graphs (cont.)}
\end{figure}
\end{document}

enter image description here

Zarko
  • 296,517
  • if some slots are to be empty (for instance row 1, 1st image is non-existent, should be empty space) how do I do it and keep the figue numbering starting only on existent images? – Luís Jervell Feb 11 '20 at 13:08
  • 1
    @LuísJervell, try to replace includegraphics{...} with \rule{0pt}{0.3\linewidth} and remove [...] label from \subfloat` (not tested) – Zarko Feb 11 '20 at 13:21