0

I have been trying to include 4 subfigures but none of the code I have tried has worked but one. I think it is due to usepackage interference but I don't know. Anyway I manage to get the following:

\begin{figure}[ht]
  \subfloat[first image]{
    \begin{minipage}[c][1\width]{
       0.3\textwidth}
       \centering
       \includegraphics[width=1\textwidth]{6.png}
    \end{minipage}}
 \hfill     
  \subfloat[second image]{
    \begin{minipage}[c][1\width]{
       0.3\textwidth}
       \centering
       \includegraphics[width=1.1\textwidth]{6.png}
    \end{minipage}}
 \hfill 
 \subfloat[third image]{
    \begin{minipage}[c][1\width]{
       0.3\textwidth}
       \centering
       \includegraphics[width=1.2\textwidth]{6}
    \end{minipage}}
    \hfill  
  \subfloat[fourth image]{
    \begin{minipage}[c][1\width]{
       0.3\textwidth}
       \centering
       \includegraphics[width=1.2\textwidth]{6}
    \end{minipage}}
\caption{}
\end{figure}

It gives me the output in the figure below. enter image description here

My question is if I can rearrange these so I have two subfigures at the top and two subfigures at the bottom?

  • Did you already try to replace the \hfill between the second and third \subfloat with an empty line? – leandriis May 14 '21 at 16:09
  • They are positioned like letters (using the same code) you have a \hfill b \hfill c \hfill d so at least one word space between each and fitting as many as possible on the line, you want a\hfill b blank line c\hfill d so two paragraphs with two in each. – David Carlisle May 14 '21 at 17:12

1 Answers1

0

enter image description here

With an empty line between the second and thid \subfloat you can get two images per row. The minipage environments are not really needed, so I removed them. I also made sure all images are of the same size. This was different in your original code.

\documentclass{article}
\usepackage[demo]{graphicx} % remove the demo option in your real document.
\usepackage{subfig}
\begin{document}

\begin{figure}[ht] \subfloat[first image]{\includegraphics[width=0.3\textwidth]{6.png}} \hfill
\subfloat[second image]{\includegraphics[width=0.3\textwidth]{6.png}}

\subfloat[third image]{\includegraphics[width=0.3\textwidth]{6}} \hfill
\subfloat[fourth image]{\includegraphics[width=0.3\textwidth]{6}} \caption{} \end{figure}

\end{document}

leandriis
  • 62,593
  • Thanks! This helped a lot! Is there any smooth way of reducing the spacing between the images? – John Greger May 16 '21 at 15:22
  • Depending on how large the space shoul be, you could replace \hfill wiht \quad or \qquad or any other command for horizontal space. If you want the images to be horizontally centered on the page, make sure to add \centeirng to the beginning of the figure environment. – leandriis May 16 '21 at 15:24