4

The following MWE, in which I'm trying to change \thepage in order to show both the chapter number and the page, does not compile if the alphalph package is loaded. How should it be done?

\documentclass[a4paper]{report}
\usepackage{alphalph}
\begin{document}
\appendix
\renewcommand*{\thepage}{\AlphAlph{chapter}-\arabic{page}}
\chapter{First}
\end{document}

! Missing number, treated as zero. to be read again c l.15 \end{document} A number should have been here; I inserted 0. (If you can't figure out why I needed to see a number, look up `weird error' in the index to The TeXbook.) ! Missing = inserted for \ifnum.

7

The alphalph commands needs \value{countername} instead of the counter name only, just like \number, e.g.

\number\value{countername}

always will print the counter as a number, not as defined \thecountername, which could have been defined somewhere else to be totally different what is expected.

The correct usage of \AlphAlph is

\AlphAlph{\value{countername}} 

then.

If the counter value is in the interval from 1 to 26, then \Alph{countername} is perhaps a simpler(?), quicker(?) alternative.

\documentclass[a4paper]{report}
\usepackage{alphalph}
\begin{document}
\appendix
\renewcommand*{\thepage}{\AlphAlph{\value{chapter}}-\arabic{page}}
\chapter{First}
\end{document}

I omitted a screen shot, since everybody can imagine a page number 'A-1' ;-)

  • Thanks for your answer. Actually it's enough with \Alph, but I'm writing a template and I want to add the option to switch easily to \AlphAlph. I though I could just do \let\origAlph\Alph and \let\Alph\AlphAlph. But, as you pointed out, it's not so easy... – U.Martinez-Corral Sep 28 '14 at 17:17
  • I use a \ProvideValue command with one argument, which handles either the direct value if the argument is no counter and otherwise it will use \value{countername} automatically. – user31729 Sep 28 '14 at 20:22
  • Yo mean writing something like \newcommand\ProvideValue[1]{ if#1counter #1 \else \value{#1} \fi }? – U.Martinez-Corral Sep 28 '14 at 22:08
  • Yes, something like that, best in a wrapper. (\ifltxcounter command from etoolbox works very good for this!) – user31729 Sep 29 '14 at 3:01
  • I don't really get it :S. If I define \newcommand\ProvideValue[1]{ \ifltxcounter{#1}{#1}{\value{#1}} }, then doing \Alph(\ProvideValue{chapter}) or \AlphAlph(\ProvideValue{chapter}) will both have the same #1, won't they? – U.Martinez-Corral Sep 29 '14 at 14:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.