I need to mark some section titles with asterisks to represent special sections. I adopted the method provided by titlesec document (sec. 6.7). Also, I found this topic had been discussed here. Everything is ok except that the vertical space between a theorem environment (for me, it's always proof environment) and the asterisked section title is a bit larger than the space between two normal sections.
Here is MWE:
\documentclass[a4paper,12pt]{article}
\usepackage[margin=1in]{geometry}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage[amsmath,thmmarks]{ntheorem}
{
\theoremstyle{nonumberplain}
\theoremindent0em
\theoremrightindent0em
\theoremheaderfont{\bfseries}
\theorembodyfont{\normalfont}
\theoremsymbol{\ensuremath{\Box}}
\newtheorem{proof}{Proof.}
}
% \usepackage{amsthm}
% \renewcommand\qedsymbol{\ensuremath{\Box}}
\usepackage{titlesec}
\usepackage{titletoc}
\renewcommand{\thesubsection}{\arabic{subsection}}
\newcommand{\secmark}{}
\newcommand{\marktotoc}[1]{\renewcommand{\secmark}{#1}}
\newenvironment{advanced}{
\renewcommand{\secmark}{*}
\addtocontents{toc}{\protect\marktotoc{*}}
}{
\addtocontents{toc}{\protect\marktotoc{}}
}
\titleformat{\subsection}
{\bfseries\large}
{\llap{\secmark}\thesubsection}
{1em}
{}
\newcommand{\starsec}[1]{\begin{advanced}\subsection{#1}\end{advanced}}
\titlecontents{section}[6em]
{\bfseries\addvspace{1pc}}
{\contentslabel[Chapter \thecontentslabel]{6em}}
{Chapter }
{\titlerule*{}\bfseries\contentspage}
\titlecontents{subsection}[3.7em]
{}
{\contentslabel[\llap{\secmark}\thecontentslabel]{2.3em}}
{\hspace*{-2.3em}}
{\titlerule*[10pt]{.}\contentspage}
\begin{document}
\tableofcontents
\section{The first section}
\subsection{The first subsection}
This is the first subsection.
\begin{proof}
Let's skip the proof.
\end{proof}
\begin{advanced}
\subsection{The first asterisked subsection}
This is the first asterisked subsection.
\subsection{The second asterisked subsection}
This is the second asterisked subsection.
\end{advanced}
\subsection{Another subsection}
This is another subsection.
\subsection{Normal subsection}
This is normal.
\end{document}
The problem still exists if I use the proof environment provided by amsthm package. But when I remove \addtocontents{toc}{...} from the definition of advanced environment, the extra space disappears. So the problem must be concerned with \addtocontents. It seems that \addtocontents is a horizontal command? When a theorem encounters it, an extra space will be placed. The extra space is \topsep because \theorempostskip{\topsep} is default setting in ntheorem.
For me, \addtocontents is needed because I want table of contents to demonstrate whether a section is asterisked. Does anyone know how to eliminate the extra space and meanwhile have table of contents printed correctly?


\addtocontentsis exactly the problem: the\addvspacecommand issued by\subsectioncannot see the trailing\addvspaceafterproofas “immediately preceding”. – egreg Sep 04 '19 at 09:44advancedhas some extra spaces produced by "unprotected" line endings. Adding%at those places would be a good idea. – barbara beeton Sep 04 '19 at 17:14