How to get the table of contents chapter wise (beginning of each chapter with sections and subsections with page numbers) and the main table of contents containing only chapter title with page range not sections and subsections tiles.

• minitoc package – David Carlisle Jul 4 '14 at 15:27
• titletoc package. – Alan Munn Jul 4 '14 at 15:58
• @Pouya No; it's not an exact duplicate; the other question/answer doesn't solve the page-range problem. – Gonzalo Medina Jul 4 '14 at 15:59
• @GonzaloMedina, indeed you are right. I take back my flag. – Pouya Jul 4 '14 at 16:51

Here's one possible solution using the titletoc package for the partial ToCs and a variation of this answer to Chapterwise page range in the TOC to generate the page ranges in the main ToC.

Use the \MiniToC after the \chapter command for chapters in which you want to typeset a partial ToC.

The code has to be compiled three times to get the right numbers for the page ranges in the main ToC.

\documentclass{report}
\usepackage{titletoc}
\usepackage{letltxmacro}
\usepackage{etoolbox}
\usepackage{lipsum}

\newcommand\MiniToC{%
\setcounter{tocdepth}{2}
\startcontents
\printcontents{}{1}{\section*{\contentsname}\vskip-3.5ex\hrulefill\vskip1ex}
\vskip-0.5ex\noindent\hrulefill
\setcounter{tocdepth}{0}
}
\setcounter{tocdepth}{0}

\makeatletter
\newif\if@chap@enddc
\@chap@enddctrue
\LetLtxMacro\ltx@@chapter\@chapter
\renewcommand\@chapter[2][]{%
\ltx@@chapter[#1]{#2}
\expandafter\label{chap:\thechapter}
}

\let\ltx@toc\tableofcontents
\renewcommand\tableofcontents{%
\ltx@toc
\let\ltx@chapter\chapter
\renewcommand\chapter{%
\expandafter\label{prenextchap:\thechapter}
\ltx@chapter
}%
}
\let\ltx@enddocument\enddocument
\renewcommand\enddocument{%
\if@chap@enddc\expandafter\label{prenextchap:\thechapter}\fi
\ltx@enddocument
}
\def\chaprange{%
\expandafter\pageref{chap:\thechapter}--\expandafter\pageref{prenextchap:\thechapter}}

}

\def\BreakChaprange{%
\expandafter\label{prenextchap:\thechapter}
\@chap@enddcfalse
}
\makeatother

\pretocmd{\section}{\BypassChaprange}{}{}
\pretocmd{\chapter}{\ToggleChaprange}{}{}

\begin{document}

\tableofcontents

\chapter{Test chapter one}
\MiniToC
\section{A test section}
\subsection{A test subsection}
\subsubsection{A test subsubsection}
\lipsum[1-30]

\chapter{Test chapter two}
\MiniToC

\section{A test section}
\subsection{A test subsection}
\subsubsection{A test subsubsection}
\lipsum[1-20]

\chapter{Test chapter three}
\MiniToC

\section{A test section}
\subsection{A test subsection}
\subsubsection{A test subsubsection}
\lipsum[1-10]

\end{document}


An image of the main ToC:

An image of the partial ToC for the first chapter:

• I was studying your answer and tried to add \parts to the report. It adds all the parts to the toc properly, except for the first one. Here is a screen-shot. – Pouya Jul 4 '14 at 16:58
• @Pouya The answer doesn't take into account \parts; this was not required in the question. My code could be modified to take parts into account if required. – Gonzalo Medina Jul 4 '14 at 17:01