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 wanted to edit my floats. Found the package floatrow and got the desired frames easily for them. Now i would like to add a backgroundcolor to the captions. The problem is that the \parbox, i inserted to captionsetup, is bigger than the frame of the float and doesn't end up with the frame. I wrote an example:

\documentclass{article}
\usepackage{caption}
\usepackage{floatrow} 
\floatsetup[figure]{framestyle=fbox,
           framearound=all,rowfill=yes}
\DeclareCaptionFormat{box}{
\colorbox{red}{\parbox{\textwidth}{#1#2#3}}
 } 
\captionsetup[figure]{format=box}
%%
\begin{document}
\begin{figure}
    TEST TEST TEST
\caption{BLA}
\end{figure}
\end{document}
share|improve this question
add comment

2 Answers

Just solved the problem by changing \frameset, adding an additional \makebox and some \vspace's:

\documentclass{article}
\usepackage{caption}
\usepackage{floatrow}
\floatsetup{style=BOXED, frameset={\fboxsep0pt}}
\DeclareCaptionFormat{box}{\colorbox{red}{\makebox[\dimexpr\captionwidth]
    {\parbox{\dimexpr\textwidth-7pt}{\vspace{1ex}#1#2#3\vspace{1ex}}}}}
\captionsetup{format=box}
%%%%
\begin{document}
\begin{figure}
    TEST TEST TEST
\caption{BLA}
\end{figure}
\end{document}
share|improve this answer
add comment

A \colorbox adds additional margins, i.e. \fboxsep, so one need to subtract it two times from the \textwidth.

The easiest way to fix this is to use the pre-defined colorbox of the caption package which code already respects \fboxsep:

\documentclass{article}
\usepackage{caption}
\usepackage{floatrow} 
\floatsetup[figure]{framestyle=fbox,
           framearound=all,rowfill=yes}
\captionsetup[figure]{box=colorbox,boxcolor=red,slc=off}
%%
\begin{document}
\begin{figure}
    TEST TEST TEST
\caption{BLA}
\end{figure}
\end{document}

enter image description here

Note that this needs at least v3.3 of the caption package (and is not documented yet since I simply did not find the time to document it so far...) If v3.3 is not available and updating is not an option, one could (of course) adapt the original code by removing extra spaces and subtracting 2\fboxsep from the \parbox width:

\documentclass{article}
\usepackage{caption}
\usepackage{floatrow} 
\floatsetup[figure]{framestyle=fbox,
           framearound=all,rowfill=yes}
\DeclareCaptionFormat{box}{%
\colorbox{red}{\parbox{\dimexpr\captionwidth-2\fboxsep}{#1#2#3}}%
 } 
\captionsetup[figure]{format=box}
%%
\begin{document}
\begin{figure}
    TEST TEST TEST
\caption{BLA}
\end{figure}
\end{document}
share|improve this answer
    
mmh ok, thanks for your help. is there any other chance with other packages? Especially i would like to have the colorbox ending with the frame, so that there is no white frame around the colorbox. –  Robert Jan 27 '13 at 20:12
    
@Robert It's not clear to me what you mean by "with other packages" since I didn't changed the packages used. However, I just have added code which works with older versions of the caption package, too. –  Axel Sommerfeldt Jan 28 '13 at 7:54
    
Your code you added works fine, thanks for that, but it's not exactly the result i wished. I would like to have the colorbox been surrounded by the frame. I don't like the small white space between colorbox and frame. Any suggestions to solve this problem? Thanks for your help! –  Robert Jan 28 '13 at 18:07
    
\documentclass{article} \usepackage{caption} \usepackage{floatrow} \floatsetup{style=BOXED, frameset={\fboxsep0pt}} \DeclareCaptionFormat{box}{\colorbox{red}{\makebox[\dimexpr\captionwidth] {\parbox{\dimexpr\textwidth-7pt}{\vspace{1ex}#1#2#3 \vspace{1ex}}}}} \captionsetup{format=box} %%%% \begin{document} \begin{figure} TEST TEST TEST \caption{BLA} \end{figure} \end{document} –  Robert Jan 31 '13 at 23:32
add comment

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.