5

I want to create an automatic Table of Content (ToC) at the beginning of very chapter. To do so, I use the combination of packages titlesec and titletoc. I use \titleformat to include the command to print the ToC after the title of the chapter. But to have a better looking I also want the ToC at very chapter to look like the main one at the beginning of the document and specially the indents for sections and subs... Therefore, I saw that I need to use \titlecontents.

Here comes my problem, this combination gives me the error ! LaTeX Error: Something's wrong--perhaps a missing \item.. I don't understand what is happening.

Here is an example:

\documentclass[onecolumn,twoside,openright,a4paper,11pt]{book}

\usepackage[utf8]{inputenc}     
\usepackage[T1]{fontenc}        

\usepackage{titletoc}
\setcounter{secnumdepth}{3}

\AtBeginDocument{
    \titlecontents{psection}[2.3em] {} {\contentslabel{2.3em}} {} {\titlerule*[1pc]{.}\contentspage}
    \titlecontents{psubsection}[5.5em] {} {\contentslabel{3.2em}} {} {\titlerule*[1pc]{.}\contentspage}
    \titlecontents{psubsubsection}[9.6em] {} {\contentslabel{4.1em}} {} {\titlerule*[1pc]{.}\contentspage}
}

\usepackage{titlesec}

\titleformat{\chapter}[hang]{\filright}{}{0pt}{ \Huge \bfseries\raggedleft}
[\vspace*{4pc}%
\startcontents
{\raggedleft\bfseries \large minitoc}\newline\llap
\noindent\hrulefill
\printcontents{p}{1}{\setcounter{tocdepth}{3}}
\noindent\hrulefill]


\begin{document}

    \tableofcontents

    \chapter{chapter}
    \section{title section}
    \subsection{subsection}
    \subsubsection{subsubsection}
    \subsubsection{subsubsection}
    \subsubsection{ssubsubection}

    \chapter{chapter}
    \section{section}
    \subsection{subsection}
    \subsubsection{subsubsection}
    \subsubsection{ssubsubection}
    \section{section}
    \subsection{subsection}
\end{document}

1 Answer 1

3

Here is a solution.

\documentclass[a4paper,11pt]{book}

\usepackage[T1]{fontenc}        

\usepackage{titletoc}
\setcounter{secnumdepth}{3}

\AtBeginDocument{
    \titlecontents{psection}[2.3em] {} {\contentslabel{2.3em}} {} {\titlerule*[1pc]{.}\contentspage}
    \titlecontents{psubsection}[5.5em] {} {\contentslabel{3.2em}} {} {\titlerule*[1pc]{.}\contentspage}
    \titlecontents{psubsubsection}[9.6em] {} {\contentslabel{4.1em}} {} {\titlerule*[1pc]{.}\contentspage}
}

\usepackage{titlesec}

\titleformat{\chapter}[hang]{\filright}{}{0pt}{ \Huge \bfseries\raggedleft}
[\vspace*{4pc}%
\startcontents
{\raggedleft\bfseries \large minitoc\endgraf}
\titlerule
\vspace{6pt}
\printcontents{p}{1}{\setcounter{tocdepth}{3}}
\vspace{6pt}
\titlerule]


\begin{document}

    \tableofcontents

    \chapter{chapter}
    \section{title section}
    \subsection{subsection}
    \subsubsection{subsubsection}
    \subsubsection{subsubsection}
    \subsubsection{ssubsubection}

    \chapter{chapter}
    \section{section}
    \subsection{subsection}
    \subsubsection{subsubsection}
    \subsubsection{ssubsubection}
    \section{section}
    \subsection{subsection}
\end{document}

Note you need to define a new format for starred chapters, see page 9 of titlesec's documentation.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .