4

together with latex i use the subcaption package for subfigures. I use different font styles (like italics, bold, sans serif) in the captions for certain terms. Those font styles are used in the list of figures as well.

Now my question is, if there is any way to overwrite all font styles for the list of figures automatically (without using \caption[without style]{with style}). In the list of figures only one font shall be used.

And i have another question: How can i reduce the spacing between the number (a,b,...) and the title of the subfigure in the list of figures?

4

Here's one possibility: the idea is to \let the font attributes you don't want to use in the list to be, for example \rmfamily (for font switches) or \textrm (for font commands with one argument); this is done \AtBeginDocument using \addtocontents{lof}{...} so the redefinitions only have effect for the LoF.

To change the separation between the number/letter and the title for subfigures in the LoF, you need to redefine \l@subsubsection (for article) or \l@subsection (for book, report); this redefinition has to be done before loading subcaption; then, you can redefine it again, to restore its original meaning for the ToC, if you want to.

\documentclass{article}
\makeatletter
\renewcommand*\l@subsubsection{\@dottedtocline{3}{3.8em}{2em}}
\makeatother
\usepackage{subcaption}

\captionsetup[subfigure]{list=true}

\makeatletter
\AtBeginDocument{
  \addtocontents{lof}{%
    \let\sffamily\rmfamily
    \let\scshape\rmfamily
    \let\textbf\textrm
    \let\textit\textrm
  }
}
\renewcommand*\l@subsubsection{\@dottedtocline{3}{3.8em}{3.2em}}
\makeatother

\begin{document}

\tableofcontents
\listoffigures

\section{Test section}
\subsection{Test section}
\subsubsection{Test section}

\begin{figure}[!ht]
\centering
\begin{subfigure}{.5\linewidth}
\centering
A
\caption{{\scshape test} \textbf{subfigure}}
\end{subfigure}%
\begin{subfigure}{.5\linewidth}
\centering
B
\caption{another {\sffamily test} \textit{subfigure}}
\end{subfigure}
\caption{A figure with subfigures}
\end{figure}

\end{document}

enter image description here

1

You can define a conditional command that applies or not the formatting given as its argument; the conditional is set to false at the start of the list of figure and to true at its end.

Formatting commands not prefixed by \maybe will be honored anyway.

\documentclass{article}

\usepackage{subcaption}

\captionsetup[subfigure]{list=true}

\AtBeginDocument{\addtocontents{lof}{\protect\formatfalse}}
\AtEndDocument{\addtocontents{lof}{\protect\formattrue}}
\newif\ifformat
\formattrue
\makeatletter
\DeclareRobustCommand{\maybe}[1]{%
  \ifformat
    \expandafter#1%
  \else
    \expandafter\@firstofone
  \fi
}
\makeatother

\begin{document}

\tableofcontents
\listoffigures

\section{Test section}
\subsection{Test section}
\subsubsection{Test section}

\begin{figure}[!ht]
\centering
\begin{subfigure}{.5\linewidth}
\centering
A
\caption{\maybe\textsc{test} \maybe\textbf{subfigure}}
\end{subfigure}%
\begin{subfigure}{.5\linewidth}
\centering
B
\caption{another \maybe\textsf{test} \maybe\textit{subfigure}}
\end{subfigure}
\caption{A figure with subfigures}
\end{figure}

\end{document}

enter image description here

Thanks to Gonzalo for the example document.

  • With this solution i would have to modify each caption individually. This is what i wanted to prevent. – Jonas Sep 7 '13 at 8:30

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.