
Tengo un book
documento de dos caras y quiero formatear el encabezado de manera que el nombre del capítulo esté en la parte exterior. Todo funciona bien, pero una cosa me molesta. Tengo algunos listados de código fuente ( listings
paquete) y pseudocódigos ( algorithmicx
paquete). Todos los nombres de los capítulos se dan "normalmente", pero la lista de listados (llamada "Listados") y la lista de algoritmos se colocan en mayúsculas en el encabezado.
Probablemente necesite anular algunas configuraciones para estos paquetes, pero no puedo encontrar cuál. ¿Cómo puedo cambiar la forma en que el comando coloca "Listados" y "Lista de algoritmos" \chaptermark
(si es la correcta)?
Aquí hay un pequeño ejemplo que demuestra el problema:
\documentclass[a4paper,twoside]{book}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{fancyhdr}
\usepackage{listings}
\fancypagestyle{fancyplain}{%
\renewcommand{\headrulewidth}{0pt}
\fancyhf{}%
\renewcommand{\footrulewidth}{0pt}
\fancyfoot{\fancyplain}{}
}
\pagestyle{fancy}
\renewcommand{\chaptermark}[1]{\markboth{#1}{}}
\renewcommand{\sectionmark}[1]{\markright{thesection\ #1}{}}
\renewcommand{\lhead}[1]{\fancyhead[OL,ER]{\fancyplain{}\chaptermark{#1}}}
\fancyhead[OR,EL]{\fancyplain{}\thepage}
\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
\addcontentsline{toc}{chapter}{Listings}
\thispagestyle{empty}
\cleardoublepage
\end{document}
Respuesta1
Una forma es eliminarlo o reemplazarlo \tableofcontents
por una versión modificada que no tenga \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}{%
\renewcommand{\headrulewidth}{0pt}
\fancyhf{}%
\renewcommand{\footrulewidth}{0pt}
\fancyfoot{\fancyplain}{}
}
\pagestyle{fancy}
\renewcommand{\chaptermark}[1]{\markboth{#1}{}}
\renewcommand{\sectionmark}[1]{\markright{thesection\ #1}{}}
\renewcommand{\lhead}[1]{\fancyhead[OL,ER]{\fancyplain{}\chaptermark{#1}}}
\fancyhead[OR,EL]{\fancyplain{}\thepage}
\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
\addcontentsline{toc}{chapter}{Listings}
\thispagestyle{empty}
\cleardoublepage
\end{document}
Actualizar
Dado que el OP solicitó tener títulos que no estén en mayúsculas ToC
, LoT
etc., sugiero usarlos \cftmarkX
desde el tocloft
paquete.
Hice esto y redefiní los comandos relevantes usando \markboth{...}{...}
ambos márgenes de la página; esto está bien, ya que el OP hace una redefinición más adelante de todos modos.
\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}{%
\renewcommand{\headrulewidth}{0pt}
\fancyhf{}%
\renewcommand{\footrulewidth}{0pt}
\fancyfoot{\fancyplain}{}
}
\pagestyle{fancy}
\renewcommand{\chaptermark}[1]{\markboth{#1}{}}
\renewcommand{\sectionmark}[1]{\markright{thesection\ #1}{}}
\renewcommand{\lhead}[1]{\fancyhead[OL,ER]{\fancyplain{}\chaptermark{#1}}}
\fancyhead[OR,EL]{\fancyplain{}\thepage}
\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
\addcontentsline{toc}{chapter}{Listings}
\thispagestyle{empty}
\cleardoublepage
\end{document}