章节标题上的部分目录

章节标题上的部分目录

我想在章节页面上创建类似的内容:

  _____________________________
  |                            |
  |         Section 1 .... 3   |
  |         Section 2 .... 5   |
  |                            |
  |                            |
  |   Chapter Title            |
  |                            |
  |____________________________|

答案1

以下是使用titletoc包来生成部分目录;\partialtoc提供了一个布尔开关来随意激活/停用部分目录(在下面的示例中,\partialtocfalse在附录之前使用它来防止部分目录):

\documentclass[openany]{book}
\usepackage{titletoc}
\usepackage{etoolbox}

\newif\ifpartialtoc
\partialtoctrue

\makeatletter
\patchcmd{\@makechapterhead}
  {\vspace*{50\p@}}
  {\ifpartialtoc
    \vspace*{0\p@}%
    \hfill\smash{\raisebox{\height}{%
      \begin{minipage}{.8\textwidth}
        \printcontents{}{1}{\section*{\contentsname}}
      \end{minipage}%
      }%
    }\vskip50pt\par
   \else
   \vspace*{50pt}%
   \fi%  
  }
  {}
  {}
\pretocmd{\chapter}{\startcontents}{}{}
\makeatother

\begin{document}

\chapter{Test chaper one}
\section{Test section one one}
\section{Test section one two}
\section{Test section one three}
\section{Test section one four}

\chapter{Test chaper one}
\section{Test section two one}
\section{Test section two two}
\section{Test section two three}

\appendix
\partialtocfalse
\chapter{Test Appendix}

\end{document}

输出:

在此处输入图片描述

第一章第一页的放大图:

在此处输入图片描述

更新:

在评论中,有人要求使用titlesec及其\titleformat命令来获得类似的结果;这是一种可能性:

\documentclass[openany]{book}
\usepackage{titlesec}
\usepackage{titletoc}

\newif\ifpartialtoc
\partialtoctrue

\titleformat{\chapter}[display]
  {\startcontents\normalfont\huge\bfseries}
  {\PartialToc\chaptertitlename\ \thechapter}
  {20pt}
  {\Huge}

\newcommand\PartialToc{%
\begingroup
\ifpartialtoc
  \normalsize\normalfont
  \vspace*{0pt}%
  \hfill\smash{\raisebox{\height}{%
  \begin{minipage}{.8\textwidth}
    \printcontents{}{1}{\textbf{\large\contentsname}\vskip10pt}
  \end{minipage}%
    }%
  }\vskip50pt\par
  \else
  \vspace*{50pt}%
  \fi%  
\endgroup
}

\begin{document}

\chapter{Test chapter one}
\section{Test section one one}
\section{Test section one two}
\section{Test section one three}
\section{Test section one four}

\chapter{Test chapter two}
\section{Test section two one}
\section{Test section two two}
\section{Test section two three}

\appendix
\partialtocfalse
\chapter{Test Appendix}

\end{document}

相关内容