我正在尝试自定义图形的标题,这是我目前所取得的成就:
没问题,但如您所见,parbox 超出了宽度,并且其右边距未精确对齐。我该如何修复它?这是 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}
答案1
你添加了空格,但没有考虑到\colorbox
添加了一些填充。
\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}
}
您应该使用\columnwidth
而不是\linewidth
。请注意 TeX 应该排版材料的地方对空格的保护。\captionsetup
我使用的 格式不是强制性的,但它有助于在更多证据中提供选项。