5

I am trying to customize the captions of my figures, this is what I achieved so far:

enter image description here

Which is ok, but as you can see the parbox exceeds the width, and its right margin is not precisely aligned. How can I fix it? This is the MWE:

\documentclass[11pt, a4paper, oneside]{memoir}

\usepackage{graphicx}
\usepackage{color}

\usepackage{caption}
\DeclareCaptionFont{white}{ \color{white} }
\DeclareCaptionFormat{figure}{
  \colorbox[cmyk]{0.43, 0.35, 0.35,0.01 }{
    \noindent
    \parbox{\linewidth}{#1#2#3}
  }
}
\captionsetup[figure]{ format=figure, labelfont=white, textfont=white, margin=0pt, font={bf,small,sf} }

\begin{document}

Nullam quis risus eget urna mollis ornare vel eu leo. Maecenas sed diam eget risus varius blandit sit amet non magna. Sed posuere consectetur est at lobortis. Nulla vitae elit libero, a pharetra augue. Nulla vitae elit libero, a pharetra augue. Integer posuere erat a ante venenatis dapibus posuere velit aliquet.

  \begin{figure}[h!t]
  \centering
    \includegraphics[width=\linewidth]{treemap.jpg}
    \caption{A treemap (source Wikipedia)}
    \label{fig:treemap}
  \end{figure}

  Nullam quis risus eget urna mollis ornare vel eu leo. Maecenas sed diam eget risus varius blandit sit amet non magna. Sed posuere consectetur est at lobortis. Nulla vitae elit libero, a pharetra augue. Nulla vitae elit libero, a pharetra augue. Integer posuere erat a ante venenatis dapibus posuere velit aliquet.

\end{document}
gcedo
  • 2,699
  • 23
  • 20
  • See: http://tex.stackexchange.com/questions/88193/center-caption-in-listing –  Jun 01 '13 at 11:28

1 Answers1

4

You're adding spaces and not taking into account that \colorbox adds some padding. Do

\usepackage{caption}
\DeclareCaptionFont{white}{\color{white}}
\DeclareCaptionFormat{figure}{%
  \colorbox[cmyk]{0.43, 0.35, 0.35,0.01 }{%
    \parbox{\dimexpr\columnwidth-2\fboxsep}{#1#2#3}%
  }
}
\captionsetup[figure]{
  format=figure,
  labelfont=white,
  textfont=white,
  margin=0pt,
  font={bf,small,sf}
}

You should be using \columnwidth rather than \linewidth. Notice the protection against spaces where TeX is supposed to typeset material. The format of \captionsetup I used is not mandatory, but it helps having the options in greater evidence.

enter image description here

egreg
  • 1,121,712