标题中两次列出“列表”

标题中两次列出“列表”

我的文档中的标题显示:下面的章节和节。它还显示其他“节”,如“列表列表”等。

问题是:“列表列表”显示两次,看起来很丑。我怎样才能让它只显示在标题的第二行(显示部分的位置)?

这是我的(简化的)代码:

\documentclass[
   final,
   12pt,
   a4paper,
   oneside
]{book}

\usepackage{tocloft}% to alighn the TOC numbers on the right
\usepackage{setspace}
\usepackage{epstopdf}
\usepackage{textcomp}
\usepackage{listings}

%%# IN NEW BEGIN
\usepackage{lipsum}
\usepackage[headheight=30pt,
            a4paper,
            left=42mm,
            right=29mm,
            top=32mm,
            bottom=38mm
]{geometry}  % or %\setlength{\headheight}{30pt}
%% IN NEW END

\usepackage{fancyhdr}
    %\pagestyle{fancy}
    %\pagestyle{fancyplain}
    %\fancyhead{}
    %\fancyfoot{}
    \fancyhead[L]{}
    \fancyhead[R]{\small\nouppercase\leftmark\\\small\nouppercase\rightmark}
    \fancyfoot[L]{\rule{2cm}{1cm}}
    \fancyfoot[R]{\thepage}
    \fancyfoot[C]{}
    \fancypagestyle{plain}{%
        \fancyhf{} % clear all header and footer fields
        \fancyhead[R]{\small\nouppercase\leftmark\\\small\nouppercase\rightmark}
        \fancyfoot[L]{\rule{2cm}{1cm}}
        \fancyfoot[R]{\thepage}
        \fancyfoot[C]{}
        \renewcommand{\headrule}{{%
        \hrule height 1.9pt width\headwidth
        \vspace{1.6pt}%
        \hrule height 0.9pt width\headwidth
    }}}
    \renewcommand{\headrule}{{%
        \hrule height 1.9pt width\headwidth
        \vspace{1.6pt}%
        \hrule height 0.9pt width\headwidth
    }}


\begin{document}
\renewcommand{\cftchapaftersnum}{.}

%%# IN NEW BEGIN
\pagestyle{fancy}
%%# IN NEW END

\frontmatter
\pagenumbering{Roman}

%% OUT NEW BEGIN
%\fancyfoot[RO, LE] {\small\thepage}
%\thispagestyle{empty}
%\fancyfoot[R] {\thepage}
%% OUT NEW END

\setlength{\parindent}{0pt}
\setlength{\parskip}{12pt}

\renewcommand\lstlistingname{Code listing}
\renewcommand\lstlistlistingname{List of Listings}
\rhead{\small{List of Listings}}
\addcontentsline{toc}{chapter}{List of Listings}
\lstlistoflistings

\mainmatter

%% IN NEW BEGIN
\renewcommand{\sectionmark}[1]{\markright{\thesection~#1}}
%% IN NEW END

\pagenumbering{arabic}
\onehalfspacing

%% OUT NEW BEGIN
%\fancyhead{}
%\pagestyle{plain}
%\lhead{}
%\rhead{\small\nouppercase\leftmark\\\small\nouppercase\rightmark}
%\fancyfoot[R] {\thepage}
%% OUT NEW END

\setlength{\parindent}{0pt}
\setlength{\parskip}{12pt}

\chapter{Some Chapter}
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.

\section{Some section}

Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.


\end{document}

答案1

您必须修补\tableofcontents(同样,\listoffigures\listoftables),因为它会发出\markboth{\contentsname}{\contentsname}。因此这也成立\rightmark,结果就是您所发现的。

我还建议使用toclofttitles选项进行加载,这样它就不会覆盖这些命令的定义。

补丁包括:

\usepackage{etoolbox}

\makeatletter
\patchcmd{\tableofcontents}
  {\@mkboth{\MakeUppercase\contentsname}{\MakeUppercase\contentsname}}
  {\@mkboth{\MakeUppercase\contentsname}{}}
  {}{}
\makeatother

另外需要注意的是,在和之后发出\pagenumbering是多余的。考虑到您使用,您真的确定要将和 设置为零吗?请不要这样做。\frontmatter\mainmatter\parindent\parskip\onehalfspacing

\documentclass[
   final,
   12pt,
   a4paper,
   oneside
]{book}

\usepackage[titles]{tocloft}% to alighn the TOC numbers on the right
\usepackage{setspace}
\usepackage{epstopdf}
\usepackage{textcomp}
\usepackage{listings}
\usepackage{etoolbox}

%%# IN NEW BEGIN
\usepackage{lipsum}
\usepackage[headheight=30pt,
            a4paper,
            left=42mm,
            right=29mm,
            top=32mm,
            bottom=38mm
]{geometry}  % or %\setlength{\headheight}{30pt}
%% IN NEW END

\usepackage{fancyhdr}
    %\pagestyle{fancy}
    %\pagestyle{fancyplain}
    %\fancyhead{}
    %\fancyfoot{}
    \fancyhead[L]{}
    \fancyhead[R]{\small\nouppercase\leftmark\\\small\nouppercase\rightmark}
    \fancyfoot[L]{\rule{2cm}{1cm}}
    \fancyfoot[R]{\thepage}
    \fancyfoot[C]{}
    \fancypagestyle{plain}{%
        \fancyhf{} % clear all header and footer fields
        \fancyhead[R]{\small\nouppercase\leftmark\\\small\nouppercase\rightmark}
        \fancyfoot[L]{\rule{2cm}{1cm}}
        \fancyfoot[R]{\thepage}
        \fancyfoot[C]{}
        \renewcommand{\headrule}{{%
        \hrule height 1.9pt width\headwidth
        \vspace{1.6pt}%
        \hrule height 0.9pt width\headwidth
    }}}
    \renewcommand{\headrule}{{%
        \hrule height 1.9pt width\headwidth
        \vspace{1.6pt}%
        \hrule height 0.9pt width\headwidth
    }}

\makeatletter
\patchcmd{\tableofcontents}
  {\@mkboth{\MakeUppercase\contentsname}{\MakeUppercase\contentsname}}
  {\@mkboth{\MakeUppercase\contentsname}{}}
  {}{\ddt}
\makeatother

\begin{document}
\renewcommand{\cftchapaftersnum}{.}

%%# IN NEW BEGIN
\pagestyle{fancy}
%%# IN NEW END

\frontmatter

%% OUT NEW BEGIN
%\fancyfoot[RO, LE] {\small\thepage}
%\thispagestyle{empty}
%\fancyfoot[R] {\thepage}
%% OUT NEW END

\setlength{\parindent}{0pt}
\setlength{\parskip}{12pt}

\renewcommand\lstlistingname{Code listing}
\renewcommand\lstlistlistingname{List of Listings}
\rhead{\small{List of Listings}}
\addcontentsline{toc}{chapter}{List of Listings}
\lstlistoflistings

\mainmatter

%% IN NEW BEGIN
\renewcommand{\sectionmark}[1]{\markright{\thesection~#1}}
%% IN NEW END

\onehalfspacing

%% OUT NEW BEGIN
%\fancyhead{}
%\pagestyle{plain}
%\lhead{}
%\rhead{\small\nouppercase\leftmark\\\small\nouppercase\rightmark}
%\fancyfoot[R] {\thepage}
%% OUT NEW END

\setlength{\parindent}{0pt}
\setlength{\parskip}{12pt}

\chapter{Some Chapter}
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.

\section{Some section}

Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.


\end{document}

在此处输入图片描述

如果您希望标题位于下行,请将补丁更改为

\makeatletter
\patchcmd{\tableofcontents}
  {\@mkboth{\MakeUppercase\contentsname}{\MakeUppercase\contentsname}}
  {\@mkboth{\mbox{}}{\MakeUppercase\contentsname}}
  {}{}
\makeatother

相关内容