3

I am trying to add a TOC in the first page for each chapter, using the answer of this question: How to obtain this fancy chapter page with the book class

There are two problems: First why the word chapter.10 appears? and Second I want the TOC to display only sections without subsections.

Edit:

I am using the MastersDoctoralThesis class, which can be found in this link: http://www.latextemplates.com/templates/theses/1/thesis_1.zip

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

This appears using the above code: enter image description here

  • 1
    Please help us help you and add a minimal working example (MWE) that illustrates your problem. Reproducing the problem and finding out what the issue is will be much easier when we see compilable code, starting with \documentclass{...} and ending with \end{document}. – DG' Oct 28 '15 at 9:50
  • @ DG` Thank you for trying to help. I have edited the question with my MWE. – student Oct 28 '15 at 10:59
3

To display only the sections, add \setcounter{tocdepth}{1}

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

Code modified from Gonzalo's answer:

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

enter image description here

  • "why the word chapter.10 appears"? It doesn't for me. So you have to provide the code that brings chapter.10 in to picture. – user11232 Oct 28 '15 at 10:09
  • @ Harish Kumar. Thank you for your answer. I have used the code in another class and it works fine. But I do not know why when I use the same code in another class which I have added in my question, the words also will appear. – student Oct 28 '15 at 10:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.