在目录中添加“章节”字样---页码

在目录中添加“章节”字样---页码

我厌倦了做不成功的事情!!我正在写论文,我正在使用这个模板https://github.com/kks32/phd-thesis-template/。然而,我需要实施一些变革,而我自己无法成功做到。

  1. 我需要在目录中的章节号和章节名称前添加 chapter 一词(使用 tocbibind 包)。这部分类似于这个帖子。我之前已经尝试过此代码,但是它在每个一级标题前都添加了单词 chapter,而我希望将其限制为主要章节,而不包含图表列表、首字母缩略词甚至附录。

以下是 MWE:

       \documentclass{report}
       \usepackage{tocbibind}

       \begin{document}
       \tableofcontents

       \section{test 1}
        First document. This is a simple example, with no 
          extra parameters or packages included.
        \end{document}

在添加 Chapter 一词之前

然后,我将以下代码添加到模板中,它执行并给出了我想要的内容,但目录中每个一级标题之前都有单词 chapter。

     \makeatletter
     \renewcommand*\l@chapter[2]{%
     \ifnum \c@tocdepth >\m@ne
     \addpenalty{-\@highpenalty}%
     \vskip 1.0em \@plus\p@
     \setlength\@tempdima{1.5em}%
     \begingroup
     \settowidth{\@tempdimb}{\normalsize\bfseries \chaptername~}%
     \advance\leftskip by \@tempdimb
     \parindent \z@ \rightskip \@pnumwidth
     \parfillskip -\@tempdima
     \leavevmode \bfseries
     \advance\leftskip\@tempdima
     \hskip -\leftskip
     \chaptername~#1\nobreak\hfil \nobreak\hb@xt@\@pnumwidth{\hss #2}\par
     \penalty\@highpenalty
     \endgroup
     \fi}
     \makeatother

以下是修改后的最终版本:

   \documentclass{report}
   \usepackage{tocbibind}

 \makeatletter
 \renewcommand*\l@chapter[2]{%
 \ifnum \c@tocdepth >\m@ne
 \addpenalty{-\@highpenalty}%
 \vskip 1.0em \@plus\p@
 \setlength\@tempdima{1.5em}%
 \begingroup
 \settowidth{\@tempdimb}{\normalsize\bfseries \chaptername~}%
 \advance\leftskip by \@tempdimb
 \parindent \z@ \rightskip \@pnumwidth
 \parfillskip -\@tempdima
 \leavevmode \bfseries
 \advance\leftskip\@tempdima
 \hskip -\leftskip
 \chaptername~#1\nobreak\hfil \nobreak\hb@xt@\@pnumwidth{\hss #2}\par
 \penalty\@highpenalty
 \endgroup
 \fi}
 \makeatother


 \begin{document}
  \tableofcontents

  \chapter{Test 1}
   First document. This is a simple example, with no extra parameters or packages included.
   \end{document}

执行代码后(添加 Word 章节后)

  1. 在章节第一页中,没有页码,并且我希望页码显示在页面的右上角...我一直在试图找出确切的代码在哪里,可以抑制页码显示在章节标题页上,但没有成功。

答案1

查看辅助文件时,我注意到常规章节已使用\numberline,而其他章节未使用。因此,我将添加的移至\chaptername\numberline

\documentclass{report}
   \usepackage{tocbibind}

 \makeatletter
 \renewcommand*\l@chapter[2]{%
 \ifnum \c@tocdepth >\m@ne
 \addpenalty{-\@highpenalty}%
 \vskip 1.0em \@plus\p@
 \setlength\@tempdima{1.5em}%
 \begingroup
   \let\oldnumberline=\numberline
   \def\numberline{\chaptername~\oldnumberline}%
   \settowidth{\@tempdimb}{\normalsize\bfseries \chaptername~}%
   \advance\leftskip by \@tempdimb
   \parindent \z@ \rightskip \@pnumwidth
   \parfillskip -\@tempdima
   \leavevmode \bfseries
   \advance\leftskip\@tempdima
   \hskip -\leftskip
   #1\nobreak\hfil \nobreak\hb@xt@\@pnumwidth{\hss #2}\par
   \penalty\@highpenalty
 \endgroup
 \fi}

 \def\ps@plain{% first page of a chapter
      \def\@oddhead{\normalfont\hfil\thepage}%
      \let\@evenhead\@oddhead
      \let\@oddfoot\@empty
      \let\@evenfoot\@empty}
 \makeatother


 \begin{document}
  \tableofcontents

  \chapter{Test 1}
   First document. This is a simple example, with no extra parameters or packages included.
   \end{document}

此解决方案在 内添加了章节/附录名称 ( \@chapapp) \addcontentsline。它使用单独的调用来\addtocontents设置长标题的缩进。

\documentclass{report}
   \usepackage{tocbibind}
   \usepackage{appendix}

\newlength{\tocindent}

 \makeatletter
\def\@chapter[#1]#2{\ifnum \c@secnumdepth >\m@ne
                         \refstepcounter{chapter}%
                         \typeout{\@chapapp\space\thechapter.}%
                         \settowidth{\tocindent}{\normalsize\bfseries \@chapapp\space}% complute additonal indentation
                         \addtocontents{toc}{\protect\tocindent=\the\tocindent}% store in TOC
                         \addcontentsline{toc}{chapter}%
                                   {\@chapapp~\protect\numberline{\thechapter}#1}%
                    \else
                      \addcontentsline{toc}{chapter}{#1}%
                    \fi
                    \chaptermark{#1}%
                    \addtocontents{lof}{\protect\addvspace{10\p@}}%
                    \addtocontents{lot}{\protect\addvspace{10\p@}}%
                    \if@twocolumn
                      \@topnewpage[\@makechapterhead{#2}]%
                    \else
                      \@makechapterhead{#2}%
                      \@afterheading
                    \fi}

\renewcommand*\l@chapter[2]{%
  \ifnum \c@tocdepth >\m@ne
    \addpenalty{-\@highpenalty}%
    \vskip 1.0em \@plus\p@
    \setlength\@tempdima{1.5em}%
    \begingroup
      \parindent \z@ \rightskip \@pnumwidth
      \parfillskip -\@pnumwidth
      \leavevmode \bfseries
      \advance\leftskip\@tempdima
      \advance\leftskip\tocindent% only change
      \hskip -\leftskip
      #1\nobreak\hfil
      \nobreak\hb@xt@\@pnumwidth{\hss #2%
                                 \kern-\p@\kern\p@}\par
      \penalty\@highpenalty
    \endgroup
  \fi}

 \def\ps@plain{% first page of chapter
      \def\@oddhead{\normalfont\hfil\thepage}%
      \let\@evenhead\@oddhead
      \let\@oddfoot\@empty
      \let\@evenfoot\@empty}
 \makeatother


 \begin{document}
  \tableofcontents

  \chapter{Test 1}
   First document. This is a simple example, with no extra parameters or packages included.

  \chapter{This is a very long chapter title, which goes on and on until the next line}

  \appendix
  \def\chaptername{Appendix}
  \chapter{Test 2}
   \end{document}

答案2

以下是使用包的建议tocbasic

\documentclass{report}
\usepackage{tocbibind}

\usepackage{tocbasic}
\DeclareTOCStyleEntry[
  entrynumberformat=\entrywithprefix{\chaptername},
  dynnumwidth
]{tocline}{chapter}
\newcommand*\entrywithprefix[2]{#1~#2}

\begin{document}
\tableofcontents
\chapter{Foo}

\section{Bar}
First document. This is a simple example, with no 
extra parameters or packages included.
\end{document}

运行三次即可获得

在此处输入图片描述

相关内容