1

I insert subfigures using the \subfig package:

\documentclass{article}
\usepackage{graphicx}
\usepackage{subfig}
\begin{document}
\begin{figure}
  \subfloat[]{
    \includegraphics[width=0.5\textwidth]{example-image-a}
  }
  \subfloat[]{
    \includegraphics[width=0.5\textwidth]{example-image-b}
  }
  \subfloat[]{
    \includegraphics[width=0.5\textwidth]{example-image-c}
  }
\end{figure}
\end{document}

The result is:

enter image description here

As can be seen, image c is already outside the page. I would like to keep the figure inside the page.

How to achieve this without inserting \\ manually?

  • Do you want c to continue in the next line or reduce the size? – user36296 Jun 13 '18 at 20:58
  • I already fixed the size - width=0.5\textwidth. Therefore, I am looking for a line break. – Viesturs Jun 13 '18 at 21:00
5

To provide possible breaking points for a line break, you could add \hfill between the subfloats. As the first two images occupy anyway the whole line, ot does not hurt there and the third image can go to a new line.

\documentclass{article}
\usepackage{graphicx}
\usepackage{subfig}
\begin{document}
\begin{figure}
  \subfloat[]{%
    \includegraphics[width=0.5\textwidth]{example-image-a}%
  }%
  \hfill
  \subfloat[]{%
    \includegraphics[width=0.5\textwidth]{example-image-b}%
  }%
  \hfill
  \subfloat[]{%
    \includegraphics[width=0.5\textwidth]{example-image-c}%
  }%
\end{figure}
\end{document}
  • Could you please remind the purpose of %? – Viesturs Jun 13 '18 at 21:29
  • @Viesturs Otherwise an additional space would be inserted at every line end. You'll notice the white gap between the two pictures in your original code and there is an overfull box warning even if there are just two of the images. – user36296 Jun 13 '18 at 22:33
2

if you fixed image width to 0.5\textwidth, than apparently the third image should be placed on the next line. for this insert empty line after the second image:

\documentclass{article}
\usepackage{graphicx}
\usepackage{subfig}
\begin{document}
\begin{figure}
\centering
  \subfloat[]{\includegraphics[width=0.5\textwidth]{example-image-a}}
  \subfloat[]{\includegraphics[width=0.5\textwidth]{example-image-b}}

  \subfloat[]{\includegraphics[width=0.5\textwidth]{example-image-duck}}
\end{figure}
\end{document}

enter image description here

as you can see, your selection of the image width cause, that image to touch each other. i would selece slightly smaller width, for example 0.48\textwidth and between first and second image insert \hfill:

\documentclass{article}
\usepackage{graphicx}
\usepackage{subfig}
\begin{document}
\begin{figure}
\centering
  \subfloat[]{\includegraphics[width=0.48\textwidth]{example-image-a}}
  \hfill
  \subfloat[]{\includegraphics[width=0.48\textwidth]{example-image-b}}

  \subfloat[]{\includegraphics[width=0.48\textwidth]{example-image-duck}}
\end{figure}
\end{document}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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