2

I would like to manually set subsections as letter or numbers in the same document

    1. First section 
        1.P. First subsection 
             1.P.1. First subsubsection
             1.P.2. Second subsubsection
        1.V. Second subsection 
    2. Second section
       2.1 First subsection 

(Spacing not needed)

I would still like the numbering on section og subsubsection level to follow the usual counting rules.

Is it possible to do something like:

    \section{First section}
    \lettersubsection[P]{First subsection}
    \subsubsection{First subsubsection} 
    \subsubsection{Second subsubsection} 
    \lettersubsection[V]{Second subsection}
    \section{First section}
    \subsection{First subsection}

But how to define \lettersubsection[]{}? Here I'm stuck. Is it even possible to combine counters like that? I think I can avoid mixing letters and numbers within the same section, if that can make things easier. Thank you very much!

1 Answer 1

4

You might extend the \subsection command to take an optional argument in parentheses; in this case, the argument will be used instead of the number.

\documentclass{article}

\NewCommandCopy{\originalsubsection}{\subsection}
\RenewDocumentCommand{\subsection}{sd()O{#4}m}{%
  \IfBooleanTF{#1}
    {\originalsubsection*{#4}}%
    {%
     \IfNoValueTF{#2}
       {% no letter
        \renewcommand{\thesubsection}{\thesection.\arabic{subsection}}%
       }
       {% letter
        \addtocounter{subsection}{-1}%
        \renewcommand{\thesubsection}{\thesection.#2}%
       }
     \originalsubsection[#3]{#4}%
    }%
}

\begin{document}

\section{First section}

\subsection(P){First subsection}

\subsubsection{First subsubsection}

\subsubsection{Second subsubsection} 

\subsection(V){Second subsection}\label{v}

\subsubsection{First subsubsection}\label{1-v}

\section{First section}

\subsection{First subsection}

\ref{v} and \ref{1-v}

\end{document}

enter image description here

In order for hyperref to work, add also

\renewcommand{\theHsubsection}{\thesubsection}

at the end of the given code.

7
  • Thanks a lot, this is very good, but unfortunately I get this strange error message: Undefined control sequence. \NewCommandCopy I'm doing something very wrong, aren't I?
    – nunatak
    Oct 4, 2021 at 19:32
  • 2
    Based on that error, the only thing you might be doing wrong is using an older version of LaTex. If you use xparse, it will probably work. Can @egreg (or someone else) please confirm if that is the case?
    – enkorvaks
    Oct 5, 2021 at 4:07
  • 2
    @nunatak In that case you're running an older version of LaTeX. In order to solve the problem do instead \usepackage{letltxmacro} and \LetLtxMacro{\originalsubsection}{\subsection}.
    – egreg
    Oct 5, 2021 at 6:52
  • Thanks a lot, I upgraded my LeTeX-version and it works! It seems however that I got an issue with table of contents (I'll make a post below):
    – nunatak
    Oct 5, 2021 at 17:50
  • 1
    @nunatak Sorry, there was a typo: one #3 needed to be #4, see fix
    – egreg
    Oct 6, 2021 at 6:55

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .