3

I observe a problem with the labels of subcaptions generated by the subfig package. The distance between label and caption is wrong, but only if I change the color with \addtokomafont and if the color is the last parameter I change. Here's the code:

\documentclass{scrbook}

\usepackage[colorlinks=true]{hyperref}
\usepackage{subfig}
\addtokomafont{captionlabel}{\sffamily\color{blue}}
%\addtokomafont{captionlabel}{\color{blue}\sffamily}

\begin{document}
\begin{figure}
    \center
    \subfloat[][Test.]{\rule{2cm}{2cm}}
    \quad
    \subfloat[][Test.]{\rule{3cm}{2cm}}
    \caption{foo}
\end{figure}
\end{document}

and the result:

Picture showing the problem.

(With the standard fonts it is not that obvious as with my font selection, therefore just for clarification: in the picture, a space character is missing between “(a)” and “Test.” and the same for “(b)”) Since exchanging the color selection with the font selection is already a workaround (see commented line in the code), I have no particular problem but I'm interested in why it behaves like that. Also, maybe others observe the problem by only selecting a color which would not lead them to the workaround. Therefore I ask for some clarification about the mechanism and if it can be solved generally.

Since I consider this a bug, but several packages are involved (hyperref, KOMAscript, subfig), to whom should I send the bug report?

2

The subfig package loads caption, so it's best to use the features of this package.

\documentclass{scrbook}

\usepackage{xcolor}
\usepackage{subfig}

\DeclareCaptionLabelFormat{bluesf}{\sffamily\color{blue}#1 #2}
\DeclareCaptionLabelFormat{subbluesf}{\sffamily\color{blue}(#2)}
\DeclareCaptionLabelSeparator{bluecolon}{\sffamily\color{blue}: }
\captionsetup{labelformat=bluesf,labelsep=bluecolon}
\captionsetup[subfloat]{labelformat=subbluesf}

\begin{document}
\begin{figure}
    \centering
    \subfloat[][Test.]{\rule{2cm}{2cm}}
    \quad
    \subfloat[][Test.]{\rule{3cm}{2cm}}
    \caption{foo}
\end{figure}
\end{document}

Note that \centering is the correct command to use.

enter image description here

However, subfig behaves badly with hyperref, so you might want to consider subcaption.

\documentclass{scrbook}

\usepackage{xcolor}
\usepackage{subcaption}

\DeclareCaptionLabelFormat{bluesf}{\sffamily\color{blue}#1 #2}
\DeclareCaptionLabelFormat{subbluesf}{\sffamily\color{blue}(#2)}
\DeclareCaptionLabelSeparator{bluecolon}{\sffamily\color{blue}: }
\captionsetup{labelformat=bluesf,labelsep=bluecolon}
\captionsetup[subfigure]{labelformat=subbluesf}

\begin{document}
\begin{figure}
\centering

\subcaptionbox{Test.}{\rule{2cm}{2cm}}
\quad
\subcaptionbox{Test.}{\rule{3cm}{2cm}}

\caption{foo}
\end{figure}
\end{document}

The output is exactly the same.

0

A workaround is already given in the question. If the color selection is the only thing to achieve, one could use a command that does not lead to a change in the appearance. E. g., \color{blue}\null works in that case or, maybe better \color{blue}{} (an empty group).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.