15

Consider following structure:

.
|_s
|_s
 |_ss
 |_ss+
  |_sss
 |_ss
|_s
|_s

How can I demote a subsection to subsubsection without changing markups ?

.
|_s
|_s
 |_ss
  |_sss+
   |_p
 |_ss
|_s
|_s

How can I promote a subsection to section without changing markups ?

.
|_s
|_s
 |_ss
|_s+
 |_ss
 |_ss
|_s
|_s

A wrapper command would be excellent

\begin[+1]{level}
\section{}
\end{level}
Real Dreams
  • 8,298
  • 12
  • 56
  • 78

1 Answers1

23

An easy way to promote/demote sectional commands would be to use a levelup/leveldown environment:

\newenvironment{leveldown}% Demote sectional commands
  {\let\section\subsection%
   \let\subsection\subsubsection%
   \let\subsubsection\paragraph%
   \let\paragraph\subparagraph%
   %\let\subparagraph\relax%
  }{}
\newenvironment{levelup}% Promote sectional commands
  {\let\subparagraph\paragraph%
   \let\paragraph\subsubsection%
   \let\subsubsection\subsection%
   \let\subsection\section%
   %\let\section\relax%
  }{}

For promotion (levelup), \section can either be left as-is, or made into something else. Similarly, for demotion (leveldown), \subparagraph can either be left as-is, or made into something else.

As an example, consider the following MWE:

enter image description here

\documentclass{article}
\usepackage{lipsum}% http://ctan.org/pkg/lipsum
\setcounter{tocdepth}{5}% Show up to \subparagraph in ToC
\setcounter{secnumdepth}{5}% Number up to \subparagraph
\newenvironment{leveldown}% Demote sectional commands
  {\let\section\subsection%
   \let\subsection\subsubsection%
   \let\subsubsection\paragraph%
   \let\paragraph\subparagraph%
   %\let\subparagraph\relax%
  }{}
\newenvironment{levelup}% Promote sectional commands
  {\let\subparagraph\paragraph%
   \let\paragraph\subsubsection%
   \let\subsubsection\subsection%
   \let\subsection\section%
   %\let\section\relax%
  }{}
\begin{document}
\tableofcontents
\section{A section}\lipsum[1]
\subsection{A subsection}\lipsum[2]
\subsubsection{A subsubsection}\lipsum[3]
\subsubsection{A subsubsection}\lipsum[4]
%\begin{leveldown}
  \subsection{A subsection}\lipsum[5]
  \subsubsection{A subsubsection}\lipsum[6]
  \subsubsection{A subsubsection}\lipsum[7]
%\end{leveldown}
\section{A section}\lipsum[1]
\subsection{A subsection}\lipsum[2]
\subsubsection{A subsubsection}\lipsum[3]
%\begin{levelup}
  \subsubsection{A subsubsection}\lipsum[4]
  \subsection{A subsection}\lipsum[5]
  \subsubsection{A subsubsection}\lipsum[6]
%\end{levelup}
\subsubsection{A subsubsection}\lipsum[7]
\section{A section}\lipsum[1]
\subsection{A subsection}\lipsum[2]
\subsubsection{A subsubsection}\lipsum[3]
\subsubsection{A subsubsection}\lipsum[4]
\subsection{A subsection}\lipsum[5]
\subsubsection{A subsubsection}\lipsum[6]
\subsubsection{A subsubsection}\lipsum[7]
\section{A section}\lipsum[1]
\subsection{A subsection}\lipsum[2]
\subsubsection{A subsubsection}\lipsum[3]
\subsubsection{A subsubsection}\lipsum[4]
\subsection{A subsection}\lipsum[5]
\subsubsection{A subsubsection}\lipsum[6]
\subsubsection{A subsubsection}\lipsum[7]
\end{document}

Uncommenting the levelup and leveldown environments, yields the following ToC:

enter image description here

The above discussion excludes \chapter commands, but that could also be incorporated.

Werner
  • 603,163
  • This used to work with \chapter and also with KOMAscript in Texlive 2014 when using \let\section\addchap in levelup. This stopped working with the current Texlive. Any idea why? Worth a new question? – vanto Oct 16 '17 at 15:00
  • 1
    @vanto: I can't replicate the problem as my example works under TL2017, even using (say) scrbook with \let\section\addchap. Perhaps you can provide a minimal example that illustrates the problem...? – Werner Oct 16 '17 at 16:45
  • Thanks for testing. I just figured that it was caused by a side-effect through monkey-patching KOMAscript. Sorry for the noise. – vanto Oct 18 '17 at 15:49