2

I'm currently finishing my thesis and have an issue with my tocs: I need an overview toc first, which contains chapters (top level) only. Afterwards I need to have a full toc, which contains chapters, sections and subsections (numbered) plus subsubsections (w/o numbering).

To achieve that I used the shorttoc package. That works pretty well!

My problem is: The shorttoc lists itself, as well as the full toc, that lists itself, too. How do I prevent the shorttoc from appearing in itself and how do I prevent the toc from appearing in itself? I want shorttoc to list toc and toc to list shorttoc.

All I found was a thread about hiding other entries from shorttoc but not toc, that didn't work sufficiently for me.

Here is my (almost minimal) working example:

\documentclass[11pt, oneside]{Thesis} % The default font size and one-sided printing (no margin offsets)
\usepackage[ngerman]{babel}
\usepackage[T1]{fontenc}
\usepackage{microtype}
\usepackage{shorttoc} % Für Inhaltsübersicht

% TOC configuration[![enter image description here][1]][1]
% Chapter numbering only for level 1-3
\setcounter{secnumdepth}{2}
% Show 1-4 in TOC 
\setcounter{tocdepth}{3}

\begin{document}

%----------------------------------------------------------------------------------------
%   TOCs
%----------------------------------------------------------------------------------------
% Top Level TOC
\shorttoc{Inhaltsübersicht}{0}
\addcontentsline{toc}{chapter}{Inhaltsübersicht}
\clearpage

% Full TOC
\tableofcontents % Write out the Table of Contents

%----------------------------------------------------------------------------------------
%   Chapter
%----------------------------------------------------------------------------------------
\chapter{Chapter 1}
Lorem Ipsum...

\section{Section 1.1}
Lorem...

%----------------------------------------------------------------------------------------
%   Chapter
%----------------------------------------------------------------------------------------
\chapter{Chapter 2}
Lorem Ipsum...

\section{Section 2.1}
Lorem...

\section{Section 2.2}
Lorem...

%----------------------------------------------------------------------------------------
%   BIBLIOGRAPHY
%----------------------------------------------------------------------------------------
\label{Literaturverzeichnis}
\lhead{\emph{Literaturverzeichnis}} % Change the page header to say "Bibliography"
%\def\UrlBreaks{\do\/\do-}
\addtotoc{Literaturverzeichnis}
\bibliographystyle{apalike-german-PK} % Use the "unsrtnat" BibTeX style for formatting the Bibliography
\bibliography{Bibliography}
\clearpage

%----------------------------------------------------------------------------------------
%   VERZEICHNISSE
%----------------------------------------------------------------------------------------
\label{Abbildungsverzeichnis}
\lhead{\emph{Abbildungsverzeichnis}} % Set the left side page header to "List of Figures"
\listoffigures % Write out the List of Figures
\clearpage

\label{Tabellenverzeichnis}
\lhead{\emph{Tabellenverzeichnis}} % Set the left side page header to "List of Tables"
\listoftables % Write out the List of Tables
\clearpage

\end{document}

edit: I forgot to attach the class "thesis" I'm using. It's taken from latextemplates.com and I adopted the variables plus some namings to my needs. Here ist the Thesis.cls:

\NeedsTeXFormat{LaTeX2e}[1996/12/01]
\ProvidesClass{Thesis}
              [2007/22/02 v1.0
   LaTeX document class]
\def\baseclass{book}
\DeclareOption*{\PassOptionsToClass{\CurrentOption}{\baseclass}}
\def\@checkoptions#1#2{
  \edef\@curroptions{\@ptionlist{\@currname.\@currext}}
  \@tempswafalse
  \@tfor\@this:=#2\do{
    \@expandtwoargs\in@{,\@this,}{,\@curroptions,}
    \ifin@ \@tempswatrue \@break@tfor \fi}
  \let\@this\@empty
  \if@tempswa \else \PassOptionsToClass{#1}{\baseclass}\fi
}
\@checkoptions{11pt}{{10pt}{11pt}{12pt}}
\PassOptionsToClass{a4paper}{\baseclass}
\ProcessOptions\relax
\LoadClass{\baseclass}
\newcommand\bhrule{\typeout{------------------------------------------------------------------------------}}

\newcommand\Declaration[1]{
\btypeout{Eidesstattliche Versicherung}
\addtotoc{Eidesstattliche Versicherung}
\thispagestyle{plain}
\null\vfil
%\vskip 60\p@
\begin{center}{\huge\bf Eidesstattliche Versicherung\par}\end{center}
%\vskip 60\p@
{\normalsize #1}
\vfil\vfil\null
%\cleardoublepage
}

\newcommand\btypeout[1]{\bhrule\typeout{\space #1}\bhrule}
\def\today{\ifcase\month\or
  January\or February\or March\or April\or May\or June\or
  July\or August\or September\or October\or November\or December\fi
  \space \number\year}
\usepackage{setspace}
\onehalfspacing
\setlength{\parindent}{0pt}
\setlength{\parskip}{2.0ex plus0.5ex minus0.2ex}
\usepackage{vmargin}

\RequirePackage[utf8]{inputenc} % Allows the use of international characters (e.g. Umlauts)

%----------------------------------------------------------------------------------------
%   MARGINS
%----------------------------------------------------------------------------------------
\setmarginsrb  { 1.5in}  % left margin
                        { 0.6in}  % top margin
                        { 1.0in}  % right margin
                        { 0.8in}  % bottom margin
                        {  20pt}  % head height
                        {0.25in}  % head sep
                        {   9pt}  % foot height
                        { 0.3in}  % foot sep
%----------------------------------------------------------------------------------------
\raggedbottom
\setlength{\topskip}{1\topskip \@plus 5\p@}
\doublehyphendemerits=10000       % No consecutive line hyphens.
\brokenpenalty=10000              % No broken words across columns/pages.
\widowpenalty=9999                % Almost no widows at bottom of page.
\clubpenalty=9999                 % Almost no orphans at top of page.
\interfootnotelinepenalty=9999    % Almost never break footnotes.
\usepackage{fancyhdr}
\lhead[\rm\thepage]{\fancyplain{}{\sl{\rightmark}}}
\rhead[\fancyplain{}{\sl{\leftmark}}]{\rm\thepage}
\chead{}\lfoot{}\rfoot{}\cfoot{}
\pagestyle{fancy}
\renewcommand{\chaptermark}[1]{\btypeout{\thechapter\space #1}\markboth{\@chapapp\ \thechapter\ #1}{\@chapapp\ \thechapter\ #1}}
\renewcommand{\sectionmark}[1]{}
\renewcommand{\subsectionmark}[1]{}
\renewcommand{\contentsname}{Inhaltsverzeichnis}
\renewcommand{\listtablename}{Tabellenverzeichnis} 
\renewcommand{\listfigurename}{Abbildungsverzeichnis} 
\renewcommand{\chaptername}{Kapitel}

\renewcommand{\tablename}{Tabelle}
\renewcommand{\figurename}{Abbildung}

\renewcommand{\bibname}{Bibliographie}
\def\cleardoublepage{\clearpage\if@twoside \ifodd\c@page\else
\hbox{}
\thispagestyle{empty}
\newpage
\if@twocolumn\hbox{}\newpage\fi\fi\fi}
\usepackage{amsmath,amsfonts,amssymb,amscd,amsthm,xspace}
\theoremstyle{plain}
\newtheorem{example}{Example}[chapter]
\newtheorem{theorem}{Theorem}[chapter]
\newtheorem{corollary}[theorem]{Corollary}
\newtheorem{lemma}[theorem]{Lemma}
\newtheorem{proposition}[theorem]{Proposition}
\newtheorem{axiom}[theorem]{Axiom}
\theoremstyle{definition}
\newtheorem{definition}[theorem]{Definition}
\theoremstyle{remark}
\newtheorem{remark}[theorem]{Remark}
\usepackage[centerlast,small,sc]{caption}
\setlength{\captionmargin}{20pt}
\newcommand{\fref}[1]{Figure~\ref{#1}}
\newcommand{\tref}[1]{Table~\ref{#1}}
\newcommand{\eref}[1]{Equation~\ref{#1}}
\newcommand{\cref}[1]{Chapter~\ref{#1}}
\newcommand{\sref}[1]{Section~\ref{#1}}
\newcommand{\aref}[1]{Appendix~\ref{#1}}
\renewcommand{\topfraction}{0.85}
\renewcommand{\bottomfraction}{.85}
\renewcommand{\textfraction}{0.1}
\renewcommand{\dbltopfraction}{.85}
\renewcommand{\floatpagefraction}{0.75}
\renewcommand{\dblfloatpagefraction}{.75}
\setcounter{topnumber}{9}
\setcounter{bottomnumber}{9}
\setcounter{totalnumber}{20}
\setcounter{dbltopnumber}{9}
\usepackage{graphicx}
\usepackage{epstopdf}
\usepackage{booktabs}
\usepackage{rotating}
\usepackage{listings}
\usepackage{lstpatch}
\lstset{captionpos=b,
        frame=tb,
        basicstyle=\scriptsize\ttfamily,
        showstringspaces=false,
        keepspaces=true}
\lstdefinestyle{matlab} {
        language=Matlab,
        keywordstyle=\color{blue},
        commentstyle=\color[rgb]{0.13,0.55,0.13}\em,
        stringstyle=\color[rgb]{0.7,0,0} }
\usepackage[pdfpagemode={UseOutlines},bookmarks=true,bookmarksopen=true,
   bookmarksopenlevel=0,bookmarksnumbered=true,hypertexnames=false,
   colorlinks,linkcolor={black},citecolor={black},urlcolor={black},
   pdfstartview={FitV},unicode,breaklinks=true]{hyperref}
\pdfstringdefDisableCommands{
   \let\\\space
}
\newcommand*{\supervisor}[1]{\def\supname{#1}}
\newcommand*{\thesistitle}[1]{\def\ttitle{#1}}
\newcommand*{\examiner}[1]{\def\examname{#1}}
\newcommand*{\degree}[1]{\def\degreename{#1}}
\newcommand*{\authors}[1]{\def\authornames{#1}}
\newcommand*{\addresses}[1]{\def\addressnames{#1}}
\newcommand*{\university}[1]{\def\univname{#1}}
\newcommand*{\UNIVERSITY}[1]{\def\UNIVNAME{#1}}
\newcommand*{\department}[1]{\def\deptname{#1}}
\newcommand*{\DEPARTMENT}[1]{\def\DEPTNAME{#1}}
\newcommand*{\group}[1]{\def\groupname{#1}}
\newcommand*{\GROUP}[1]{\def\GROUPNAME{#1}}
\newcommand*{\faculty}[1]{\def\facname{#1}}
\newcommand*{\FACULTY}[1]{\def\FACNAME{#1}}
\newcommand*{\subject}[1]{\def\subjectname{#1}}
\newcommand*{\keywords}[1]{\def\keywordnames{#1}}

%----------------------------------------------------------------------------------------
%   DOCUMENT VARIABLES
%   Fill in the lines below to update the thesis template
%   If you wish to cite each of the variables defined below, look at the
%   section above for the citation command e.g. \examiner{} below is
%   defined as \examname above so you cite it as \examname
%----------------------------------------------------------------------------------------

\thesistitle{How to define TOCs} % Your thesis title - this is used in the title and abstract
%-------------------------------------------------  
\supervisor{Prof. Dr. \textsc{xxx} \\ Universität xxx} % You supervisor's name - this is used in the title page
%-------------------------------------------------   
\examiner{Prof. Dr. \textsc{xxx} \\ Hochschule xxx} % Your examiner's name - this is not currently used anywhere in the template, cite it with \examname if you want it
%-------------------------------------------------   
\degree{xxx (M.Sc.)} % Your degree name - this is currently used in the title page and abstract
%-------------------------------------------------   
\authors{\textsc{xxx}} % Your name - this is used in the title page and abstract
%-------------------------------------------------   
\addresses{} % Your address - this is not currently used anywhere in the template, cite it with \addressnames if you want it
%-------------------------------------------------   
\subject{} % Your subject area - this is not currently used anywhere in the template, cite it with \subjectname if you want it
%-------------------------------------------------   
\keywords{} % Keywords for your thesis - this is not currently used anywhere in the template, cite it with \keywordnames if you want it
%-------------------------------------------------   
\university{\texorpdfstring{% Your university's URL
                {Universität xxx \\ Hochschule xxx}} % Your university's name - this is currently used in the title page
                {Universität xxx \\ Hochschule xxx}}
%-------------------------------------------------   
\UNIVERSITY{\texorpdfstring{ % Your university's URL
                {UNIVERSITÄT xxx \\ HOCHSCHULE xxx}} % Your university's name in capitals - this is currently used in the abstract page
                {UNIVERSITÄT xxx \\ HOCHSCHULE xxx}}
%-------------------------------------------------                
\department{\texorpdfstring{ % Your department's URL
                {Institut xxx}} % Your department's name - used in the title page and abstract
                {Institut xxx}}
%-------------------------------------------------                
\DEPARTMENT{\texorpdfstring{% Your department's URL
                {DEPARTMENT OR SCHOOL NAME (IN BLOCK CAPITALS)}} % Your department's name in capitals - this is not currently used anywhere in the template, cite it with \DEPTNAME if you want it
                {DEPARTMENT OR SCHOOL NAME (IN BLOCK CAPITALS)}}
%-------------------------------------------------                
\group{\texorpdfstring{% Your research group's URL
                {xxx}} % Your research group's name - this is currently used in the title page 
                {xxx}}
%-------------------------------------------------                
\GROUP{\texorpdfstring{ % Your research group's URL
                {RESEARCH GROUP NAME (IN BLOCK CAPITALS)}} % Your research group's name in capitals - this is not currently used anywhere in the template, cite it with \GROUPNAME if you want it
                {RESEARCH GROUP NAME (IN BLOCK CAPITALS)}}
%-------------------------------------------------                
\faculty{\texorpdfstring{% Your faculty's URL
                {xxx (M.Sc.)}} % Your faculty's name - this is currently used in the abstract page
                {xxx (M.Sc.)}}
%-------------------------------------------------                
\FACULTY{\texorpdfstring{ % Your faculty's URL
                {FACULTY NAME (IN BLOCK CAPITALS)}} % Your faculty's name in capitals - this is not currently used anywhere in the template, cite it with \FACNAME if you want it
                {FACULTY NAME (IN BLOCK CAPITALS)}}
%----------------------------------------------------------------------------------------    

% The default title page, this is not used in this www.latextemplates.com version            
\renewcommand\maketitle{
  \btypeout{Title Page}
  \hypersetup{pdftitle={\@title}}
  \hypersetup{pdfsubject=\subjectname}
  \hypersetup{pdfauthor=\authornames}
  \hypersetup{pdfkeywords=\keywordnames}
  \thispagestyle{empty}
  \begin{titlepage}
    \let\footnotesize\small
    \let\footnoterule\relax
    \let \footnote \thanks
    \setcounter{footnote}{0}
    \null\vfil
    \vskip 60\p@
    \begin{center}
      \setlength{\parskip}{0pt}
      {\large\textbf{\UNIVNAME}\par}
      \vfill
      {\huge \bf \@title \par}
      \vfill
      {\LARGE by \par}
      \smallskip
      {\LARGE \authornames \par}
      \vfill
      {\large A thesis submitted in partial fulfillment for the \par}
      {\large degree of \degreename \par}
      \bigskip
      \bigskip
      {\large in the \par}
      {\large \facname \par}
      {\large \deptname \par} 
      \bigskip
      \bigskip
      \bigskip
      {\Large \@date \par}
      \bigskip
    \end{center}
    \par
    \@thanks
    \vfil\null
  \end{titlepage}
  \setcounter{footnote}{0}%
  \global\let\thanks\relax
  \global\let\maketitle\relax
  \global\let\@thanks\@empty
  \global\let\@author\@empty
  \global\let\@date\@empty
  \global\let\@title\@empty
  \global\let\title\relax
  \global\let\author\relax
  \global\let\date\relax
  \global\let\and\relax
  \cleardoublepage
}
%----------------------------------------------------------------------------------------
%   ABSTRACT PAGE DESIGN
%----------------------------------------------------------------------------------------
\newenvironment{abstract}
{
  \btypeout{Zusammenfassung}
  \thispagestyle{empty}
  %\null\vfil
  \begin{center}
    \setlength{\parskip}{0pt}
    {\normalsize \UNIVNAME \par} % University name in capitals
    \medskip
    {\normalsize \degreename \par} % Faculty name
    \medskip
    {\huge{\textit{Zusammenfassung}} \par}
    %{\normalsize \deptname \par} % Department name
    %{\normalsize \groupname\par} % Degree name
    \bigskip
    {\normalsize\bf \@title \par} % Thesis title
    \bigskip
    {\normalsize von \authornames \par} % Author name
    \medskip
  \end{center}
}
%----------------------------------------------------------------------------------------
{
  \vfil\vfil\vfil\null
  \cleardoublepage
}
\addtocounter{secnumdepth}{1}
\setcounter{tocdepth}{6}
\newcounter{dummy}
\newcommand\addtotoc[1]{
\refstepcounter{dummy}
\addcontentsline{toc}{chapter}{#1}}
\renewcommand\tableofcontents{
\btypeout{Inhaltsverzeichnis}
\addtotoc{Inhaltsverzeichnis}
\begin{spacing}{1}{
    \setlength{\parskip}{1pt}
    \if@twocolumn
      \@restonecoltrue\onecolumn
    \else
      \@restonecolfalse
    \fi
    \chapter*{\contentsname
        \@mkboth{
           \MakeUppercase\contentsname}{\MakeUppercase\contentsname}}
    \@starttoc{toc}
    \if@restonecol\twocolumn\fi
   \cleardoublepage
}\end{spacing}
}
\renewcommand\listoffigures{
\btypeout{List of Figures}
\addtotoc{Abbildungsverzeichnis}
\begin{spacing}{1}{
    \setlength{\parskip}{1pt}
    \if@twocolumn
      \@restonecoltrue\onecolumn
    \else
      \@restonecolfalse
    \fi
    \chapter*{\listfigurename
      \@mkboth{\MakeUppercase\listfigurename}
              {\MakeUppercase\listfigurename}}
    \@starttoc{lof}
    \if@restonecol\twocolumn\fi
    \cleardoublepage
}\end{spacing}
}
\renewcommand\listoftables{
\btypeout{List of Tables}
\addtotoc{Tabellenverzeichnis}
\begin{spacing}{1}{
    \setlength{\parskip}{1pt}
    \if@twocolumn
      \@restonecoltrue\onecolumn
    \else
      \@restonecolfalse
    \fi
    \chapter*{\listtablename
      \@mkboth{
          \MakeUppercase\listtablename}{\MakeUppercase\listtablename}}
    \@starttoc{lot}
    \if@restonecol\twocolumn\fi
    \cleardoublepage
}\end{spacing}
}
\newcommand\listsymbolname{Abbreviations}
\usepackage{longtable}
\newcommand\listofsymbols[2]{
\btypeout{\listsymbolname}
\addtotoc{\listsymbolname}
    \chapter*{\listsymbolname
      \@mkboth{
          \MakeUppercase\listsymbolname}{\MakeUppercase\listsymbolname}}
\begin{longtable}[c]{#1}#2\end{longtable}\par
    \cleardoublepage
}
\newcommand\listconstants{Physical Constants}
\usepackage{longtable}
\newcommand\listofconstants[2]{
\btypeout{\listconstants}
\addtotoc{\listconstants}
    \chapter*{\listconstants
      \@mkboth{
          \MakeUppercase\listconstants}{\MakeUppercase\listconstants}}
\begin{longtable}[c]{#1}#2\end{longtable}\par
    \cleardoublepage
}
\newcommand\listnomenclature{Symbols}
\usepackage{longtable}
\newcommand\listofnomenclature[2]{
\btypeout{\listnomenclature}
\addtotoc{\listnomenclature}
    \chapter*{\listnomenclature
      \@mkboth{
          \MakeUppercase\listnomenclature}{\MakeUppercase\listnomenclature}}
\begin{longtable}[c]{#1}#2\end{longtable}\par
    \cleardoublepage
}
\newcommand\acknowledgements[1]{
\btypeout{Acknowledgements}
\addtotoc{Acknowledgements}
\thispagestyle{plain}
\begin{center}{\huge{\textit{Acknowledgements}} \par}\end{center}
{\normalsize #1}
\vfil\vfil\null

}
\newcommand\dedicatory[1]{
\btypeout{Dedicatory}
\thispagestyle{plain}
\null\vfil
\vskip 60\p@
\begin{center}{\Large \sl #1}\end{center}
\vfil\null
\cleardoublepage
}
\renewcommand\backmatter{
  \if@openright
    \cleardoublepage
  \else
    \clearpage
  \fi
  \addtotoc{\bibname}
  \btypeout{\bibname}
  \@mainmatterfalse}
\endinput

\usepackage{listings}

edit 2: esdd suggested to remove \addcontentsline{toc}{chapter}{Inhaltsübersicht}, but this removes the overview toc from the full toc also. Just to make really clear what I need, I attached two pictures of the tocs and how I would like to edit them: Overview TOC Full TOC

Thanks in advance for any help!

  • 2
    As we don't have your class we can't test the issue. Try to reproduce it with e.g. book.cls. – Ulrike Fischer Aug 16 '18 at 15:15
  • Remove \addcontentsline{toc}{chapter}{Inhaltsübersicht} from your code. This should remove the entries for the shorttoc. – esdd Aug 16 '18 at 20:20
  • @UlrikeFischer : Sorry, I forgot to attach the class. I hope it's okay to provide the class instead of reproducing the issue with a built-in class? – Nils Aug 17 '18 at 7:08
  • @esdd : Thanks for your advice, unfortunately it removes the "Inhaltsübersicht" (overview toc) from both of the tocs. I provided two pictures, which should clarify my needs. – Nils Aug 17 '18 at 7:09
  • Your class redefines \tableofcontents and adds there \addtotoc{Inhaltsverzeichnis}. – Ulrike Fischer Aug 17 '18 at 7:12
0

I'd simply remove all references to table of contents (short and long) in both lists.

If you want to keep them, change, in Thesis.cls,

\btypeout{Inhaltsverzeichnis}
\addtotoc{Inhaltsverzeichnis}

into

\btypeout{Inhaltsverzeichnis}
\addtocontents{toc}{\string\ifdefined\string\weareinshorttoc}
\addtotoc{Inhaltsverzeichnis}
\addtocontents{toc}{\string\fi}

and in your document change

% Top Level TOC
\shorttoc{Inhaltsübersicht}{0}
\addcontentsline{toc}{chapter}{Inhaltsübersicht}
\clearpage

into

% Top Level TOC
\begingroup\def\weareinshorttoc{}
\shorttoc{Inhaltsübersicht}{0}
\addtocontents{toc}{\string\ifdefined\string\weareinshorttoc\string\else}
\addcontentsline{toc}{chapter}{Inhaltsübersicht}
\addtocontents{toc}{\string\fi}
\endgroup
\clearpage
  • Thanks a lot! That did exactly what I wanted. Now I need to do some research on the if-syntax in LaTeX, in order to understand your suggestions ;-) – Nils Aug 21 '18 at 19:49

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.