2

Here is a screenshot of my table of content (amsart documentclass) : TOC

I do not want these Section *.2, Section *.3, Section *.4 in between the actual lines. How do I get rid of these inexplicable phrases? Thank you.


Apparently the problem is occurring due to the use of my self-defined command \addsubsection* instead of \subsection* (because I do not want the subsections to be shown in the table of contents).


A minimal code:

 \pdfoutput=1
 \documentclass[11pt,a4paper,reqno]{amsart}
 \usepackage{amssymb}

 \usepackage{bm}
 \numberwithin{equation}{section}

 \usepackage{mathabx}
 \usepackage{mathrsfs}
 \usepackage{mathtools}
 \usepackage{color}



 \theoremstyle{plain}

 \newtheorem{theorem}{Theorem}[section]
 \newtheorem{proposition}[theorem]{Proposition}
 \newtheorem{lemma}[theorem]{Lemma}
 \newtheorem{corollary}[theorem]{Corollary}
 \newtheorem{conjecture}[theorem]{Conjecture}
 \newtheorem{principle}[theorem]{Principle}
 \newtheorem{claim}[theorem]{Claim}

 \theoremstyle{definition}

 \newtheorem{definition}[theorem]{Definition}
 \newtheorem{remark}[theorem]{Remark}
 \newtheorem{remarks}[theorem]{Remarks}
 \newtheorem{example}[theorem]{Example}
 \newtheorem{examples}[theorem]{Examples}

 \newcommand\R{\mathbb{R}}
 \newcommand\Z{\mathbb{Z}}
 \newcommand\N{\mathbb{N}}
 \newcommand\Q{\mathbb{Q}}
 \newcommand\eps{\varepsilon}
 \newcommand\normsymb{\ell}  % was \|\,\|
 \newcommand\norm[1]{\ell({#1})}   % was \|{#1}\|
 \newcommand\normn[1]{\ell_n({#1})}   % was \|{#1}\|
 \newcommand\free[1]{\mathbf{F}_{#1}}

 %\vast \Vast - Bigger than \Bigg
 \makeatletter
 \newcommand{\vast}{\bBigg@{4}}
 \newcommand{\Vast}{\bBigg@{5}}
 \makeatother

 %\addsubsection - not shown in toc
 \makeatletter
 \ifcsname phantomsection\endcsname
  \newcommand*{\qrr@gobblenexttocentry}[5]{}
 \else
  \newcommand*{\qrr@gobblenexttocentry}[4]{}
 \fi
 \newcommand*{\addsubsection}{%
  \addtocontents{toc}{\protect\qrr@gobblenexttocentry}%
  \subsection}
 \makeatother

 \usepackage[breaklinks=true,hidelinks]{hyperref}


 \begin{document}

 \title{TITLE}

 \maketitle
 %\today

 \tableofcontents %\need to fix it

 \section{Introduction}
 \label{section-introduction}

 bla bla bla...

 \vspace{0.2cm}
 \addsubsection*{blablabla}
 We consider this and that, that and that..

 \vspace{0.2cm}
 \section{New section}

 \vspace{0.2cm}
 \addsubsection*{here we are}

 \addsubsection*{also here}

 \vspace{0.2cm}
 \section{The main theorem}

 \end{document}
4

Your current definition of \addsubsection inserts \qrr@gobblenexttocentry into the ToC in an attempt to gobble a subsequent entry of \contentsline. This may seem appropriate, but two \addsubsections immediately following one another causes a problem, since the gobbling becomes out-of-sync. Moreover, if you wish to define \qrr@gobblenexttocentry to be conditional on the existence of \phantomsection (when hyperref is loaded), it's obvious that which branch will be chosen since you're loading hyperref after this.

There's a far better way of doing what you're after: Use \subsection (starred or not) as-is and add to your preamble

\setcounter{tocdepth}{1}

The above will only print ToC entries up to \section.

enter image description here

\documentclass{amsart}

\usepackage{hyperref}

\let\addsubsection\subsection
\setcounter{tocdepth}{1}

\begin{document}

\tableofcontents %\need to fix it

\section{Introduction}

\addsubsection*{blablabla}

\section{New section}

\addsubsection*{here we are}

\addsubsection*{also here}

\section{The main theorem}

\end{document}

Technically this allows you to get rid of \addsubsection altogether. I've left it in the above code, making it similar to \subsection.

  • Excellent. That's what I wanted. Thank you sir. – firestorm Jan 13 '18 at 5:26
  • And thanks for the detailed clarification for why the previous definition did not work. I really appreciate it. – firestorm Jan 13 '18 at 5:27
0

Okay so I found a solution. It's a bit of cheating really but produces the same result.

I replaced

\addsubsection*{subsection-name}

with

\noindent\textbf{subsection-name.}

I guess it's a situation when we were looking for an flamethrower where a simple lighter would have worked. However, it is still an interesting problem to find code for self-defined subsection that does not show up in the toc.

  • why not simple \subsection*{subsection title}? read @Werner answer carefully again. – Zarko Jan 13 '18 at 5:36
  • @Zarko the name of the subsection along with the page number still shows in the table of contents (just without the subsection number). – firestorm Jan 13 '18 at 5:38
  • 1
    apparently you not understand @Werner. with\setcounter{tocdepth}{1} in toc will appear only sections. remove your \addsubsection definition. it is superfluous. – Zarko Jan 13 '18 at 5:40
  • You're right! So all I needed is \setcounter{tocdepth}{1} Thank you so much! – firestorm Jan 13 '18 at 5:45
  • 2
    and use standard subsection{...} (if you like to be numbered) or \subsection*{...} (for unnumbered) :-) – Zarko Jan 13 '18 at 5:48

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.