# Problem with mixed alphabetic/numeric counters

My question builds upon this one. Namely, I wish to have the following structure:

APPENDIX (Part)

First part of the appendix (Chapter)

A.1 First section of the first part (Section)

Here is an MWE:

\documentclass[11pt,twoside]{report}
\usepackage[hypertexnames=false]{hyperref}

\begin{document}
\tableofcontents

\phantomsection
\chapter*{Preface}
\addcontentsline{toc}{chapter}{Preface}
%===
\phantomsection
\part*{APPENDIX}
\addcontentsline{toc}{part}{APPENDIX}
%
\setcounter{chapter}{0}
\renewcommand{\thechapter}{\Alph{chapter}}
%
\chapter*{First chapter of the appendix}
\addcontentsline{toc}{chapter}{\numberline{A}First chapter of the appendix}
%
\setcounter{section}{0}
\renewcommand{\thesection}{\Alph{chapter} . \arabic{section}}
\section{First section of the first chapter}

\end{document}


For part and chapter this works allright, but for section I get

. 1 First part of the first chapter


That is, the counter chapter in \thesection gets lost. What's wrong?

Also, interestingly enough, without \setcounter{section}{0} I get . 3, where 3 is the value of \thesection from the previous chapter. Why wasn't it reinitialized?

Since I started to ask, there is another little issue. In TOC I see APPENDIX on p.4 while in the text it is on p.3.

ADDON: here is the desired TOC that I managed to produce thanks to your answers.

• A numbered section in an unnumbered chapter is not reset. You have to reset yourself and configure the \thesection macro – user31729 Mar 6 '17 at 13:37
• Note that according to the answer provided by Nathan Grigg here: (tex.stackexchange.com/a/62766/117050) the usage of \phantomsection is not necessary here. – Skillmon Mar 6 '17 at 19:22

## 4 Answers

No twiddling with counters: what you want is that, for the appendix, the chapter head is typeset as if it were starred.

\documentclass[11pt,twoside]{report}
\usepackage{hyperref}

\makeatletter
\newcommand{\startappendix}{%
\cleardoublepage
\appendix
\phantomsection\addcontentsline{toc}{part}{APPENDIX}
\part*{APPENDIX}
\let\@makechapterhead\@makeschapterhead
}
\makeatother

\begin{document}

\tableofcontents

\phantomsection
\chapter*{Preface}
\addcontentsline{toc}{chapter}{Preface}

\chapter{Title}

\section{First}

\section{second}

\startappendix

\chapter{First chapter of the appendix}

\section{First section of the first chapter}

\section{Second section of the first chapter}

\chapter{Second chapter of the appendix}

\section{First section of the first chapter}

\end{document}


• Very good answer. Only one addition: Usage of \phantomsection in \startappendix is not necessary with latest hyperref-package. – Skillmon Mar 7 '17 at 7:54

The easiest way to get around your problem is to have numbered chapters.

The problem is that the counter chapter is zero. You write the chapter without a number and then the counter is not increased, hence zero. The function \Alph translates the number to a capital letter, starting with 1->A, and so on until 26->Z. Numbers higher than 26 will give an error. Now, when the counter is zero it doesn't give any output. Compare with the code below

\documentclass{article}
\newcounter{TestCount}
\begin{document}
\setcounter{TestCount}{0}
First: \Alph{TestCount}.

\setcounter{TestCount}{1}
Second: \Alph{TestCount}.

\setcounter{TestCount}{26}
Third: \Alph{TestCount}.
\end{document}


• So, basically, I just needed to set chapter to 1! I've tried and it works! – Dmitry Mar 6 '17 at 13:49
• The only extra modification I have to add is the line \stepcounter{chapter} before starting a new chapter, that is, I need to increase the counter manually. – Dmitry Mar 6 '17 at 13:53

You get the output because you used \chapter* which results in an empty \thechapter variable. Try using \chapter{First part of appendix} instead. Additionally you should provide a complete MWE in your question (containing the document header and stuff).

EDIT: My formulation was not good. \thecapter is empty because the counter chapter is 0. To get the desired behavior you could advance the counter manually like this:

\chapter*{foo}
\setcounter{chapter}{1}


To get lost of the "Chapter 1" line globally you might have a look at this question: how to suppress “chapter” in \chapter (while keeping numbering)

EDIT2: Regarding the wrong page of the part in TOC: (only guessing) This might be because of the \part command clearing the page. You might try the following changes:

\clearpage
\addcontentsline{toc}{part}{APPENDIX}
\phantomsection
\part*{APPENDIX}

• Dear @Skillmon, I added an MWE as you suggested. Also, regarding \chapter*: I used it deliberately to avoid getting Chapter A at the top of the page. However, I include A in the TOC. – Dmitry Mar 6 '17 at 13:13
• I'm also not quite sure about your interpretation. Just above \chapter* I define \thechapter to be \Alph{chapter}. Even if I move these lines below \chapter* the problem still occurs. – Dmitry Mar 6 '17 at 13:18
• @Dmitry sorry for initially poor answer. I wasn't sure what you wanted to achieve. I edited my answer but StefanH's might be better anyway. – Skillmon Mar 6 '17 at 13:59
• Thank you, this was useful. Alas, I cannot upvote questions yet, so I cannot give you +1. – Dmitry Mar 6 '17 at 14:14
• If \c@chapter expands to 0, then \thechapter will print 0 if \arabic is enabled. You're right that there will be no output of \thechapter if \Alph is used in \thechapter – user31729 Mar 6 '17 at 14:32

The usage of numbered sections in unnumbered chapter is weird, in my point of view.

In order to prevent screwing up numbers, I introduced a fakechapter counter and \addtocounter{chapter}{-1}\stepcounter{chapter} -- this will reset the full counter list of chapter. \setcounter{section}{0} is not sufficient there.

I also changed to another version of the \appendix macro.

\documentclass[11pt,twoside]{report}
\usepackage[hypertexnames=false]{hyperref}

\newcounter{fakechapter}
\usepackage{xpatch}

\makeatletter

\AtBeginDocument{%
\xpretocmd{\@schapter}{\phantomsection\refstepcounter{fakechapter}\addtocounter{chapter}{-1}\stepcounter{chapter}}{\typeout{success!}}{}% This will reset the section counter
}
\let\appendixorig\appendix
\renewcommand{\appendix}{%
\appendixorig
\renewcommand{\appendixname}{APPENDIX}
\part*{\appendixname}
\renewcommand{\thefakechapter}{\Alph{fakechapter}}
\renewcommand{\thesection}{\arabic{section}}
\setcounter{fakechapter}{0}
}
\makeatother

\begin{document}
\tableofcontents
\phantomsection
\chapter*{Preface}
\addcontentsline{toc}{chapter}{Preface}
%===
\chapter{Normalchapter}

\section{Foo section}
\section{Foobar section}
\section{FoobarFoo section}

\appendix

\chapter*{First chapter of the appendix}
\addcontentsline{toc}{chapter}{\protect\numberline{\thefakechapter}First chapter of the appendix}
\section{First section of the first chapter}
\end{document}


• I vote your question. Very nice. – Sebastiano Mar 6 '17 at 14:30
• Dear @Christian, thank you for your elaborated answer. I'll need some time to understand how it works. The point was to refer with letters to the results presented in the Appendix and retain numbered chapters for the main part of the document. So my chapters are not unnumbered, but just differently numbered (see the figure in my question) – Dmitry Mar 6 '17 at 15:23
• @Dmitry: If you use \chapter* the chapters are unnumbered – user31729 Mar 6 '17 at 15:26
• I used it to get rid of CHAPTER A at the top of the page. Perhaps this was not the best choice, though. – Dmitry Mar 6 '17 at 15:28
• @Dmitry: No, apparently not. There are other ways to do so. I'll try to update later on – user31729 Mar 6 '17 at 15:29