
両面book
文書があり、章名が外側になるようにヘッダーをフォーマットしたいと考えています。すべて正常に動作しますが、1 つ気になることがあります。ソース コード リスト (listings
パッケージ) と疑似コード (algorithmicx
パッケージ) があります。章名はすべて「通常どおり」指定されていますが、リストのリスト (「Listings」という名前) とアルゴリズムのリストはヘッダーですべて大文字で入力されています。
おそらく、これらのパッケージのいくつかの設定を上書きする必要があると思いますが、どれを上書きすればよいのかわかりません。コマンドによって「リスト」と「アルゴリズムのリスト」が表示される方法を変更するにはどうすればよいですか\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
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
OP は、などの大文字以外の見出しを要求したので、パッケージからLoT
使用することをお勧めします。\cftmarkX
tocloft
私はこれを実行し、ページの両方の余白に を使用して関連するコマンドを再定義しました\markboth{...}{...}
。いずれにしても、OP は後で再定義を行うので、これは問題ありません。
\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}