[Tex/LaTex] lstlistoflistings font

fontslistingstable of contents

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?

Best Answer

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}
Related Question