4

My demo code is as follows. Now the caption of each subfigure is displayed centered. How can I move each caption (including the counter) by 0.5cm right?

[PS: I want the caption "(a) Data" is aligned centrally to the center of "Threshold".]

\documentclass{article}
\usepackage{subfigure}
\usepackage[demo]{graphicx}
\begin{document}
\begin{figure}
\centering
\subfigure[caption for a]{
    \includegraphics[width=3.5cm,height=3cm]{dummy}%
}
\subfigure[capture for b]{
    \includegraphics[width=3.5cm,height=3cm]{dummy}%
}
\subfigure[caption for c]{
    \includegraphics[width=3.5cm,height=3cm]{dummy}%
}
\end{figure}
\end{document}

enter image description here

Werner
  • 603,163
loujing
  • 53

2 Answers2

5

The issue lies with the vertical axis labels that are included in your image. Since they protrude out to the left, it seems like the sub-caption should shift to the right.

One way to fix this - which is independent of the sub-figure package you may be using, is to insert some space to the right of the images, thereby simulating some axis labels on the right. Alternatively, you can shift the caption to the left by inserting some space at the right of the sub-caption.

Here are some examples:

enter image description here

\documentclass{article}

\usepackage{subcaption,graphicx}

\begin{document}

\begin{figure}
  \centering
  \subcaptionbox{First}{%
    \includegraphics[width=3.5cm,height=3cm]{example-image-a}%
  }\qquad
  \subcaptionbox{Second}{%
    \includegraphics[width=3.5cm,height=3cm]{example-image-b}%
  }

  \bigskip

  \subcaptionbox{First}{%
    \includegraphics[width=3.5cm,height=3cm]{example-image-a}\hspace*{2em}%
  }\qquad
  \subcaptionbox{Second}{%
    \hspace*{2em}\includegraphics[width=3.5cm,height=3cm]{example-image-b}%
  }

  \bigskip

  \subcaptionbox{First\hspace*{2em}}{%
    \includegraphics[width=3.5cm,height=3cm]{example-image-a}%
  }\qquad
  \subcaptionbox{\makebox[0pt][l]{Second}}{%
    \includegraphics[width=3.5cm,height=3cm]{example-image-b}%
  }
\end{figure}

\end{document}

In the above example, (a) and (b) are the controls, while (c) and (d) have spaces set to the right and left of the images, respectively. This enlarges the "images", thereby shifting the caption. (e) shifts the caption to the left as a result of adding space to the right. (f) shifts the caption to the right by setting the caption in a [l]eft-aligned box of lesser (0pt) width.

Werner
  • 603,163
  • It works well. Thanks a lot for your kind help. But I still have a question. If I have fixed the size and interval of all figures, I wonder if it is possible to tackle this problem by only using the command "\subfigure"? – loujing Oct 04 '16 at 17:08
  • Thanks a lot for your kind help. I have modified the template and replaced subfigure with subfig. Now it works well. – loujing Oct 05 '16 at 16:16
  • Isn't there a solution where the label can be shifted? My images are so big that I can't insert space... – trinity420 Aug 16 '23 at 22:53
  • @trinity420: Do you have whitespace around your images? If so, you can clip/trim those. – Werner Aug 21 '23 at 20:02
  • @Werner No, I have not. However, I switched to subfig package which solves this problem in a one-liner, thanks. – trinity420 Aug 24 '23 at 15:20
0

I found a simpler and better solution than the accepted, without adding space to images (e.g. when your images are too big). Just add:

\captionsetup[subfigure]{oneside,margin={0.5cm,0cm}}

before \begin{subfigure}. Adjust to your desired margin. To change it for another subfigure, just re-use it and change amount of shifting.