7

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}
Kara
  • 6,115
  • 16
  • 50
  • 57
Karpik
  • 322
  • 1
  • 5
  • 14

5 Answers5

9

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.

Pindatjuh
  • 10,550
  • 1
  • 41
  • 68
  • the problem is that for hyperref package *A* is the same as *1*, so links to *section 1* direct to *section A* I need a command that will tell LaTeX to keep the original counter running but display different values (in my example - keep number 3 but display A and keep number 4 but display B) – Karpik May 15 '10 at 11:27
  • @user309937 Fixed the problem ;) Enjoy! – Pindatjuh May 16 '10 at 13:16
4

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%
}%
Mario
  • 41
  • 1
1

The problem Karpik had (problem with hyperref) could more easily be solved by adding the option [naturalnames] to the hyperref package: \usepackage[naturalnames]{hyperref}

Bob
  • 11
  • 1
0

Ok, I solve it using @Pindatjuh code, solution is pretty ugly...

 \newcounter{alphasect}

 \renewcommand\thesection{%
 \ifnum\value{alphasect}=1%
A%%
 \else
\ifnum\value{alphasect}=2%
B%%
\else
\ifnum\value{alphasect}=3%
C%%
\else
\ifnum\value{alphasect}=4%
D%%
\else
 \arabic{section}%%
 \fi\fi\fi\fi}%

 \newenvironment{asection}{%
 \setcounter{alphasect}{1}%%
 }{%
 \setcounter{alphasect}{0}%%
 }%

 \newenvironment{bsection}{%
 \setcounter{alphasect}{2}%%
 }{%
 \setcounter{alphasect}{0}%%
 }%

a than in document:

\section{First test}
First content
\section{Second test}
Second content
\begin{asection}
\section{Third test}
\subsection{Subsection test}
Content test
\end{asection}
\begin{bsection}
\section{Test Other section}
\end{bsection}
\section{Fourth test}
Last content

now list of contents works, and it's displayed as it should

Karpik
  • 322
  • 1
  • 5
  • 14
-1

Have a look at the titlesec package.

Bozhidar Batsov
  • 55,802
  • 13
  • 100
  • 117