標題中的清單名稱

標題中的清單名稱

我有一個雙面book文檔,想要格式化標題,使章節名稱位於外部。一切都很好,但有一件事讓我很惱火。我有一些原始程式碼清單(listings包)和偽代碼(algorithmicx包)。所有章節名稱均“正常”給出,但列表列表(名為“列表”)和演算法列表在標題中全部大寫。

我可能需要覆蓋這些包的一些設置,但我無法找出哪些設置。如何更改命令放置“列表”和“演算法列表”的方式\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}

更新

由於 OP 要求 等具有非大寫標題ToC,我建議從包中LoT使用。\cftmarkXtocloft

\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}

相關內容