2

I am working on a thesis, and I need to create some levels of headings under the main heading (subheadings), for instance:

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

And after that I need to create a listed headings such that under any headings of the previous example I can add an alphabetical numbered heading, for instance;

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 Answers1

6

You can use a modification of 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}

enter image description here

egreg
  • 1,121,712