views:

449

answers:

3

Hi, 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 tired 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}
A: 

Have a look at the titlesec package.

Bozhidar Batsov
+4  A: 

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
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)
@user309937 Fixed the problem ;) Enjoy!
Pindatjuh
A: 

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