# Modifying an individual subsection number

I have an article divided into sections and subsections. I need to insert a subsection "5.2a" between "5.2" and "5.3". What is the easiest way to do this?

• Hi, you can find the answer to your question in this topic stackoverflow.com/questions/2839647/…. Only small adaptation would be required to get the result you want. Mar 22, 2013 at 12:27
• I removed the sections-paragraphs tag because your question could also be useful for modifying chapter numbers. Mar 22, 2013 at 12:59

If it is just for just one time, the easies way would be to redefine the representation for the subsection counter, and then revert to the original definition:

\documentclass{article}

\begin{document}

\section{Test Section}
\subsection{Test Subsection One}
\renewcommand\thesubsection{\thesection.\arabic{subsection}a}
\subsection{Test Subsection One A}\label{sec:test}
\renewcommand\thesubsection{\thesection.\arabic{subsection}}
\subsection{Test Subsection Two}

\end{document}


• instead of re-resetting after the changed subsection, one could precede the initial \addtocounter by \begingroup and replace the second \renewcommand\thesubsection by \endgroup. the changed heading will go into the table of contents. (and yes, i know these are "plain" tex commands, not latex, but they're more visible than braces, which could also be used.) Mar 22, 2013 at 13:52
• Thanks, as this is a one-off I think I'll go for the quick and dirty solution!
– ajd
Mar 23, 2013 at 5:51

A more general solution is to do the redefinition without any assumption about what \thesubsection expands to.

\documentclass{article}

%\usepackage{hyperref} % uncomment for testing with it

\makeatletter
\newcommand{\specialsubsection}[1]{%
\def\@specialsubsectionsuffix{#1}%
\@dblarg\@specialsubsection
}
\def\@specialsubsection[#1]#2{%
\begingroup
\expandafter\def\expandafter\thesubsection\expandafter{%
\thesubsection\@specialsubsectionsuffix}%
\@ifundefined{theHsubsection}%
{}%
{\expandafter\def\expandafter\theHsubsection\expandafter{%
\theHsubsection\@specialsubsectionsuffix}}%
\subsection[#1]{#2}%
\endgroup
}
\makeatother

\begin{document}

\section{Test Section}
\subsection{Test Subsection One}

\specialsubsection{a}{Test Subsection One A}\label{sec:test}

\specialsubsection{b}[For toc]{Test Subsection One B}

\subsection{Test Subsection Two}

\end{document}


This allows also for a different TOC entry, with the usual optional argument (after the suffix).

The \theHsubsection bit is to make the code work with hyperref.

• Looks excellent, but it doesn't appear to work nicely with \ref.
– ajd
Mar 23, 2013 at 5:51