在 Latex 中每章的第一页添加自定义目录

在 Latex 中每章的第一页添加自定义目录

我正在尝试在每章的第一页添加目录,使用以下问题的答案:如何使用书籍类获取这个精美的章节页面

有两个问题:第一,为什么chapter.10会出现这个词?第二,我希望目录只显示章节,不显示子章节。

编辑:

我正在使用该MastersDoctoralThesis课程,可以在以下链接中找到:http://www.latextemplates.com/templates/theses/1/thesis_1.zip

我的 MWE:

    \documentclass[
    14pt, % The default document font size, options: 10pt, 11pt, 12pt
    oneside, % Two side (alternating margins) for binding by default, uncomment to switch to one side
    english, % ngerman for German
     ]{MastersDoctoralThesis} % The class file specifying the document structure

    % My Dissertation Rules for Line spacing + paragraph spacing + identation

    \linespread{1.4}
    \setlength{\parskip}{0.5cm}
    \setlength{\parindent}{1.5cm}
    \usepackage{mathptmx}

    % Float to use H in placing figures and tables
    \usepackage{float}

    %write algorithms
    \usepackage{algorithm}
    \usepackage{algpseudocode}
    \usepackage{pifont}

    \algnewcommand\algorithmicinput{\textbf{Input:}}
    \algnewcommand\INPUT{\item[\algorithmicinput]}
    \algnewcommand\algorithmicoutput{\textbf{Output:}}
    \algnewcommand\OUTPUT{\item[\algorithmicinput]}


    % Adding sub TOC
    \usepackage[explicit]{titlesec}
    \usepackage{titletoc}
    \usepackage{tikz}
    \usepackage{epigraph}
    \usepackage{xpatch}
    \usepackage{lmodern}

    \newlength\ChapWd
    \settowidth\ChapWd{\huge\chaptertitlename}

    \definecolor{myblue}{RGB}{0,0,122}

    \titleformat{\chapter}[display]
      {\normalfont\filcenter\sffamily}
      {\tikz[remember picture,overlay]
        {
        \node[fill=myblue,font=\fontsize{60}{72}\selectfont\color{white},anchor=north east,minimum size=\ChapWd]
          at ([xshift=-15pt,yshift=-15pt]current page.north east)
          (numb) {\thechapter};
        \node[rotate=90,anchor=south,inner sep=0pt,font=\huge] at (numb.west) {\chaptertitlename};
        }
      }{0pt}{\fontsize{33}{40}\selectfont\color{myblue}#1}[\vskip10pt\Large***]
    \titlespacing*{\chapter}
      {0pt}{50pt}{10pt}


    \makeatletter
    \xpatchcmd{\ttl@printlist}{\endgroup}{{\noindent\color{myblue}\rule{\textwidth}{1.5pt}}\vskip30pt\endgroup}{}{}
    \makeatother

    \newcommand\DoPToC{%
    \setcounter{tocdepth}{1}
    \startcontents[chapters]
    \printcontents[chapters]{}{1}{\noindent{\color{myblue}\rule{\textwidth}{1.5pt}}\par\medskip}%
    }

    % End of TOC

    % Drop Cap

    \usepackage{lettrine}


    \usepackage[utf8]{inputenc} % Required for inputting international characters
    \usepackage[T1]{fontenc} % Output font encoding for international characters

    \usepackage{palatino} % Use the Palatino font by default

    \thesistitle{Thesis Title} % Your thesis title, this is used in the title and abstract, print it elsewhere with \ttitle

\degree{Doctor of Philosophy} % Your degree name, this is used in the title page and abstract, print it elsewhere with \degreename

\author{John \textsc{Smith}} % Your name, this is used in the title page and abstract, print it elsewhere with \authorname

\university{\href{http://www.university.com}{University Name}} % Your university's name and URL, this is used in the title page and abstract, print it elsewhere with \univname

\department{\href{http://department.university.com}{Department or School Name}} % Your department's name and URL, this is used in the title page and abstract, print it elsewhere with \deptname

\faculty{\href{http://faculty.university.com}{Faculty Name}} % Your faculty's name and URL, this is used in the title page and abstract, print it elsewhere with \facname

    \begin{document}

    \frontmatter % Use roman page numbering style (i, ii, iii, iv...) for the pre-content pages
    \pagenumbering{Roman}

    \pagestyle{plain} % Default to the plain heading style until the thesis style is called for the body content


    \addtocontents{ptc}{\protect\setcounter{tocdepth}{1}}


    \begin{abstract}
    %\addchaptertocentry{\abstractname} % Add the abstract to the table of 

    \end{abstract}



    \begin{acknowledgements}
    %\addchaptertocentry{\acknowledgementname} % Add the acknowledgements to the table of contents

    The acknowledgements and the people to thank go here, don't forget to include your project advisor\ldots

    \end{acknowledgements}



    \tableofcontents % Prints the main table of contents

    \listoffigures % Prints the list of figures

    \listoftables % Prints the list of tables



    \begin{abbreviations}{ll}

    \textbf{LAH} & \textbf{L}ist \textbf{A}bbreviations \textbf{H}ere\\
    \textbf{WSF} & \textbf{W}hat (it) \textbf{S}tands \textbf{F}or\\

    \end{abbreviations}


    \dedicatory{For/Dedicated to/To my\ldots} 



    \mainmatter % Begin numeric (1,2,3...) page numbering

    \pagestyle{thesis} % Return the page headers back to the "thesis" style



    \input{Chapters/Chapter1}

    \end{document}

使用上面的代码会出现这样的情况: 在此处输入图片描述

答案1

要仅显示部分,请添加\setcounter{tocdepth}{1}

\newcommand\DoPToC{%
\setcounter{tocdepth}{1}
\startcontents[chapters]
\printcontents[chapters]{}{1}{\noindent{\color{myblue}\rule{\textwidth}{1.5pt}}\par\medskip}%
}

代码根据 Gonzalo 的答案修改

\documentclass{book}
\usepackage[margin=1.5cm,a5paper]{geometry}
\usepackage[explicit]{titlesec}
\usepackage{titletoc}
\usepackage{tikz}
\usepackage{epigraph}
\usepackage{xpatch}
\usepackage{lmodern}
\usepackage{lipsum}


\newlength\ChapWd
\settowidth\ChapWd{\huge\chaptertitlename}

\definecolor{myblue}{RGB}{0,0,122}

\titleformat{\chapter}[display]
  {\normalfont\filcenter\sffamily}
  {\tikz[remember picture,overlay]
    {
    \node[fill=myblue,font=\fontsize{60}{72}\selectfont\color{white},anchor=north east,minimum size=\ChapWd]
      at ([xshift=-15pt,yshift=-15pt]current page.north east)
      (numb) {\thechapter};
    \node[rotate=90,anchor=south,inner sep=0pt,font=\huge] at (numb.west) {\chaptertitlename};
    }
  }{0pt}{\fontsize{33}{40}\selectfont\color{myblue}#1}[\vskip10pt\Large***]
\titlespacing*{\chapter}
  {0pt}{50pt}{10pt}


\makeatletter
\xpatchcmd{\ttl@printlist}{\endgroup}{{\noindent\color{myblue}\rule{\textwidth}{1.5pt}}\vskip30pt\endgroup}{}{}
\makeatother

\newcommand\DoPToC{%
\setcounter{tocdepth}{1}
\startcontents[chapters]
\printcontents[chapters]{}{1}{\noindent{\color{myblue}\rule{\textwidth}{1.5pt}}\par\medskip}%
}

\setlength\epigraphrule{0pt}
\renewcommand\textflush{flushright}
\renewcommand\epigraphsize{\normalsize\itshape}

\begin{document}

\chapter{Title of the first chapter}
\epigraph{A brainy quote -- Its Author}{}
\DoPToC
\lipsum[4]
\section{A test section}
\lipsum[4]
\subsection{A test subsection}
\lipsum[4]
\subsection{A test subsection}
\lipsum[4]
\section{Another test section}
\lipsum[4]
\section{Yet another test section}
\lipsum[4]
\subsection{A test subsection}
\lipsum[4]
\subsection{A test subsection}
\lipsum[4]

\chapter{Title of the second chapter}
\DoPToC
\lipsum[4]
\section{A test section}
\lipsum[4]
\subsection{A test subsection}
\lipsum[4]
\subsection{A test subsection}
\lipsum[4]
\subsection{A test subsection}
\lipsum[4]
\section{Another test section}
\lipsum[4]
\subsection{A test subsection}
\lipsum[4]
\subsection{A test subsection}
\lipsum[4]

\end{document}

在此处输入图片描述

相关内容