4

i tried to put 6 images in a 3x2 imagebox using this code:

\begin{figure}[H]
\begin{subfigure}{0.3\textwidth}
  \centering
  \includegraphics[width=.8\linewidth]{imp_1.png}\quad
  \caption{image1}
  \label{fig:1}
\end{subfigure}%
\begin{subfigure}{0.3\textwidth}
  \centering
  \includegraphics[width=.8\linewidth]{imp_2.png}\quad
  \caption{image2}
  \label{fig:2}
\end{subfigure}
\begin{subfigure}{0.3\textwidth}\quad
  \centering
  \includegraphics[width=.8\linewidth]{imp_3.png}
  \caption{image3}
  \label{fig:3}
\end{subfigure}
\medskip
\begin{subfigure}{0.3\textwidth}
  \centering
  \includegraphics[width=.8\linewidth]{imp_4.png}\quad
  \caption{image4}
  \label{fig:4}
\end{subfigure}
\begin{subfigure}{0.3\textwidth}
  \centering
  \includegraphics[width=.8\linewidth]{imp_5.png}\quad
  \caption{image5}
  \label{fig:5}
\end{subfigure}
\begin{subfigure}{0.3\textwidth}
  \centering
  \includegraphics[width=.8\linewidth]{imp_6.png}
  \caption{image6}
  \label{fig:6}
\end{subfigure}
\caption{Fasi del processo di impregnazione}
\label{fig:images}
\end{figure}

I obtain the images as i wanted in 3 columns 2 rows, but the third one on the first row is shifted to the right, and i don't know how to fix it.

3x2 but not aligned

thank for your help!

12

One more suggestion:

  • make figure content centered with use of \centering
  • between sub figures insert \hfil
  • purpose of \quad is not clear, let remove it
  • centering of subfigure content is surplus. Rather make sub figure width smaller and adopt figure width to width of subfigure

Complete code:

\documentclass{article}
\usepackage{graphicx} 
\usepackage{caption,subcaption}
\usepackage[showframe]{geometry}

\begin{document}
\begin{figure}[htb]
    \centering % <-- added
\begin{subfigure}{0.25\textwidth}
  \includegraphics[width=\linewidth]{example-image-a}
  \caption{image1}
  \label{fig:1}
\end{subfigure}\hfil % <-- added
\begin{subfigure}{0.25\textwidth}
  \includegraphics[width=\linewidth]{example-image-b}
  \caption{image2}
  \label{fig:2}
\end{subfigure}\hfil % <-- added
\begin{subfigure}{0.25\textwidth}
  \includegraphics[width=\linewidth]{example-image-c}
  \caption{image3}
  \label{fig:3}
\end{subfigure}

\medskip
\begin{subfigure}{0.25\textwidth}
  \includegraphics[width=\linewidth]{example-image-a}
  \caption{image4}
  \label{fig:4}
\end{subfigure}\hfil % <-- added
\begin{subfigure}{0.25\textwidth}
  \includegraphics[width=\linewidth]{example-image-b}
  \caption{image5}
  \label{fig:5}
\end{subfigure}\hfil % <-- added
\begin{subfigure}{0.25\textwidth}
  \includegraphics[width=\linewidth]{example-image-c}
  \caption{image6}
  \label{fig:6}
\end{subfigure}
\caption{Fasi del processo di impregnazione}
\label{fig:images}
\end{figure}
\end{document}

The result is:

enter image description here

3

You did \quad before the the third \includegraphics moving it behind it like in the other cases should fix it.

\begin{figure}[H]
\begin{subfigure}{0.3\textwidth}
  \centering
  \includegraphics[width=.8\linewidth]{imp_1.png}\quad
  \caption{image1}
  \label{fig:1}
\end{subfigure}%
\begin{subfigure}{0.3\textwidth}
  \centering
  \includegraphics[width=.8\linewidth]{imp_2.png}\quad
  \caption{image2}
  \label{fig:2}
\end{subfigure}
\begin{subfigure}{0.3\textwidth}%"\quad" not here since this will insert a spacing before the image.
  \centering
  \includegraphics[width=.8\linewidth]{imp_3.png}\quad %but here
  \caption{image3}
  \label{fig:3}
\end{subfigure}
\medskip
\begin{subfigure}{0.3\textwidth}
  \centering
  \includegraphics[width=.8\linewidth]{imp_4.png}\quad
  \caption{image4}
  \label{fig:4}
\end{subfigure}
\begin{subfigure}{0.3\textwidth}
  \centering
  \includegraphics[width=.8\linewidth]{imp_5.png}\quad
  \caption{image5}
  \label{fig:5}
\end{subfigure}
\begin{subfigure}{0.3\textwidth}
  \centering
  \includegraphics[width=.8\linewidth]{imp_6.png}
  \caption{image6}
  \label{fig:6}
\end{subfigure}
\caption{Fasi del processo di impregnazione}
\label{fig:images}
\end{figure}
  • 1
    Please extend your answer to show the corrected code. Such one-liners are discouraged on this site. – Henri Menke Jun 25 '16 at 13:49
1

I don't think you need those \quads. Add a blank line between the rows.

\documentclass{article}
\usepackage[demo]{graphicx}
\usepackage{caption, subcaption}
\usepackage[showframe]{geometry}

\begin{document}

\begin{figure}[H]
  \begin{subfigure}{0.3\textwidth}
    \centering
    \includegraphics[width=.8\linewidth]{imp₁.png}
    \caption{image1}
    \label{fig:1}
  \end{subfigure}%
  \begin{subfigure}{0.3\textwidth}
    \centering
    \includegraphics[width=.8\linewidth]{imp₂.png}
    \caption{image2}
    \label{fig:2}
  \end{subfigure}
  \begin{subfigure}{0.3\textwidth}\quad
    \centering
    \includegraphics[width=.8\linewidth]{imp₃.png}
    \caption{image3}
    \label{fig:3}
  \end{subfigure}
  \medskip

  \begin{subfigure}{0.3\textwidth}
    \centering
    \includegraphics[width=.8\linewidth]{imp₄.png}
    \caption{image4}
    \label{fig:4}
  \end{subfigure}
  \begin{subfigure}{0.3\textwidth}
    \centering
    \includegraphics[width=.8\linewidth]{imp₅.png}
    \caption{image5}
    \label{fig:5}
  \end{subfigure}
  \begin{subfigure}{0.3\textwidth}
    \centering
    \includegraphics[width=.8\linewidth]{imp₆.png}
    \caption{image6}
    \label{fig:6}
  \end{subfigure}
  \caption{Fasi del processo di impregnazione}
  \label{fig:images}
\end{figure}

\end{document} 

enter image description here

0

Please check this:

\documentclass{article}
\usepackage{graphicx,subfigure}
\begin{document}

\begin{figure}[t!]
\centering
\subfigure[image1]{\fbox{\hbox to 5pc{\vbox to 5pc{~}}}}\quad
\subfigure[image2]{\fbox{\hbox to 5pc{\vbox to 5pc{~}}}}\quad
\subfigure[image3]{\fbox{\hbox to 5pc{\vbox to 5pc{~}}}}\quad\\
\subfigure[image4]{\fbox{\hbox to 5pc{\vbox to 5pc{~}}}}\quad
\subfigure[image5]{\fbox{\hbox to 5pc{\vbox to 5pc{~}}}}\quad
\subfigure[image6]{\fbox{\hbox to 5pc{\vbox to 5pc{~}}}}\quad
\caption{Fasi del processo di impregnazione}
\label{fig:images}
\end{figure}        
\end{document}

Replace \fbox{\hbox to 5pc{\vbox to 5pc{~}}} with \includegraphics{...}. If you need 3x2 then give \\ after second \subfigure. Now it is 2x3.

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.