# captionsetup redefines my margin captions nicely, but I want other captions to be default style

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}

\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

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.

-

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}

\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

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}

-
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