可选子节编号:2.1 2.2A 2.2B 2.3... 适用于文章类别

可选子节编号:2.1 2.2A 2.2B 2.3... 适用于文章类别

对于文档,我尝试根据读者的需要,引导他们查看第 2.2A 节或第 2.2B 节。有没有办法更改文档某一部分的节号,并使其在目录中也显示出来?

为了清楚起见,我需要以下部分:

  • 1
  • 1.1
  • 1.2
  • 2
  • 2.1
  • 2.2A
  • 2.2B
  • 2.3
  • ETC...

干杯!

答案1

唯一棘手的部分是直接从 2.1 升级到 2.2A。

\documentclass{article}
\renewcommand{\thesubsection}{\thesection.\arabic{subsection}}
\renewcommand{\thesubsubsection}{\thesubsection\Alph{subsubsection}}

\begin{document}
\tableofcontents

\section{Axiomatic}
\subsection{Bidirectional}
\subsection{Concatenate}
\section{Defenestration}
\subsection{Epistemology}
\stepcounter{subsection}% skip 2.2
\subsubsection{Fallacious}
\subsubsection{Gastronomical}
\subsection{Histrionics}
\section{Isomorphic}

\end{document}

只是为了好玩:

\documentclass{article}
\usepackage{etoolbox}

\makeatletter
\patchcmd{\l@section}{1.5em}{2.8em}{}{}% change width of \numberline
\makeatother

\renewcommand{\thesection}{\ifcase\value{section}\relax 0
  \or 1
  \or 1.1
  \or 1.2
  \or 2
  \or 2.1
  \or 2.2A
  \or 2.2B
  \or 2.3
  \else \arabic{section}
  \fi}

\begin{document}
\tableofcontents

\section{Axiomatic}
\section{Bidirectional}
\section{Concatenate}
\section{Defenestration}
\section{Epistemology}
\section{Fallacious}
\section{Gastronomical}
\section{Histrionics}
\section{Isomorphic}

\end{document}

答案2

这是一个alternativesubsections环境。

\documentclass{article}
\usepackage{hyperref}

\newcounter{savedsubsection}

\newenvironment{alternativesubsections}
 {%
  % step the subsection counter and save the value
  \refstepcounter{subsection}%
  \setcounter{savedsubsection}{\value{subsection}}%
  % save the current value of \thesubsection
  \edef\subsectionprefix{\thesubsection}%
  % now reset the subsection counter to zero
  \setcounter{subsection}{0}%
  % and define accordingly the format for \thesubsection
  \renewcommand{\thesubsection}{\subsectionprefix\Alph{subsection}}%
  % to keep hyperref happy
  \ifdefined\theHsubsection
    \let\theHsubsection\thesubsection
  \fi
 }
 {%
  % restore the value
  \setcounter{subsection}{\value{savedsubsection}}
 }

\begin{document}

\section{Section title}

\subsection{Normal subsection}

\subsection{Another}

\section{A new section}

\subsection{Normal subsection}

\begin{alternativesubsections}\label{global}

\subsection{First alternative}\label{first}

\subsection{Second alternative}\label{second}

\end{alternativesubsections}

\subsection{Normal subsection}\label{third}

We can refer to~\ref{global}, but also to~\ref{first}
and~\ref{second}. And~\ref{third}

\end{document}

请注意这hyperref不是必需的。使用它或省略它;我添加它只是为了确保代码也可以使用它。

在此处输入图片描述

相关内容