降级/升级章节等

降级/升级章节等

考虑以下结构:

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

如何在不改变标记的情况下将小节降级为小节?

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

如何在不改变标记的情况下将子部分提升为部分?

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

包装命令会很好

\begin[+1]{level}
\section{}
\end{level}

答案1

提升/降级分段命令的一个简单方法是使用levelup/leveldown环境:

\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%
  }{}

对于升级 ( levelup),\section可以保持原样,也可以将其转换为其他内容。同样,对于降级 ( leveldown),\subparagraph可以保持原样,也可以将其转换为其他内容。

作为示例,考虑以下 MWE:

在此处输入图片描述

\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}

取消注释levelupleveldown环境,得到以下目录:

在此处输入图片描述

上述讨论不包括\chapter命令,但也可以纳入其中。

相关内容