2

I'm using MikTex and I'm attempting to create a government statute-type document that has nested levels such as:

I. Section
  A. Subsection
    1. Subsubsection

etc.

Additionally, I would like "enumerate" to start where the section, subsection, etc. leaves off, such that \begin{enumerate} starts with A. or B. underneath a section, or 1. or 2. underneath a subsection, etc., such that rather than having the section title, it prints normal text as needed.

I have been attempting to use the following code to change the section numbering (based on other answers on stackexchange), but I continue to get an error reading "Undefined control sequence. \subsection{name of subsection}".

\renewcommand\thesection{\Roman{Section}}
\renewcommand\thesubsection{\Alpha{Subsection}}
\renewcommand\thesubsubsection{\arabic{Subsubsection}}

I know I could manually reset the numbering using something like the following:

\begin{enumerate}
  \setcounter{enumi}{3}
  \item Continue numbering
\end{enumerate}

However, I'm hoping to automate the process. I hope this makes sense as to what I'm attempting to accomplish. Please let me know if I can clarify further.

Here's a minimum working example.

\documentclass[a4paper,12pt]{article}
\usepackage{color}
\usepackage{graphicx}
\usepackage{float}
\usepackage{lipsum}
\usepackage{natbib}
\usepackage{setspace, graphicx, fullpage, fancyhdr, amssymb, amsmath, epsfig, array, multirow, hyperref, tabularx, lscape, booktabs, sidecap, subfig, longtable, enumitem, libertine, todonotes}
\usepackage{caption}
\usepackage[hang]{footmisc}
\usepackage{multicol}
\renewcommand\thesection{\Roman{Section}}
\renewcommand\thesubsection{\Alpha{Subsection}}
\renewcommand\thesubsubsection{\arabic{Subsubsection}}

\begin{document}

\pagenumbering{arabic}
\title{\huge The Constitution}
\author{\large The Author}
\date{\today}
\maketitle 

\tableofcontents

\newpage

\section{Preamble}

\subsection{Name}

We shall be called The Government.

\subsection{Purpose}
\begin{enumerate}
    \item To represent the people.
    \item To preserve democracy.
\end{enumerate}
\subsection{Senate}
Who are the members?
\subsubsection{Voting Members}
These people can vote.
\end{document}

TL;DR I need \renewcommand\thesection{\Roman{Section}} to work, and I need the enumerate function to continue the numbering of the section wherever it leaves off to print normal text rather than titles.

EDIT: A visual example from a legislative drafting website (but with a different numbering order/layout):

(a) (Subsection could be a label/heading, but also could be just the enumerate at the same level as plain text) 

            (1) (Subsubsection, could be a label/heading, but also could be just the enumerate at the same level as plain text) 

                        (A) (Paragraph, should be text)

                                    (i) (Clause, should be text)

                                                (I) (Subclause, should be text)

EDIT 2: Here's the format I'm attempting to create

Circumscribe
  • 10,856
  • for the first issue, it should be \Roman{section}, \Alph{subsection} and \arabic{subsubsection}. Should the "to represent the people" enumerate label be B.1 or I.B.1? – Troy Dec 25 '18 at 19:01
  • @Troy thanks for your answer! The label should actually be just the number, aka 1. – ryuhekai Dec 25 '18 at 19:39
  • oh? then I'm afraid I don't understand your question anymore. what does "I need the enumerate function to continue the numbering of the section" mean then? – Troy Dec 25 '18 at 19:41
  • I tried to use the {section} change and still got the same error...I'm still struggling to figure out what's wrong there. – ryuhekai Dec 25 '18 at 19:55
  • delete your auxiliary (aux, toc etc.) files and recompile. your exact MWE with my suggested changes works here. – Troy Dec 25 '18 at 19:57
  • hm...I did try that and I got the same error. I create a new file and copy/pasted the MWE with your suggested changes and got the same issues. I also closed and reopened TexStudio and got the same error message again. So now I'm thinking there might be a settings issue? – ryuhekai Dec 25 '18 at 20:07
  • As for the numbering, I'm trying to not have the sections or subsections label the entire string of levels. For example, I'm trying to only have it displayed as such:

    I. Section A. Subsection 1. Subsubsection 2. Another subsubsection B. Another section 1. Same numbering as subsubsection but normal text rather than a heading.

    – ryuhekai Dec 25 '18 at 20:07
  • just so we are on the same page, what I meant by my first comment was: \renewcommand\thesection{\Roman{section}} and similarly for the other two. also, it's \Alph not \Alpha etc. Was this what you did? if it is, could you paste the error message in full? – Troy Dec 25 '18 at 20:20
  • @Troy yo that completely solved my issue with getting the code to even compile (changing it to \Alph). Thank you so much! Now there's just the issue of attempting to automate the continued numbering since it will be a long document (the original Word file is 45 pages).

    My edit shows a somewhat clearer example if that helps?

    – ryuhekai Dec 25 '18 at 20:25
  • np! the edit shows the numbering layout but I still don't understand the "continued numbering" part. presumably you could do a mockup pdf using manual adjustments (with setcounter or whatever) -- could you then take a screenshot and show us a picture of what you actually want? For example, in your current example code, what should be changed? what number should have been "continued"? – Troy Dec 25 '18 at 20:33
  • I will work on a better example. Using the one I have, let's say after (1), there is a (2), we return to the subsection level with (b), the create a new section. I create a subsection (a), go down to the subsubsection level but instead of it being a label, it starts with (1). I get to that via \enumerate. Or, say I go to the subsection level via \enunerate and then it automatically starts with (a) but is plain text. That's what I'm working towards--where the "level" means the indent to show the clause is underneath a previous section or subsection but is NOT a new section or subsection – ryuhekai Dec 25 '18 at 20:39
  • @Troy I've added an image to hopefully clarify what I'm trying to do. Please let me know if I can provide any additional clarity, and thanks again for all your help! – ryuhekai Dec 25 '18 at 21:43
  • thanks, much clearer now. is the indentation required? if you want this behaviour (fully automated) with a single enumerate environment, it probably needs some severe hacking (though no doubt, someone here would be able to do it :p). imo, it would be significantly easier if you are willing to use different environments on each level. – Troy Dec 25 '18 at 21:55
  • The indentations are only needed once the \enumerate begins for text on any level, which already happens. Otherwise, for sections, subsections, and subsubsections can be normal headings. – ryuhekai Dec 25 '18 at 22:02
  • the section label should be Roman (I) or Alph (A)? your example code and image don't match up – Troy Dec 25 '18 at 23:03
  • Section should be I, subsection should be A. Sorry, something happened when I copy/pasted it. My bad! – ryuhekai Dec 25 '18 at 23:15
  • Have you googled if there is a command that only Returns the current value of the enumi counter so you could take that commands Output and put it into the "Manual numbering example" as an Input and then encapsulate all that into a new command (I wouldn't recommend overwriting the original enumerate). – der bender Dec 25 '18 at 20:08

2 Answers2

2

Regarding your first issue, they should be \Roman{section}, \Alph{subsection} and \arabic{subsubsection} respectively. Note it is \Alph not \Alpha.

As for your second issue... see the code below. Basically, I check for the current section depth (adapted from Detecting section depth) and set the label based on that value using an \ifcase construct [for more info on \ifcase, @Joseph's answer here should explain things well].

\documentclass[a4paper,12pt]{article}
\usepackage{enumitem}
\usepackage{etoolbox}  % for \pretocmd

\setcounter{secnumdepth}{4} % for "subsubsubsection" <-> paragraph

% Issue 1:
\renewcommand\thesection{\Roman{section}.}
\renewcommand\thesubsection{\Alph{subsection}.}
\renewcommand\thesubsubsection{\alph{subsubsection}.}
\renewcommand\theparagraph{\roman{paragraph}.}

% Issue 2:
% adapted from: https://tex.stackexchange.com/a/401744
\makeatletter
\def\currentsection{0}% initialise
\pretocmd\@startsection{\def\currentsection{#2}}{}{}
\makeatother

\setlist[enumerate]{label={%
    \ifcase\currentsection
    \Roman*.% if outside section
    \or
    \Alph*.% section level
    \or
    \arabic*.% subsection level
    \or
    \roman*.% subsubsection level
    \or
    \alph*)% "subsubsub"section level
    \fi}
}

\begin{document}    
    \pagenumbering{arabic}
    \title{\huge The Constitution}
    \author{\large The Author}
    \date{\today}
    \maketitle 

    \tableofcontents

    \newpage

    \section{Preamble}

    \subsection{Name}   
    We shall be called The Government.

    \subsubsection{Subsubsection title}
    \begin{enumerate}
        \item Enum item 1
        \item Enum item 2
    \end{enumerate}

    \subsubsection{Another Subsubsection}
    \begin{enumerate}
        \item Enum item 1
        \item Enum item 2
    \end{enumerate}

    \paragraph{The subsubsubsection}
    \begin{enumerate}
        \item Enum 1
        \item Enum 2
    \end{enumerate}

    \subsection{Another subsection}
    \begin{enumerate}
        \item Enum item 1
        \item Enum item 2
    \end{enumerate}

    \section{Another section}
    Who are the members?
    \begin{enumerate}
        \item Enum item 1
        \item Enum item 2
    \end{enumerate}

    \section{TOC format}
    \begin{enumerate}
        \item Enum item 1
        \item Enum item 2
    \end{enumerate}

\end{document}

Troy
  • 13,741
  • This is amazing! A Christmas Miracle if you will! As a final question, if I wanted to create indentations all the way down (as in my Edit 2 example), what'd be the best way to do that? Would that be renewing a command? – ryuhekai Dec 25 '18 at 23:20
  • indentation of the enumerate environments only? or the section/subsection etc. titles must shift as well? – Troy Dec 25 '18 at 23:21
  • Having the section/subsection items move as well. – ryuhekai Dec 25 '18 at 23:23
  • @ryuhekai that's not my area of expertise unfortunately. probably with titlesec or related packages. i'm sorry I can't help you with that. if you think my answer is insufficient, feel free to remove the tick. and/or ask a follow-up question linking to this one. – Troy Dec 25 '18 at 23:25
  • No your answer was beautiful and has saved me hoooouuuurs of work. Thank you so very very much! I'm sure the indentation question has been asked before, so I'll do some searching. Many many thanks for your help! – ryuhekai Dec 25 '18 at 23:31
  • @ryuhekai no problem! happy holidays! – Troy Dec 26 '18 at 01:04
1

If you also want text within sections indented as if these were items of an enumeration environment, you may want to consider also using replacing the sectioning commands by enumerations.

I'm setting up an enumeration environment called ryuenum below that allows you to use \Item{<title>} instead of \item to produce items with a heading that is formatted like a section heading of the appropriate depth. It also inserts an entry in the TOC.

\documentclass{article}

\usepackage{enumitem}
\newlist{ryuenum}{enumerate}{5}                             %% <- max depth = 5
\setlist[ryuenum]{align=left,labelindent=0pt,               %% <- label placement
                  listparindent=\parindent,parsep=\parskip} %% <- set parindent/parskip

\setlist[ryuenum,1]{label=\Roman*.,ref=\Roman*,
  before={\ryuenumsetup[\ryutoctop]{section}{.5em}{.5em}{\Large\bfseries}}}
\setlist[ryuenum,2]{label=\Alph*.,ref=\Alph*,
  before={\ryuenumsetup{subsection}{.5em}{.5em}{\large\bfseries}}}
\setlist[ryuenum,3]{label=\arabic*.,ref=\arabic*,
  before={\ryuenumsetup{subsubsection}{.5em}{.5em}{\normalsize\bfseries}}}
\setlist[ryuenum,4]{label=\roman*.,ref=\roman*}
\setlist[ryuenum,5]{label=\alph*.,ref=\alph*}

%% Sets parameters that determine appearance of headings/toc entries:
\newlength\ryuspacebefore \newlength\ryuspaceafter
\newcommand\ryuenumsetup[5][\ryutocnormal]{%
  \let\ryutocformat#1%
  \def\ryusecdp{#2}%
  \setlength{\ryuspacebefore}{#3}%
  \setlength{\ryuspaceafter}{#4}%
  \def\ryusecformat{#5}%
}

%% Toc entry styles:
\newcommand*\ryutocnormal[2]{\protect\numberline{#1.}#2}
\newcommand*\ryutoctop[2]{Article #1: #2}

%% The \Item command
\makeatletter %% <- make @ usable in command sequences
\newcommand*\Item[1]{%
  \begingroup                                  %% <- limit scope of font change
    \normalfont\ryusecformat                   %% <- set font
    \par\vspace{\ryuspacebefore}%              %% <- space above
    \item                                      %% <- item
    \interlinepenalty\@M                       %% <- inhibit page breaks
    #1\par%                                    %% <- heading, paragraph break
    \vspace{\ryuspaceafter}                    %% <- space below
    \csname\ryusecdp mark\endcsname{#1}%       %% <- \sectionmark etc.
    \ifx\ryusecdp\empty\else                   %% <- if ryusecdp is non-empty
      \addcontentsline{toc}{\ryusecdp}         %% <- ...create toc entry at right depth
        {\ryutocformat{\@currentlabel}{#1}}%   %% <- ... with the right number/name
    \fi
  \endgroup
  \@afterheading                               %% <- prohibit indentation and enum topsep
  \ignorespaces                                %% <- does what it says
}
\makeatother  %% <- revert @

\usepackage{hyperref} %% <- not necessary, but compatible

\begin{document}

\tableofcontents

\vspace{1cm}\noindent\rule{\linewidth}{1pt}\par\vspace{1cm}

\begin{ryuenum}
    \Item{Preamble}
    \begin{ryuenum}
        \Item{Name}
        We shall be called The Government.
        \Item{Purpose}
        \begin{ryuenum}
        \item To represent the people.
            \begin{ryuenum}
            \item subclause!
            \end{ryuenum}
        \item To preserve democracy.
        \end{ryuenum}
        \Item{Senate}
        Who are the members?
        \begin{ryuenum}
            \Item{Voting Members}
            These people can vote.
        \end{ryuenum}
    \end{ryuenum}
\Item{Final item}
Lorem ipsum dolor sit.
\end{ryuenum}

\end{document}

output

I'm using the enumitem package (which I see you're also using) to set up a custom list environment and I'm setting this environment up with

before={\ryuenumsetup[<toc style>]{<section type>}{<space above>}{<space below>}{<font>}}`.

The \ryuenumsetup command sets up the variables that determine what a heading created with \Item will look like. You can tweak these values if you like to make this match your needs.

Remarks

  • Instead of defining a new enumeration environment you could also modify enumerate with \renewlist{enumerate}{enumerate}{5} and \setlist[enumerate,<n>]{…}.

  • Currently, the section headings are indented exactly as much as the content below it. This may not work for large numbers at the top level because roman numerals can be quite wide.

  • You may wish to also tweak the appearance of the toc a bit. It is by default set up so that the distance between the start of the section numbers and the titles increases with depth because section titles usually stack. From what I hear the tocloft package is good for doing this sort of thing, but I have very little experience with it.

  • You can leave the first mandatory parameter of \ryuenumsetup empty, in which case headings at this level won't show up in the table of contents.

  • Most of the definition of \Item was taken from the default sectioning commands, but some parts are left out. \Item will thus not behave exactly as a sectioning command. (It most notably won't increment the \<sub*>section counter.)

Circumscribe
  • 10,856
  • +1 @ryuhekai this seems much closer to your desired output, if you do end up using this answer, know that you can (and should) give this the green tick :) – Troy Dec 26 '18 at 15:38
  • Wow, this is super useful, thank you! Do you know if it's possible to use this set-up but alter the numbering display in the ToC? The only one I'd like (but don't have as it is somewhat more for aesthetics) to change is the highest level, so that rather than reading "I. Preamble" it would read "Article I: Preamble" and, for the next one, "Article II: Other Text".

    @Troy your answer still definitely helped a lot, thank you! Quick question re: your set-up, do you know if it would be possible to limit the counting format to a specific section of the document?

    – ryuhekai Dec 26 '18 at 20:09
  • @ryuhekai: I've significantly improved my answer (the spacing in particular has been improved). If you intend to use it you may wish to switch to this version. I've also addressed the toc entry formatting, as requested. – Circumscribe Dec 26 '18 at 22:18
  • @ryuhekai: In case you just copied my edited answer: I just discovered that I had forgotten a comma before ref=… at depth 4 and 5. I've fixed this now. – Circumscribe Dec 26 '18 at 22:25
  • @Circumscribe I have been successfully using this, though I was wondering how I could reference different items.

    I have used \label{Item:name} to provide labels to each heading. However, when I attempt to use ~\ref to call the reference, it returns a blank space. I have also tried to change the label to \label{section:name}, which has not worked (I assumed it would not given section was replaced with Item).

    Do you know how I might accomplish this? Would this need to be defined in the new environment?

    – ryuhekai Jan 07 '19 at 20:28
  • @ryuhekai: It works if you place the label inside the argument of \Item, so e.g. \Item{Preamble\label{Item:preamble}}. – Circumscribe Jan 07 '19 at 21:57
  • The reason is that \begingroup…\endgroup is like {…} and anything defined between them (such as the font changes I'm making, but also what the next \label should refer to) is forgotten after \endgroup. – Circumscribe Jan 07 '19 at 21:58
  • I can add a line to "remind" LaTeX about this after the \endgroup :). – Circumscribe Jan 07 '19 at 21:59
  • What I had in mind was replacing \endgroup by \expandafter\endgroup\expandafter\def\expandafter\@currentlabel\expandafter{\@currentlabel}, and this does work. I'll try to think of a better solution though, since this might not be compatible with any number of packages that modify \item or \refstepcounter. – Circumscribe Jan 07 '19 at 23:33