I have something like this:
Section 1
...
Section 2
...
Section 3
Subsection 3.1
...
Section 4
...
And I would like to have something like this:
Section 1
...
Section 2
...
Section A
Subsection A.1
...
Section 4
...
In other words - change one of section numbers to something else 3 == A I need this for my thesis which is written in article class, and when I tried to add appendices the hyperref package broke, and "links" to section 1 directed to appendix A
edit: I made a mistake when describing the problem, I meant that the table of contents doesn't work because LaTeX generates code (*.toc file):
\contentsline {section}{\numberline {1}}{1}{section.1}
\contentsline {section}{\numberline {2}}{1}{section.2}
\contentsline {section}{\numberline {A}}{1}{section.1}
I created the following construction, and now updated it:
Description:
A new counter for sections, which will get used only in a \begin{alphasection}
... \end{alphasection}
block. Do not nest the block, or the original section number will get lost; an error message is given in this case. Each block will start recounting from "A". Original section counting continues, as this is required for HyperRef.
Put the following code in the Preamble:
\newcounter{alphasect}
\def\alphainsection{0}
\let\oldsection=\section
\def\section{%
\ifnum\alphainsection=1%
\addtocounter{alphasect}{1}
\fi%
\oldsection}%
\renewcommand\thesection{%
\ifnum\alphainsection=1%
\Alph{alphasect}
\else%
\arabic{section}
\fi%
}%
\newenvironment{alphasection}{%
\ifnum\alphainsection=1%
\errhelp={Let other blocks end at the beginning of the next block.}
\errmessage{Nested Alpha section not allowed}
\fi%
\setcounter{alphasect}{0}
\def\alphainsection{1}
}{%
\setcounter{alphasect}{0}
\def\alphainsection{0}
}%
In document:
\section{First test}
First content
\section{Second test}
Second content
\begin{alphasection}
\section{Third test}
\subsection{Subsection test}
Content test
\section{Test Other section}
\end{alphasection}
\section{Fourth test}
Last content
Produces:
1 First test
First content
2 Second test
Second content
A Third test
A.1 Subsection test
Content test
B Test Other section
5 Fourth test
Last content
Tested, works with HyperRef.
to Sandra, I had the spacing problem when using Pindatjuh code above. It was affecting all lists. I fixed it adding "%" at the end of a couple of lines in the 3rd block of its code. Now I don't have the spacing anymore.
From:
\renewcommand\thesection{%
\ifnum\alphainsection=1%
\Alph{alphasect}
\else%
\arabic{section}
\fi%
}%
To:
\renewcommand\thesection{%
\ifnum\alphainsection=1%
\Alph{alphasect}%
\else
\arabic{section}%
\fi%
}%
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With