
У меня есть двусторонний book
документ, и я хочу отформатировать заголовок так, чтобы название главы было на внешней части. Все работает отлично, но меня раздражает одна вещь. У меня есть некоторые листинги исходного кода ( listings
package) и псевдокоды ( algorithmicx
package). Все названия глав даны "обычно", но список листингов (с именем "Listings") и список алгоритмов в заголовке написаны заглавными буквами.
Мне, вероятно, нужно переопределить некоторые настройки для этих пакетов, но я не могу найти какие. Как изменить способ, которым "Listings" и "List of Algorithms" помещаются командой \chaptermark
(если это правильный)?
Вот небольшой пример, демонстрирующий проблему:
\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}
решение1
Один из способов — удалить или заменить \tableofcontents
модифицированной версией, не имеющей \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}
Обновлять
Поскольку автор публикации попросил не использовать заголовки с заглавными буквами для ToC
и LoT
т. д., я предлагаю использовать \cftmarkX
из tocloft
пакета.
Я сделал это и переопределил соответствующие команды, используя \markboth{...}{...}
для обоих полей страницы — это нормально, поскольку автор в любом случае сделает переопределение позже.
\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}