1

I have 4 images of various sizes (attached herewith). I want to place them in a 2 x 2 grid. Their widths should be the same, roughly 0.5/textwidth. I have done the following:

'''

\documentclass[12pt,onehalfspacing,headsepline,oneside,openright,a4paper]{article}
\usepackage{subcaption}
\usepackage{graphicx}
\begin{document}
\begin{figure}
    \centering
    \begin{subfigure}[t]{0.5\textwidth}
    \centering
        \raisebox{-\height}{\includegraphics[width=.8\linewidth]{images/image1.jpg}}
        \caption{Step 1: Creating a new Project}
        \vspace{1.7cm}
        \label{fig:newproj}
    \end{subfigure}%
    \begin{subfigure}[t]{0.5\textwidth}
    \centering
    \raisebox{-\height}{\includegraphics[width=.8\linewidth]{images/image2.jpg}}
        \caption{Step 3: Creating a new Model}
        \label{fig:newmod}
    \end{subfigure}
    \newline
    \begin{subfigure}{0.5\textwidth}
    \centering
        \includegraphics[width=0.8\linewidth]{images/image3.jpg}
        %\vspace{0.7cm}
        \caption{Step 5: Choosing model subsystem structure}
        \label{fig:smsc_structure}
    \end{subfigure}
    \begin{subfigure}{0.5\textwidth}
    \centering
        \includegraphics[width=0.8\linewidth]{images/image4.jpg}
        %\vspace{0.7cm}
        \caption{Step 7: Editing new Model}
        \label{fig:smsc_structure}
    \end{subfigure}
    \caption{How to make a model in OPAL-RT}
    \label{fig:scratch}
\end{figure}

\end{document}

'''

The output looks like this: output_original

But what I want is :

expected_output

To explain in words, I want the top margin and bottom margins of the figures to be flush with each other horizontally. I should be able to do the fine-tuning by using space to add space between sub-figures and captions.

Any insights about what I am doing wrong would be greatly appreciated.

Note: I am new to this forum and I am trying my best to adhere to the guidelines. Kindly give me a chance to rectify any mistakes made before downvoting.

image1 image2 image3 image4

UPDATE: With the suggestion from @David Carlisle. I have added '%' a comment after the \end{subfigure}. And Adding [t], makes the second row flush to the bottom. This is how the result looks like:

Updated_output

However, as pointed out, the numbering is now jumbled up (I need c and b to be interchanged). How do I fix that? Updated code is as follows:

'''

\documentclass[12pt,onehalfspacing,headsepline,oneside,openright,a4paper]{article}
\usepackage{subcaption}
\usepackage{graphicx}
\begin{document}
\begin{figure}
    \centering
    \begin{subfigure}[t]{0.5\textwidth}
    \centering
        \raisebox{-\height}{\includegraphics[width=.8\linewidth]{images/image1.jpg}}
        \caption{Step 1: Creating a new Project}
        %\vspace{1.7cm}
        \label{fig:newproj}
    \end{subfigure}%
    \begin{subfigure}[t]{0.5\textwidth}
    \centering
        \raisebox{-\height}{\includegraphics[width=.8\linewidth]{images/image3.jpg}}
    %\includegraphics[width=.8\linewidth]{images/image2.jpg}
        \caption{Step 5: Creating a new Model}
        \label{fig:newmod}
    \end{subfigure}
    \newline
    \begin{subfigure}[t]{0.5\textwidth}
    \centering
        \includegraphics[width=0.8\linewidth]{images/image2.jpg}
        %\vspace{0.7cm}
        \caption{Step 3: Choosing model subsystem structure}
        \label{fig:smsc_structure}
    \end{subfigure}%
    \begin{subfigure}[t]{0.5\textwidth}
    \centering
        \includegraphics[width=0.8\linewidth]{images/image4.jpg}
        %\vspace{0.7cm}
        \caption{Step 7: Editing new Model}
        \label{fig:smsc_structure}
    \end{subfigure}
    \caption{How to make a model in OPAL-RT}
    \label{fig:scratch}
\end{figure}
\end{document}

'''

2 Answers2

2

A subfigure is positioned by the same logic as a letter you have

WX
\newline
Y Z

where each of the "letters" is half of the text width.

So on the first line you get two just fitting but on the second line the word-space between them would make them not fit so you get an automatic line break at the space.

In your case the word space comes from the end of line after \end{subfigure} in the case that it is not commented out.

David Carlisle
  • 757,742
  • I understand the problem. Could you kindly point out which method I can use to put the first two images in a vertical column? If I put the 1st and 3rd subfigures together, it kind of works but then I have a problem with caption numbers. They also get rearranged. Is there a manual way to number them? – Rambo partyush Jan 26 '22 at 14:49
  • 2
    @Rambopartyush the only difference between the first two and the second two is the % hiding the word space, so if you want to put the second two in the same row add a % or if you want all 4 to be stacked vertically remove the % after the first. – David Carlisle Jan 26 '22 at 15:01
1

I am posting my answer from inputs received from David Carlisle and How to vertically label the subfigures?. I shall not accept my answer as right unless the community agrees. If not I shall choose David's answer as the right one, even though it did not exactly provide a solution.

'''

\documentclass[12pt,onehalfspacing,headsepline,oneside,openright,a4paper]{article}
\usepackage{subcaption}
\usepackage{graphicx}
\begin{document}
\begin{figure}
\begin{subfigure}[t]{0.5\textwidth}
%   \includegraphics[width=0.9\linewidth]{images/image1.jpg}
  \raisebox{-\height}{\includegraphics[width=.9\linewidth]{images/image1.jpg}}
  \vspace{0.25cm}
  \caption{First subfigure} \label{fig:1a}
  \vspace{0.25cm}
  \par\medskip % if more vertical separation needed, use \bigskip
  \includegraphics[width=0.9\linewidth]{images/image2.jpg}
  \caption{Second subfigure} \label{fig:1b}
\end{subfigure}
\hspace*{\fill}
\begin{subfigure}[t]{0.5\textwidth}
    \raisebox{-\height}{\includegraphics[width=.9\linewidth]{images/image3.jpg}}
  %\includegraphics[width=0.9\linewidth]{images/image3.jpg}
  \caption{Third subfigure} \label{fig:1c}
  \par\medskip % if more vertical separation needed, use \bigskip
  \includegraphics[width=0.9\linewidth]{images/image4.jpg}
  \caption{Fourth subfigure} \label{fig:1d}
\end{subfigure}
\caption{This is a figure with six subfigures}\label{fig:1}
\end{figure}

\end{document}

''' The outcome is as expected

outcome

  • 1
    There are other ways to renumber the captions, but his is probably the easiest. Not to mention being able to overlap the left upper and right lower images. – John Kormylo Jan 26 '22 at 17:05
  • you have two subfigure each .5\tetwidth wide and now have <wordspace>\hspace*{\fill}<wordspace> between them so they will not rot on a line and you'll get a linebreak at each of the spaces which will be discarded and then the \hspace* (being the star form will make a blank line of text. This is sort of OK but as you want them vertically stacked it would be more natural to us a blank line between them and the a \vspace rather than \hspace if you want additional space. – David Carlisle Jan 26 '22 at 17:06