0

Related to this question. How to reduce the default gap between the two side by side images ? Thank you in advance.

  • Which gap? There is no gap? Where is the MWE that shows the gap? – Johannes_B Mar 14 '18 at 7:02
  • @Johannes_B, if you go to the hyperlink and check the first answer, between the two images in the output there's, of course, a gap, a distance. I just want to know how to reduce it. – Eureka Mar 14 '18 at 7:12
  • 1
    In one sense there is no gap, in that there is no gap between the subfigure/minipage environments. But the images inside those environments are much narrower than the width of the environment, so there is a gap between the images. So in that sense there is no default gap, it depends on how large your images are compared to the minipage/subfigure they're in, and also any space between the minipages/subfigure`s. – Torbjørn T. Mar 14 '18 at 7:51
  • @TorbjørnT., thank you for the explanation. The caption of one of the images runs to the next line. So I thought, if there's a way I can bring say that image bit closer the other, I can still keep the caption on one line. Maybe my question above wasn't clear . – Eureka Mar 14 '18 at 12:52
  • 1
    If that was what you were asking about it was utterly unclear. The width available for the caption is determined by the width of the subfigure/minipage, so make one subfigure a bit wider, the other narrower by the same amount. – Torbjørn T. Mar 14 '18 at 12:54
4

There's no gap between images. The gap is due to the size of each image inside every subfigure.

In Gonzalo's answer, every subfigure occupies half text line, but the image inside every subfigure only uses 40% of available space. This creates the gap.

Following code shows the original answer and another where images inside subfigure use the whole available space. And there is no gap!

\documentclass{article}
\usepackage{graphicx}
\usepackage{caption}
\usepackage{subcaption}

\begin{document}

\begin{figure}
\centering
\begin{subfigure}{.5\textwidth}
  \centering
  \includegraphics[width=.4\linewidth]{example-image}
  \caption{A subfigure}
  \label{fig:sub1}
\end{subfigure}%
\begin{subfigure}{.5\textwidth}
  \centering
  \includegraphics[width=.4\linewidth]{example-image}
  \caption{A subfigure}
  \label{fig:sub2}
\end{subfigure}
\caption{A figure with two subfigures}
\label{fig:test}
\end{figure}

\begin{figure}
\centering
\begin{subfigure}{.5\textwidth}
  \centering
  \includegraphics[width=\linewidth]{example-image}
  \caption{A subfigure}
  \label{fig:sub1}
\end{subfigure}%
\begin{subfigure}{.5\textwidth}
  \centering
  \includegraphics[width=\linewidth]{example-image}
  \caption{A subfigure}
  \label{fig:sub2}
\end{subfigure}
\caption{A figure with two subfigures}
\label{fig:test}
\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.