Text FormattingConstrain Caption underneath Figure

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
Post Reply
User avatar
Cham
Posts: 937
Joined: Sat Apr 02, 2011 4:06 pm

Constrain Caption underneath Figure

Post by Cham »

I'm using the subfig, graphicx, array and booktabs packages.

How can I tell LaTeX to constrain the caption under a figure to be of the same width as the picture itself ?

I'm just not sure anymore of the right caption width that I should use for a book. Currently, the caption will take all the page's width, if the caption's text is large enough.

What should be the best caption width ?

EDIT : I tested the margin option but I'm now having a spacement problem with the sub-captions, as shown on the picture below. What is wrong with my caption config (I'm using the subfig package) ?

Code: Select all

\captionsetup{
  margin=1cm,
  font=small,
  format=plain,
  labelfont={bf,up},
 textfont={it}
}
Attachments
caption.jpg
caption.jpg (30.89 KiB) Viewed 7375 times

Recommended reading 2024:

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

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

localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

To constrain the caption under the figures

Post by localghost »

By now you should know that an adequate problem description includes a minimal example. Otherwise I'm pessimistic about specific help.

But since you have a global caption setup that leaves a margin of 1cm, this will also affect captions for sub-figures. For a remedy you can try a setup only for sub-figures.

Code: Select all

\captionsetup[subfigure]{…}
Due to a missing example this is only an assumption. For details you should consult the caption manual.


Thorsten
User avatar
Cham
Posts: 937
Joined: Sat Apr 02, 2011 4:06 pm

To constrain the caption under the figures

Post by Cham »

localghost wrote:But since you have a global caption setup that leaves a margin of 1cm, this will also affect captions for sub-figures. For a remedy you can try a setup only for sub-figures.

Code: Select all

\captionsetup[subfigure]{…}

Ahaa ! Thanks for the info, I think I now solved my problem with this code (please, can you confirm that there isn't any inconsistencies with this ?) :

Code: Select all

\usepackage{subfig}
\captionsetup{
	margin=1cm,
	format=hang,
	font=small,
	format=plain,
	labelfont={bf,up},
	textfont={it}}
\captionsetup[subfigure]{
	margin=0cm,
	font=small,
	format=plain,
	labelfont={bf,up},
	textfont={up}}
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

To constrain the caption under the figures

Post by localghost »

Cham wrote:[…](please, can you confirm that there isn't any inconsistencies with this ?) […]
At the moment I don't have an appropriate example at hand. But I guess it will work. The best confirmation would be if you just test it. No fear, your machine won't explode.
User avatar
Cham
Posts: 937
Joined: Sat Apr 02, 2011 4:06 pm

To constrain the caption under the figures

Post by Cham »

Yes, I tried it and it's working very well. However, I'm a bit nervous about editing codes that I don't understand perfectly. I just want to be sure that the caption setup will not introduce something bad elsewhere in the whole document.

I tend to add more commands and parameters that I really need, and sometimes there are packages "clashes"...

EDIT : For example : I just noticed that my index entries do not point to the right page. I don't know why. Apparently, this has nothing to do with the figures captions.

I'll give a minimalist code later today... My book is now extremely complicated. The preamble is very large with lots of specific commands and macros.
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

To constrain the caption under the figures

Post by localghost »

Cham wrote:Yes, I tried it and it's working very well. However, I'm a bit nervous about editing codes that I don't understand perfectly. I just want to be sure that the caption setup will not introduce something bad elsewhere in the whole document. […]
No need to be nervous. And if it solves the issue, it's good. It's very unlikely that this code will have undesired side effects since the caption package is written very tidy. Furthermore it contains accommodations to many classes and packages in order to avoid clashes.
Cham wrote:[…] I tend to add more commands and parameters that I really need, and sometimes there are packages "clashes"... […]
If you don't insert too much code at a time, you will be able to revert your changes easily. Just have nerve. You can't mess up your document in a way that you won't be able to recover it.
Cham wrote:[…] For example : I just noticed that my index entries do not point to the right page. I don't know why. Apparently, this has nothing to do with the figures captions. […]
That would be indeed stuff for a separate question.
Cham wrote:[…] I'll give a minimalist code later today... My book is now extremely complicated. The preamble is very large with lots of specific commands and macros.
Since the problem is solved I think that this is not necessary any more.
User avatar
Cham
Posts: 937
Joined: Sat Apr 02, 2011 4:06 pm

Re: To constrain the caption under the figures

Post by Cham »

Thanks a lot for your help.

I'll start another topic elsewhere, about my index which don't point to the right page in all cases. There's something fishy here.
Post Reply