2

Update: a previous version of this question wrongly attributed the problem to use of minitoc to get section-level tables of contents (\secttoc).

I've got a complicated document with a tables of content, and which switches between one and two-column mode.

I'd like to remove the subsection headings themselves from the text, but leave them in the TOCs.

I tried the recipe from this answer:

\newcommand{\nosubsection}[1]{%
  \refstepcounter{subsection}%
  \addcontentsline{toc}{subsection}{\protect\numberline{\thesubsection}#1}%
  \markright{#1}}

This almost works, but the TOCs comes out wrong. I.E.,

1 first section
   1.1 first sub
     1.1.1 first subsub
     1.1.2 second subsub
     1.2.1 first subsub    % <--- WRONG
   1.2 second sub

but should really be

1 first section
   1.1 first sub
     1.1.1 first subsub
     1.1.2 second subsub
   1.2 second sub
     1.2.1 first subsub

I think this is due to a strange interaction with the switching between one- and two-column mode: the first subsubsection in each subsection are put in the subsection above where they belong. This happens even when I just to include the supposedly do-nothing \onecolumn\twocolumn.

Here's an MWE (or actually, a minimal failing example):

\documentclass[11pt]{article}
\newcommand{\nosubsection}[1]{%
  \refstepcounter{subsection}%
  \addcontentsline{toc}{subsection}{\protect\numberline{\thesubsection}#1}%
  \markright{#1}}

\begin{document}
\tableofcontents

\section{first section---show all subs 1---works}
\subsection{first sub 1.1}
\twocolumn[{\subsubsection{first subsub 1.1.1}}]
\twocolumn[{\subsubsection{second subsub 1.1.2}}]
\subsection{second sub 1.2}
\twocolumn[{\subsubsection{first subsub 1.2.1}}]

\section{second section--don't show subs 2 --- fails}
\nosubsection{first sub 2.1} %\label{sub:2.1}
\twocolumn[{\subsubsection{first subsub 2.1.1}}]
\twocolumn[{\subsubsection{second subsub 2.1.2}}]
\onecolumn  %%%% these casuse the problem, I think
\twocolumn
\nosubsection{second sub 2.2}
\twocolumn[{\subsubsection{first subsub 2.2.1 \textbf{WRONG}}}]

\end{document}

(Note that you need both nosubsection and column-switching to get the failure.)

I have also tried using the multicol package, and I get the same problem.

Any ideas?

closed as unclear what you're asking by user31729, Mensch, Mike Renfro, Svend Tveskæg, Martin Schröder Sep 27 '15 at 19:11

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • Welcome to TeX.SX! Please add a minimal working example (MWE) starting with \documentclass{...} and ending with \end{document} to help us reproduce your problem. – Pier Paolo Feb 9 '15 at 16:12
  • @PierPaolo, yes, thanks for the admonition. The very fact that I can't do that easily implies that the problem is some ugly interaction between the macros in my document (I suspect includeonly and import, but I can't trace it very far. Aaargh! – Andrew Jaffe Feb 9 '15 at 17:55
  • 1
    @PierPaolo: much changed now (just adding comment so that you notice it -- sorry!) – Andrew Jaffe Feb 10 '15 at 13:42
  • Please, make a sensible example: \onecolumn immediately followed by \twocolumn means nothing. – egreg Feb 10 '15 at 14:20
  • @egreg: this is the minimal working example. Feel free to insert any text between those; it will still fail! – Andrew Jaffe Feb 10 '15 at 14:22
2

The relevant part of the \subsection heading is (see macro \@sect in latex.ltx for example)

\begingroup 
  #6{%
    \@hangfrom{\hskip #3\relax\@svsec}%
    \interlinepenalty \@M #8\@@par}%
\endgroup

If this should not appear when the section level is subsection, it could be patched to use a \ifstrequal for testing if #1 is equal to subsection.

I added the \begin{multicols}{2}...\end{multicols} wrappers as well.

\documentclass[11pt]{article}
\usepackage{multicol}
\usepackage{blindtext}
\usepackage{xpatch}

\makeatletter
\xpatchcmd{\@sect}{%
  \begingroup 
  #6{%
    \@hangfrom{\hskip #3\relax\@svsec}%
    \interlinepenalty \@M #8\@@par}%
  \endgroup
}{%
  \ifstrequal{#1}{subsection}{%
    % Do nothing here!
  }{%
    \begingroup
    #6{%
      \@hangfrom{\hskip #3\relax\@svsec}%
      \interlinepenalty \@M #8\@@par}%
    \endgroup
  }%
}{\typeout{successful patching}}{\typeout{Nope}}
\makeatother

\begin{document}
\tableofcontents

\section{first section---show all subs 1---works}
\subsection{first sub 1.1}
\begin{multicols}{2}
\subsubsection{first subsub 1.1.1}
\blindtext[2]
\subsubsection{second subsub 1.1.2}
\blindtext[2]

\end{multicols}
\subsection{second sub 1.2}
\begin{multicols}{2}
  \subsubsection{first subsub 1.2.1}
\blindtext[5]

\end{multicols}

\section{second section--don't show subs 2 --- works now}
\subsection{first sub 2.1} %\label{sub:2.1}
\begin{multicols}{2}
\subsubsection{first subsub 2.1.1}
\blindtext[10]

\subsubsection{second subsub 2.1.2}
\blindtext[5]

\end{multicols}
\subsection{second sub 2.2}

\begin{multicols}{2}
\subsubsection{first subsub 2.2.1 \textbf{CORRECT}}
\blindtext[5]

\end{multicols}

\end{document}

enter image description here

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