Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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}
share|improve this question
1  
Does tex.stackexchange.com/questions/26181/… help at all? –  Joseph Wright Jun 30 '12 at 17:00
    
@JosephWright Thanks, It's strongly related but it is just applicable to new documents. –  PHPst Jun 30 '12 at 17:40

1 Answer 1

up vote 14 down vote accepted

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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