Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I'm writing a document with small and supporting figures placed in wide margins and larger figures in the text. I use the captions package and redefine the captions with

\captionsetup{
justification=raggedright
font=small}

and use this for my margin figure captions, which works fine. Since there are so few words on each line of the margin captions it looks ugly when Latex stretches the caption to cover the entire margin width, hence the raggedright.

Now, the problem is that the \captionsetup also redefines my "normal" captions, so that they also become raggedright, which I don't want.

So, the elements of my file are:

\usepackage{captions}

\addtolength{\evensidemargin}{1.5cm} 
\addtolength{\textwidth}{-1.5cm}
\addtolength{\marginparwidth}{20pt}
\addtolength{\marginparsep}{10pt}

\captionsetup{
justification=raggedright
font=small}

\begin{document}

text text text ...

\begin{figure}
\begin{center}    
\includegraphics{figure1}
\caption{figure 1 text, which I don't want to have a raggedright justification, since it looks quite good without it due to the many words that I can fit into one line in this type of caption.}    
\end{center}
\end{figure}

some 

more 

text 

about 

something

\marginpar{\includegraphics[width=\marginparwidth]{figure2}
\captionof{figure}{Here for figure 2, the caption will look odd when few words are stretched across the marginparwidth}}

\end{document}

So, I want the \captionof to produce a different kind of caption than what caption does when used inside a figure environment. Thankful for any hints. I had a look at the tufte class but is seems to me that all captions have a raggedright justifcation in that class.

share|improve this question

1 Answer 1

up vote 6 down vote accepted

You could use \captionsetup[<name>]{...} ... \captionsetup{options=<name>} to define and execute options for custom commands or environments, e.g.:

\documentclass{article}
\usepackage[demo]{graphicx}
\usepackage{caption}

\addtolength{\evensidemargin}{1.5cm} 
\addtolength{\textwidth}{-1.5cm}
\addtolength{\marginparwidth}{20pt}
\addtolength{\marginparsep}{10pt}

\captionsetup[marginfigure]{
justification=raggedright,
font=small}

\newcommand\marginfigure[1]{%
  \marginpar{%
    \captionsetup{type=figure,options=marginfigure}%
    #1}}

\begin{document}

text text text ...

\begin{figure}
\centering
\includegraphics{figure1}
\caption{figure 1 text, which I don't want to have a raggedright justification, since it looks quite good without it due to the many words that I can fit into one line in this type of caption.}    
\end{figure}

some 

more 

text 

about 

something

\marginfigure{\includegraphics[width=\marginparwidth]{figure2}
\caption{Here for figure 2, the caption will look odd when few words are stretched across the marginparwidth}}

\end{document}
share|improve this answer
    
I works exactly as I wanted - thank you –  Carina May 24 '12 at 20:42
    
@Carina: please consider accepting Axel's answer; in case of doubt, please see How do you accept an answer?. –  Gonzalo Medina May 24 '12 at 23:30

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.