Graphics, Figures & TablesHow to move the caption of a subfigure right?

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
loujing
Posts: 9
Joined: Mon Jun 01, 2015 7:13 pm

How to move the caption of a subfigure right?

Post by loujing »

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".]
3.png
3.png (18.16 KiB) Viewed 35755 times
Thanks for your help.

Code: Select all

\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}
Before:
1.png
1.png (5.9 KiB) Viewed 35755 times
After:
2.png
2.png (6.21 KiB) Viewed 35755 times
Last edited by cgnieder on Tue Oct 04, 2016 5:42 pm, edited 2 times in total.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

User avatar
Stefan Kottwitz
Site Admin
Posts: 10324
Joined: Mon Mar 10, 2008 9:44 pm

How to move the caption of a subfigure right?

Post by Stefan Kottwitz »

Very good minimal example!

The subfigure package is obsolete, it's recommended to use the subfig package instead. You could use the \captionsetup command to define a margin for the shifting. You can call it before each sub float command to adjust as needed.

Code: Select all

\documentclass{article}
\usepackage{subfig}
\usepackage[demo]{graphicx}
\begin{document}
\begin{figure}
\centering
\captionsetup[subfigure]{oneside,margin={0.5cm,0cm}}
\subfloat[caption for a]{
\includegraphics[width=3.5cm,height=3cm]{dummy}%
}
\captionsetup[subfigure]{oneside,margin={1.4cm,0cm}}
\subfloat[capture for b]{
\includegraphics[width=3.5cm,height=3cm]{dummy}%
}
\subfloat[caption for c]{
\includegraphics[width=3.5cm,height=3cm]{dummy}%
}
\end{figure}
\end{document}
Stefan
LaTeX.org admin
loujing
Posts: 9
Joined: Mon Jun 01, 2015 7:13 pm

How to move the caption of a subfigure right?

Post by loujing »

Stefan Kottwitz wrote:Very good minimal example!

The subfigure package is obsolete, it's recommended to use the subfig package instead. You could use the \captionsetup command to define a margin for the shifting. You can call it before each sub float command to adjust as needed.

Code: Select all

\documentclass{article}
\usepackage{subfig}
\usepackage[demo]{graphicx}
\begin{document}
\begin{figure}
\centering
\captionsetup[subfigure]{oneside,margin={0.5cm,0cm}}
\subfloat[caption for a]{
\includegraphics[width=3.5cm,height=3cm]{dummy}%
}
\captionsetup[subfigure]{oneside,margin={1.4cm,0cm}}
\subfloat[capture for b]{
\includegraphics[width=3.5cm,height=3cm]{dummy}%
}
\subfloat[caption for c]{
\includegraphics[width=3.5cm,height=3cm]{dummy}%
}
\end{figure}
\end{document}
Stefan
Thanks for your help.

Now I'm using a given LaTeX template to write my thesis. If I do not modify the given template, I wonder if it is possible to tackle this problem by only using "subfigure" .
User avatar
Stefan Kottwitz
Site Admin
Posts: 10324
Joined: Mon Mar 10, 2008 9:44 pm

How to move the caption of a subfigure right?

Post by Stefan Kottwitz »

How much does it hurt do change to subfig? It only affects subfigures, so no worries about other things, and the changes are simple, as you can see above. That's easier than hacking the old unsupported subfigure package.

Stefan
LaTeX.org admin
loujing
Posts: 9
Joined: Mon Jun 01, 2015 7:13 pm

How to move the caption of a subfigure right?

Post by loujing »

Stefan Kottwitz wrote:How much does it hurt do change to subfig? It only affects subfigures, so no worries about other things, and the changes are simple, as you can see above. That's easier than hacking the old unsupported subfigure package.

Stefan

Thanks for your suggestion.

Sorry, I'm not familiar to LaTeX.

I search "subfigure" in the template and try to modify them to "subfig" (totally two places). Although I comment all "figure codes", I still get a few errors as the uploaded figure. But my thesis works well when I use "subfigure".
I do not know how to tackle this problem.

Code: Select all

\usepackage{subfigure} -> \usepackage{subfig}  (in the xxx.sty)
\RequirePackage{graphicx,psfrag,flafter,subfigure}  -> \RequirePackage{graphicx,psfrag,flafter,subfig} (in the xxx.cls)
My environment is texlive2014 + TeXstudio.
Attachments
4.png
4.png (88.03 KiB) Viewed 35738 times
Last edited by cgnieder on Tue Oct 04, 2016 8:24 pm, edited 1 time in total.
User avatar
Stefan Kottwitz
Site Admin
Posts: 10324
Joined: Mon Mar 10, 2008 9:44 pm

How to move the caption of a subfigure right?

Post by Stefan Kottwitz »

It seems that you still load subfigure, so you get a clash with the subfig package (same commands, since it's the successor). Find where you load subfigure still, and remove it. If necessary, upload the full template as .zip file as attachment, if you like.

Stefan
LaTeX.org admin
loujing
Posts: 9
Joined: Mon Jun 01, 2015 7:13 pm

How to move the caption of a subfigure right?

Post by loujing »

Stefan Kottwitz wrote:It seems that you still load subfigure, so you get a clash with the subfig package (same commands, since it's the successor). Find where you load subfigure still, and remove it. If necessary, upload the full template as .zip file as attachment, if you like.

Stefan
Thanks.

My template is downloaded from https://github.com/jiec827/njustThesis, and the URL of .zip is https://codeload.github.com/jiec827/nju ... zip/master
Due to the maximum upload size, I failed to upload it.
loujing
Posts: 9
Joined: Mon Jun 01, 2015 7:13 pm

How to move the caption of a subfigure right?

Post by loujing »

Stefan Kottwitz wrote:It seems that you still load subfigure, so you get a clash with the subfig package (same commands, since it's the successor). Find where you load subfigure still, and remove it. If necessary, upload the full template as .zip file as attachment, if you like.

Stefan
Thank you for your code and suggestion again. I have modified the template and replaced subfigure with subfig. Now it works well.
Post Reply