49

I want to reduce the space between two subfigures and use that space to make those subfigures large. How to do that? My code is as follows:

\begin{figure}[htp]
  \centering
  \subfigure[1a]{\label{fig1:a}\includegraphics[width=1.6in]{./fig1a.eps}}\hfill
  \subfigure[1b]{\label{fig1:b}\includegraphics[width=1.6in]{./fig1b.eps}}
  \label{fig1}
\end{figure}
2

5 Answers 5

77

Consider the following minimal example that shows three different ways of spacing sub-figures:

  1. Maximum length
  2. Equal lengths
  3. Fixed length

Different lengths separating subfigures

\documentclass{article}
\usepackage{showframe,subcaption,graphicx}
\begin{document}
\begin{figure}[htp]
  % Maximum length
  \subcaptionbox{1a\label{fig1:a}}{\includegraphics[width=1.6in]{example-image-a}}\hfill%
  \subcaptionbox{1b\label{fig1:b}}{\includegraphics[width=1.6in]{example-image-a}}%

  \bigskip

  % Equal length
  \hspace*{\fill}%
  \subcaptionbox{2a\label{fig2:a}}{\includegraphics[width=1.6in]{example-image-b}}\hfill%
  \subcaptionbox{2b\label{fig2:b}}{\includegraphics[width=1.6in]{example-image-b}}%
  \hspace*{\fill}%

  \bigskip

  % Fixed length
  \centering
  \subcaptionbox{3a\label{fig3:a}}{\includegraphics[width=1.6in]{example-image-c}}\hspace{1em}%
  \subcaptionbox{3b\label{fig3:b}}{\includegraphics[width=1.6in]{example-image-c}}
\end{figure}

\end{document}​

The showframe package was loaded to highlight the text block boundaries. Note the use of % for precise spacing. See What is the use of percent signs (%) at the end of lines? for more on this.

  1. Maximum length: Here a stretchable length of \hfill is used to push both subfigures to the edges of the text block. Note the % at the end of the second subfigure, if you're placing content on the following line.

  2. Equal lengths: A stretchable length is placed on either side of the subfigures to equalize the length from the text block boundary as well as between the subfigures. Note the use of \hspace*{\fill} on either side of the subfigures, while \hfill suffices between them.

  3. Fixed length: Use a fixed \hspace{<len>} between the subfigures, together with \centering to centre and separate the subfigures by a fixed distance <len> (1em in my example).

Some comments:

  • Note the use of % at the end of lines. They do add spurious spaces in your output. While it may not be visible, you may not get exact lengths otherwise. See What is the use of percent signs (%) at the end of lines? for more on this.

  • Only method 3 (fixed length) requires \centering, unless you're also providing a figure caption (which you didn't in your code snippet. Moreover, using \label without a \caption does not help here. It works within \subcaptionbox (from subcaption), since it writes a caption, but you would still need a separate \caption for your figure environment for \label{fig1} to yield anything.

1
  • For the equal length case exists a special function called "\hfil" with only one "l". This does exactly the same as your code :)
    – jovobe
    Commented Feb 17, 2017 at 21:54
6

use a relative width:

\documentclass{article}
\usepackage{showframe}% only for demo
\usepackage{subfig}
\usepackage[demo]{graphicx}% [demo] only for demo
\begin{document}
\begin{figure}[!htp]
  % Maximum length
  \subfloat[1a]{\label{fig1:a}\includegraphics[width=0.49\linewidth]{fig1a}}\hfill
  \subfloat[1b]{\label{fig1:b}\includegraphics[width=0.49\linewidth]{fig1b}}%
\end{figure}

\end{document}​

enter image description here

6

In my case, the subfig package introduces a default space of a little less than 1em between two figures. I still need them tight, as the two figures correspond in major features, so I found it helpful to tweak the spacing with negative horizontal space as well.

\documentclass[draft]{article}
\usepackage{subfig}
\usepackage{graphicx}
\begin{document}
\begin{figure}[htbp]
    \centering
    \subfloat[Subfigure caption 1.]{
        \includegraphics[width=0.75\textwidth] {img1.png}
        \label{fig:img1} } \hspace*{-0.9em}
    \subfloat[Subfigure caption 2.]{
        \includegraphics[width=0.25\textwidth] {img2.png}
        \label{fig:img2} } \\
    \caption{Two corresponding images.}
    \label{fig:img}
\end{figure}
\end{document}
1
4

To use all the space available remove the hfill (or keep it, it doesn't really change) and set a relative width .49\textwidth. You may actually want to try a slightly lower value to leave some space between them.

\begin{figure}[htp]
  \centering
  \subfigure[1a]{\label{fig1:a}\includegraphics[width=.49\textwidth]{./fig1a.eps}}
  \subfigure[1b]{\label{fig1:b}\includegraphics[width=.49\textwidth]{./fig1b.eps}}
  \label{fig1}
\end{figure}
0

This turns out to be the best solution for me as it allows to keep using the subfigure environment.

Original post : Syntax similar to \centering for right and left?

\documentclass{article}
\usepackage[export]{adjustbox}

\begin{document}
\begin{figure}
    \begin{subfigure}{.5\textwidth}
        \includegraphics[width=\linewidth, right]{img1}
    \end{subfigure}
    \begin{subfigure}{.5\textwidth}
            \includegraphics[width=\linewidth, left]{img2}
    \end{subfigure}
\end{figure}
\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .