5

I'd like to change my list of listings to match my list of figures, which I have changed using tocloft:

\renewcommand{\cftfigfont}{\sffamily\mdseries\upshape}

Is there a way to do the same with my list of listings?

3

This is not possible using tocloft commands, but you can emulate tocloft's behaviour by redefining \l@lstlisting. (Note: If you don't want to redefine \cftfigpagefont, you have to omit the second \sffamily in my redefinition of \l@lstlisting.)

\documentclass{article}

% \usepackage{tocloft}
% \renewcommand{\cftfigfont}{\sffamily}
% \renewcommand{\cftfigpagefont}{\sffamily}

\usepackage{listings}
\makeatletter
\renewcommand*{\l@lstlisting}[2]{\@dottedtocline{1}{1.5em}{2.3em}{\sffamily#1}{\sffamily#2}}
\makeatother

\begin{document}

\listoffigures
\lstlistoflistings

\section{foo}

\begin{figure}[!ht]
\centering
\rule{1cm}{1cm}
\caption{A figure}
\end{figure}

\begin{lstlisting}[caption={A listing}]
(Listing content)
\end{lstlisting}

\end{document}
1
  • If you don't want to change the fonts, this is meant: \renewcommand*{\l@lstlisting}[2]{\@dottedtocline{1}{<lengthFromLeftMargin>}{lengthFromNumbersStartToLabelsStart}{#1}{#2}} – kando Aug 19 '16 at 15:40

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.