[Tex/LaTex] Partial ToC over the chapter title

chapterstable of contents

I want to create something similar to that on a chapter page:

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

Best Answer

Here's one possibility using the titletoc package to generate the partial ToCs; a boolean switch \partialtoc is provided to activate/deactivate the partial ToCs at will (in the example below \partialtocfalse was used just before the appendix to prevent the partial ToC):

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

The output:

enter image description here

A zoomed-in image for the first page of chapter one:

enter image description here

Update:

In a comment, it has been requested to get a similar result using titlesec and its \titleformat command; here's one possibility:

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