是否可以指定相对于上一级别的\ section\subsection\subsubsection等级别?我在想的是类似的东西
\thissection The top level
\pushsection
\thissection The next level down
\thissection One more
\pushsection
\thissection Deeper
\popsection
\thissection At the same level and follows "one more"
Run Code Online (Sandbox Code Playgroud)
我的想法是,我从内到外编写一个文档,即从更深层次开始,我不知道它上面会有多少层.这样就可以避免通过将\ subsection重命名为\ subsubsection等来进行大规模的重新调整.
顺便说一下,谷歌搜索乳胶和"相关部分"会导致几乎完全涉及滥用"相对"一词的命中; 作者打算说"相关部分".
谢谢你的任何想法.
利亚姆
您可以实现您的\pushsection,, \popsection并\thissection使用计数器和if-then-else逻辑:
\usepackage{ifthen}
\newcounter{section-level}
\setcounter{section-level}{0}
\newcommand{\pushsection}{\addtocounter{section-level}{1}}
\newcommand{\popsection}{\addtocounter{section-level}{-1}}
\newcommand{\thissection}[1]
{
\ifthenelse{\equal{\value{section-level}}{0}}{\section{#1}}{}
\ifthenelse{\equal{\value{section-level}}{1}}{\subsection{#1}}{}
\ifthenelse{\equal{\value{section-level}}{2}}{\subsubsection{#1}}{}
}
Run Code Online (Sandbox Code Playgroud)
对于3个级别的部分,这将与您在上面显示的完全一样.当然,您应该做一些事情来处理超出范围的嵌套级别(例如崩溃TeX构建和打印警告).