# captionsetup inside floatbox messing up image

I'm trying to include images with custom caption label format defined using \DeclareCaptionLabelFormat from caption package. If I put \captionsetup inside \floatbox environment the caption and image are not aligned properly.

\documentclass[10pt]{article}
\usepackage[usenames,dvipsnames,svgnames,table]{xcolor}
\usepackage{graphicx}
\usepackage{caption}
\usepackage{floatrow}

\DeclareCaptionFont{red}{\color{red}}
\DeclareCaptionFont{blue}{\color{blue}}
\DeclareCaptionFont{green}{\color{green}}

\DeclareCaptionLabelFormat{mycap1}{(#2) Caption label type 1}
\DeclareCaptionLabelFormat{mycap2}{(#2) Caption label type 2}

\captionsetup[figure]{labelformat=default,
labelsep=newline,
justification=centering,
labelfont={small,red,bf,it},
textfont={blue}}

\begin{document}
\begin{figure}
\begin{floatrow}
\floatbox{figure}
{\captionsetup{labelformat=mycap1}}
{\caption {Caption for this figure}}
{\includegraphics[scale=0.5]{sample.png}}
\end{floatrow}
\end{figure}
\end{document}


If I remove \captionsetup after \floatbox the image and caption are aligned properly, but I'll not be able to get custom label for the caption. What am I missing here?

• Welcome to TeX.SX! You can have a look at our starter guide to familiarize yourself further with our format. – texenthusiast Jul 12 '13 at 4:55
• You should use \floatbox{figure}{\captionsetup{labelformat=mycap1}\caption {Caption for this figure}}{\includegraphics[scale=0.5]{sample.png}} instead since \floatbox has three (and not four) mandatory arguments. – Axel Sommerfeldt Jul 12 '13 at 7:36
• Thats it. Fixed it. – Surya Jul 12 '13 at 8:13
• @AxelSommerfeldt: An answer please ;-) – Marco Daniel Jul 12 '13 at 10:29

Axel Sommerfeldt wrote:

You should use

\floatbox%
{%first mandatory argument
figure%
}%
{%second mandatory argument
\captionsetup{labelformat=mycap1}%
\caption {Caption for this figure}%
}%
{%third mandatory argument
\includegraphics[scale=0.5]{sample.png}%
}


instead since \floatbox has three (and not four) mandatory arguments.