1

Current scenario

I wanted to align the four images in a grid of 2x2, but the images are getting arranged vertically. I'm working on a template of IEEE format. This is the code that I'm working on:

\begin{figure}[!tbp]
\centering

\begin{subfigure}{0.25\textwidth}
\includegraphics[width=0.7\linewidth,height=5cm,center]{MobileApp/Menu.png}
\caption{Menu}
\label{fig:menu}
\end{subfigure}

\begin{subfigure}{0.25\textwidth}
\includegraphics[width=0.7\linewidth,height=5cm,center]{MobileApp/Cart.png}
\caption{Cart}
\label{fig:cart}
\end{subfigure}

\begin{subfigure}{0.25\textwidth}
\includegraphics[width=0.7\linewidth,height=5cm,center]{MobileApp/Address.png}
\caption{Address selection}
\label{fig:address}
\end{subfigure}

\begin{subfigure}{0.25\textwidth}
\includegraphics[width=0.7\linewidth,height=5cm,center]{MobileApp/Payment.png}
\caption{Payment screen}
\label{fig:payment}
\end{subfigure}

\caption{Main screens of the application}
\label{fig:main}
\end{figure}

Any suggestions as to what needs to be done to get them arranged in a grid?

  • Because you are leaving an empty line between them. In TeX an empty line means a paragraph break. Remove the empty line and end the first and third subfigures with \end{subfigure}% (the % is important). – Phelype Oleinik May 03 '19 at 13:34
  • @PhelypeOleinik Thanks for the suggestion, it worked! Earlier I wasn't leaving a line though, but didn't add that % sign. – Amey Meher May 03 '19 at 13:38
  • @PhelypeOleinik Yup, now realized had the same mistake. – Amey Meher May 03 '19 at 13:41
  • Good to know it worked :) I marked a duplicate for your question, which is essentially the same problem. My answer there explains why the % is important. Essentially, it's because when you have a line break TeX reads it as a space, then the width of the figures plus the space don't fit in the line so TeX breaks the line in that space. Adding the % removes that space so the subfigures are “glued” to each other. – Phelype Oleinik May 03 '19 at 13:42
  • @PhelypeOleinik Thanks for the explanation! Just started with tex so couldn't relate earlier XD – Amey Meher May 03 '19 at 13:46
  • You're welcome :) In this case, welcome to TeX! Hope you enjoy your stay :) – Phelype Oleinik May 03 '19 at 13:48
  • Also, you appear to be in twocolumn mode, so you need figure" instead of figure. – John Kormylo May 03 '19 at 14:04

0 Answers0