# List of listings name in header

I have a two-sided book document and want to format the header such that the chapter name is on the outer part. Everything works fine, but one thing annoys me. I have some source code listings (listings package) and pseudo codes (algorithmicx package). All the chapter names are given "normally" but the list of listings (named "Listings") and list of algorithms are put in all-caps in the header.

I probably need to override some settings for these packages, but I cannot find out which. How can I change the way "Listings" and "List of Algorithms" is put by the \chaptermark command (if that's the correct one)?

Here is a small example that demonstrates the problem:

\documentclass[a4paper,twoside]{book}

\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{fancyhdr}
\usepackage{listings}

\fancypagestyle{fancyplain}{%
\fancyhf{}%
\renewcommand{\footrulewidth}{0pt}
\fancyfoot{\fancyplain}{}
}

\pagestyle{fancy}

\renewcommand{\chaptermark}[1]{\markboth{#1}{}}
\renewcommand{\sectionmark}[1]{\markright{thesection\ #1}{}}

\begin{document}

\chapter{My chapter}
\begin{lstlisting}[caption={My listing},label=lst:my_listing,language=C++]
std::cout << "Hello World!" << std::endl;
\end{lstlisting}
\cleardoublepage

\lstlistoflistings
\thispagestyle{empty}
\cleardoublepage

\end{document}

• \lstlistoflistings uses \tableofcontents, which explicitly uses \MakeUppercase --> that's the reason! – user31729 Mar 23 '16 at 10:39
• Okay, can I disable the \MakeUppercase? In your solution below I would have to override all other commands like \listoffigures, \listoftables, etc. – tickferno Mar 23 '16 at 11:51

One way is to remove or replace \tableofcontents by a modified version which does not have \MakeUppercase\contentsname.

\documentclass[a4paper,twoside]{book}

\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{fancyhdr}
\usepackage{listings}

\usepackage{xpatch}

\makeatletter

\newcommand{\othertableofcontents}{%
\if@twocolumn
\@restonecoltrue\onecolumn
\else
\@restonecolfalse
\fi
\chapter*{\contentsname
\@mkboth{%
\contentsname}{\contentsname}}%
\@starttoc{toc}%
\if@restonecol\twocolumn\fi
}
\makeatother

\xpatchcmd{\lstlistoflistings}{%\
\tableofcontents}{%
\othertableofcontents}{}{}

%\lst@UserCommand\lstlistoflistings{\bgroup
%    \let\contentsname\lstlistlistingname
%    \let\lst@temp\@starttoc \def\@starttoc##1{\lst@temp{lol}}%
%    \othertableofcontents \egroup}

\fancypagestyle{fancyplain}{%
\fancyhf{}%
\renewcommand{\footrulewidth}{0pt}
\fancyfoot{\fancyplain}{}
}

\pagestyle{fancy}

\renewcommand{\chaptermark}[1]{\markboth{#1}{}}
\renewcommand{\sectionmark}[1]{\markright{thesection\ #1}{}}

\begin{document}

\chapter{My chapter}
\begin{lstlisting}[caption={My listing},label=lst:my_listing,language=C++]
std::cout << "Hello World!" << std::endl;
\end{lstlisting}
\cleardoublepage

\lstlistoflistings
\thispagestyle{empty}
\cleardoublepage

\end{document}


Update

Since the O.P. requested to have non upper case headings for ToC, LoT etc, I suggest to use \cftmarkX from the tocloft package.

I've done this and redefined the relevant commands using \markboth{...}{...} for both margins of the page -- this is alright, since the O.P. does a redefinition later on anyway.

\documentclass[a4paper,twoside]{book}

\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{fancyhdr}
\usepackage{listings}
\usepackage{tocloft}

\renewcommand{\cftmarktoc}{\markboth{\contentsname}{\contentsname}}
\renewcommand{\cftmarklof}{\markboth{\listfigurename}{\listfigurename}}
\renewcommand{\cftmarklot}{\markboth{\listtablename}{\listtablename}}

\fancypagestyle{fancyplain}{%
\fancyhf{}%
\renewcommand{\footrulewidth}{0pt}
\fancyfoot{\fancyplain}{}
}

\pagestyle{fancy}

\renewcommand{\chaptermark}[1]{\markboth{#1}{}}
\renewcommand{\sectionmark}[1]{\markright{thesection\ #1}{}}

\begin{document}
\tableofcontents
\cleardoublepage
\listoffigures
\cleardoublepage
\listoftables
\chapter{My chapter}
\begin{lstlisting}[caption={My listing},label=lst:my_listing,language=C++]
std::cout << "Hello World!" << std::endl;
\end{lstlisting}
\cleardoublepage

\lstlistoflistings

• That works. Can I do this "globally", i.e. for all possible list types that use \tableofcontents? – tickferno Mar 23 '16 at 11:52
• @tickferno: Of course. I will update, for \tableofcontents this is easy. – user31729 Mar 23 '16 at 12:18
• @tickferno: Thanks. This is crucial to close the question as being successfully answered – user31729 Mar 25 '16 at 15:19