LaTeX 中有多个子标题级别

LaTeX 中有多个子标题级别

我正在写一篇论文,需要在主标题(副标题)下创建一些级别的标题,例如:

1 Level A
1.1 Level B
1.1.1 Level C
1.1.1.1 Level D
1.1.1.1.1 Level E
1.1.1.1.1.1 Level F
1.1.1.1.1.1.1 Level G

之后,我需要创建一个列出的标题,以便在前面的示例的任何标题下,我都可以添加按字母编号的标题,例如;

1 Level A
  A Numbered subheading 1
  B Numbered Subheading 2
1.1 Level B
  A Numbered subheading 1
  B Numbered Subheading 2
1.1.1 Level C
  A Numbered subheading 1
  B Numbered Subheading 2
1.1.1.1 Level D
  A Numbered subheading 1
  B Numbered Subheading 2
1.1.1.1.1 Level E
  A Numbered subheading 1
  B Numbered Subheading 2
1.1.1.1.1.1 Level F
  A Numbered subheading 1
  B Numbered Subheading 2
1.1.1.1.1.1.1 Level G
  A Numbered subheading 1
  B Numbered Subheading 2

答案1

您可以使用修改https://tex.stackexchange.com/a/31010/4427

\documentclass[a4paper]{report}
\usepackage{chngcntr}

\usepackage[margin=2cm]{geometry}% just to increase the page area

\makeatletter
\newcommand\level[1]{%
  \ifcase#1\relax\expandafter\chapter\or
    \expandafter\section\or
    \expandafter\subsection\or
    \expandafter\subsubsection\else
    \def\next{\@level{#1}}\expandafter\next
  \fi}
\newcommand{\@level}[1]{%
  \@startsection{level#1}
    {#1}
    {\z@}%
    {-3.25ex\@plus -1ex \@minus -.2ex}%
    {1.5ex \@plus .2ex}%
    {\normalfont\normalsize\bfseries}}

\newdimen\@leveldim
\newdimen\@dotsdim
{\normalfont\normalsize
 \sbox\z@{0}\global\@leveldim=\wd\z@
 \sbox\z@{.}\global\@dotsdim=\wd\z@
}

\newcounter{level4}[subsubsection]
\@namedef{thelevel4}{\thesubsubsection.\arabic{level4}}
\@namedef{level4mark}#1{}
\def\l@section{\@dottedtocline{1}{0pt}{\dimexpr\@leveldim*4+\@dotsdim*1+6pt\relax}}
\def\l@subsection{\@dottedtocline{2}{0pt}{\dimexpr\@leveldim*5+\@dotsdim*2+6pt\relax}}
\def\l@subsubsection{\@dottedtocline{3}{0pt}{\dimexpr\@leveldim*6+\@dotsdim*3+6pt\relax}}
\@namedef{l@level4}{\@dottedtocline{4}{0pt}{\dimexpr\@leveldim*7+\@dotsdim*4+6pt\relax}}

\count@=4
\def\@ncp#1{\number\numexpr\count@+#1\relax}
\loop\ifnum\count@<100
  \begingroup\edef\x{\endgroup
    \noexpand\newcounter{level\@ncp{1}}[level\number\count@]
    \noexpand\@namedef{thelevel\@ncp{1}}{%
      \noexpand\@nameuse{thelevel\@ncp{0}}.\noexpand\arabic{level\@ncp{1}}}
    \noexpand\@namedef{level\@ncp{1}mark}####1{}%
    \noexpand\@namedef{l@level\@ncp{1}}%
      {\noexpand\@dottedtocline{\@ncp{1}}{0pt}{\the\dimexpr\@leveldim*\@ncp{5}+\@dotsdim*\@ncp{0}\relax}}%
    \noexpand\counterwithin{paragraph}{level\@ncp{1}}%
  }\x
  \advance\count@\@ne
\repeat

\makeatother


\setcounter{secnumdepth}{100}
\setcounter{tocdepth}{100}
\renewcommand{\theparagraph}{\Alph{paragraph}}


\begin{document}

\tableofcontents

\level{0}{Level A}
\paragraph{Subheading}
\paragraph{Subheading}
\level{1}{Level B}
\paragraph{Subheading}
\paragraph{Subheading}
\level{2}{Level C}
\paragraph{Subheading}
\paragraph{Subheading}
\level{3}{Level D}
\paragraph{Subheading}
\paragraph{Subheading}
\level{4}{Level E}
\paragraph{Subheading}
\paragraph{Subheading}
\level{5}{Level F}
\paragraph{Subheading}
\paragraph{Subheading}
\level{6}{Level G}
\paragraph{Subheading}
\paragraph{Subheading}
\end{document}

在此处输入图片描述

相关内容