Chapters in the appendix of a book

1,380 views
Skip to first unread message

Michael Rudolf

unread,
Nov 9, 2009, 5:55:23 PM11/9/09
to tufte-latex
Hi,

In order to distinguish the chapters in the appendix of my book from
the regular chapters in the main matter, I decided it might be a good
idea to prepend the string "Appendix" together with an alphanumeric
counter and a colon to the chapter title. I am not sure whether this
is what Tufte would recommend, maybe there is a better way?

Anyway, I am stuck with what I deem a LaTeX macro parameter expansion
and I would be very happy if someone could point out the right way to
do it. In the peamble of my document I redefine the \appendix command
to in turn redefine the chapter command in order to prepend the string
described above to the chapter name:

\newcounter{appendices}
\let\stdappendix\appendix
\def\appendix{%
\stdappendix%
\let\stdchapter\chapter%
\def\chapter##1{%
\stepcounter{appendices}%
\stdchapter{Appendix~\Alph{appendices}: ##1}%
}%
}

I already decided to throw some \expandafter commands at the problem,
one before \stdchapter and one before the opening curly brace, but it
does not quite work. Actually, the counter value is displayed in the
chapter titles as well as in the table of context and in the PDF
bookmarks, probably due to some hyperref explicit expansion under the
hood. However, a \nameref to a \label attached to one chapter in the
appendix appears in the text as "Appendix : My Appendix Title", i.e.,
the roman counter is not printed there. I also found that the AUX file
contains a \newlabel entry with the \Alph macro unexpanded, which is
probably the reason why it does not appear correctly in the \nameref
macro.

Does someone know what I am doing wrong? Thanks in advance!

Best regards,
Michael

Kevin Godby

unread,
Nov 15, 2009, 8:13:05 PM11/15/09
to tufte...@googlegroups.com
Hello, Michael.

I haven't looked at the code you provided yet, but have you checked
out the 'appendix' package (http://ctan.org/pkg/appendix)? I haven't
tried it with the Tufte-LaTeX document classes, but you might give it
a shot. If it doesn't work (or if it does), please let me know and
I'll try to help you further.

Thanks!

--Kevin

Michael Rudolf

unread,
Nov 17, 2009, 5:26:48 AM11/17/09
to tufte-latex
Hi Kevin,

> I haven't looked at the code you provided yet, but have you checked
> out the 'appendix' package (http://ctan.org/pkg/appendix)? I haven't
> tried it with the Tufte-LaTeX document classes, but you might give it
> a shot.  If it doesn't work (or if it does), please let me know and
> I'll try to help you further.

Thanks for pointing me to the appendix package. Unfortunately it does
not work together well with the tufte document class, because the
latter uses the titlesec package to change the way chapter titles are
typeset. As a result, the titletoc option from the appendix package
works, placing the word "Appendix" before each chapter in the table of
contents (without a counter, though), but the title and header options
do not.

Therefore I tried to persuade the titlesec package to rename my
appendix chapters but I had to realize that this only affects the
typesetting, not the actual value of the chapter titles. As a
consequence, additional magic would be required to get the chapter
name customization to work in the table of contents and in the page
headers. Thus, I think that the easiest way is still to modify the
chapter name itself before it is passed on to all the other commands
responsible for typesetting it in the table of contents, the page
headers and the chapter page itself.

Best regards,
Michael

Kevin Godby

unread,
Nov 20, 2009, 11:11:07 PM11/20/09
to tufte...@googlegroups.com
Hello, Michael.

I'm not sure if the attached .tex file does everything you want or not.

I've modified the appearance of appendices in the TOC so that they look like:

Appendix A: My first appendix 57

The chapter heads for appendices look like this:

Appendix A
My first appendix

To make sure the appendices are enumerated in the TOC:

\setcounter{tocdepth}{1}

and in the chapter heads themselves:

\setcounter{secnumdepth}{1}

Did I miss any of your requirements?

If this code suits your needs, you can create a file named
'tufte-book-local.tex' and put it someplace where LaTeX will find it
(e.g., with the other Tufte-LaTeX files, in your own TEXMF directory,
or in the same directory as your book's .tex file). The tufte-book
document class will automatically load this file if it exists and use
your \appendix definition. (If you do put this code in the
tufte-book-local.tex file, remove the \makeatletter and \makeatother
commands.)

--Kevin
appendix-book.tex

Michael Rudolf

unread,
Nov 21, 2009, 6:56:10 AM11/21/09
to tufte-latex
Hi Kevin,

> I'm not sure if the attached .tex file does everything you want or not.

This is just wonderful - except for one small gotcha: it does not seem
to work in conjunction with the commands \frontmatter, \mainmatter and
\backmatter. I had a look into the redefinition of these commands in
the tufte-book class but I could not find a reason there.

Furthermore, it seems as if the appendix entries in the table of
contents use a slightly larger font, but this could also be a
subjective impression. However, thanks for the work so far!

Best regards,
Michael

Kevin Godby

unread,
Nov 21, 2009, 7:56:46 PM11/21/09
to tufte...@googlegroups.com
Hey, Michael.

On Sat, Nov 21, 2009 at 5:56 AM, Michael Rudolf
<s060...@mail.inf.tu-dresden.de> wrote:
> Hi Kevin,
>
>> I'm not sure if the attached .tex file does everything you want or not.
>
> This is just wonderful - except for one small gotcha: it does not seem
> to work in conjunction with the commands \frontmatter, \mainmatter and
> \backmatter. I had a look into the redefinition of these commands in
> the tufte-book class but I could not find a reason there.

It looks like it's an interaction between the titlesec package and the
fact that \backmatter sets the @mainmatter boolean to false. (The
titlesec package suppresses the chapter numbering outside of the main
matter.

This may have unintentional side effects, but you can temporarily set
the @mainmatter boolean to true, typset your appendices, and then set
@mainmatter to false again before typsetting your index or other back
matter.

After the \appendix command, put \setboolean{@mainmatter}{true}.
After you're done with your appendices, put in
\setboolean{@mainmatter}{false}.

If you encounter any adverse side-effects of this, please let me know.

> Furthermore, it seems as if the appendix entries in the table of
> contents use a slightly larger font, but this could also be a
> subjective impression. However, thanks for the work so far!

They appear to measure the same size on my end. Are you using the
default fonts? If you do notice a difference in the sizes, please
attach an example and I'll try to figure out what's up.

--Kevin

Michael Rudolf

unread,
Nov 22, 2009, 5:59:34 AM11/22/09
to tufte-latex
Hi Kevin,

> It looks like it's an interaction between the titlesec package and the
> fact that \backmatter sets the @mainmatter boolean to false.  (The
> titlesec package suppresses the chapter numbering outside of the main
> matter.
>
> This may have unintentional side effects, but you can temporarily set
> the @mainmatter boolean to true, typset your appendices, and then set
> @mainmatter to false again before typsetting your index or other back
> matter.

This has done the trick and I did not notice any side effects.

> > Furthermore, it seems as if the appendix entries in the table of
> > contents use a slightly larger font, but this could also be a
> > subjective impression. However, thanks for the work so far!
>
> They appear to measure the same size on my end.  Are you using the
> default fonts?  If you do notice a difference in the sizes, please
> attach an example and I'll try to figure out what's up.

Yes, I have been using the example file you attached, no font changes
there. I removed the second chapter and the second appendix and
renamed the first chapter and appendix to only contain a single letter
(e.g., TTTTTTTTTT). The table of contents uses a larger font for the
appendix name than for the regular chapter, you can see that from the
space required by a single letter. Unfortunately I do not seem to have
the rights to attach files to this post, otherwise I would have sent
the PDF file along for you to have a look.

Another thing that bugs me now is that sections, tables and figures in
the appendices are numbered differently: the numbering is reset and
the Appendix number is included, as in section A.1. I found out that
this has something to do with the line \setcounter{secnumdepth}{1},
setting it to 0 removes at least the section numbering but leaves the
inconsistent figure and table numbering, while setting it to -1 or
deleting the line messes up the newly gained appendix typesetting.

Best regards,
Michael

Kevin Godby

unread,
Nov 23, 2009, 8:11:34 PM11/23/09
to Michael Rudolf, tufte...@googlegroups.com
Hello.

On Sun, Nov 22, 2009 at 4:59 AM, Michael Rudolf
<s060...@mail.inf.tu-dresden.de> wrote:
>> > Furthermore, it seems as if the appendix entries in the table of
>> > contents use a slightly larger font, but this could also be a
>> > subjective impression. However, thanks for the work so far!
>>
>> They appear to measure the same size on my end.  Are you using the
>> default fonts?  If you do notice a difference in the sizes, please
>> attach an example and I'll try to figure out what's up.
>
> Yes, I have been using the example file you attached, no font changes
> there. I removed the second chapter and the second appendix and
> renamed the first chapter and appendix to only contain a single letter
> (e.g., TTTTTTTTTT). The table of contents uses a larger font for the
> appendix name than for the regular chapter, you can see that from the
> space required by a single letter. Unfortunately I do not seem to have
> the rights to attach files to this post, otherwise I would have sent
> the PDF file along for you to have a look.

I've adjusted my sample document to match your description (see
attached), and I'm not noticing the difference in size. If you like,
you can email me a copy of your PDF and sample document privately (to
<god...@gmail.com>) and I'll investigate it further.

> Another thing that bugs me now is that sections, tables and figures in
> the appendices are numbered differently: the numbering is reset and
> the Appendix number is included, as in section A.1. I found out that
> this has something to do with the line \setcounter{secnumdepth}{1},
> setting it to 0 removes at least the section numbering but leaves the
> inconsistent figure and table numbering, while setting it to -1 or
> deleting the line messes up the newly gained appendix typesetting.

Ah, that's true. One of the frustrating things about LaTeX is that
they conflate a lot of actions into a single command. This makes for
convenient defaults, but is sometimes difficult to override.

I've added the following line to our new \appendix command:

\renewcommand{\thefigure}{\@arabic\c@figure}% define \thefigure to
use only the figure number (1), not A.1

This will fix the formatting of the figure number. (We'll do the same
for tables.)

Using the remreset package, we can stop LaTeX from resetting the
figure/table numbers to 0. (See the \@removefromreset commands.)

Let me know if you run into any more problems with this code. I
haven't tested it thoroughly. (For instance, if you're using
equations, we may have to tweak their counters and numbering as well.)

--Kevin
appendix-book.pdf
appendix-book.tex

Michael Rudolf

unread,
Nov 24, 2009, 3:44:27 AM11/24/09
to tufte-latex
Hi Kevin,

> I've adjusted my sample document to match your description (see
> attached), and I'm not noticing the difference in size.  If you like,
> you can email me a copy of your PDF and sample document privately (to
> <god...@gmail.com>) and I'll investigate it further.

Don't bother, I have just found it: I have been working with the 3.0.0
release and not with the SVN version. Testing the SVN revisions since
the 3.0.0 release shows that revision 114 fixes this. So there is no
issue here (except that another release would be nice, but the SVN
version should be fine for me so long).

> Ah, that's true.  One of the frustrating things about LaTeX is that
> they conflate a lot of actions into a single command.  This makes for
> convenient defaults, but is sometimes difficult to override.
>
> I've added the following line to our new \appendix command:
>
>   \renewcommand{\thefigure}{\@arabic\c@figure}% define \thefigure to
> use only the figure number (1), not A.1
>
> This will fix the formatting of the figure number.  (We'll do the same
> for tables.)
>
> Using the remreset package, we can stop LaTeX from resetting the
> figure/table numbers to 0.  (See the \@removefromreset commands.)
>
> Let me know if you run into any more problems with this code.  I
> haven't tested it thoroughly.  (For instance, if you're using
> equations, we may have to tweak their counters and numbering as well.)

This works very nicely indeed, I just added the line

\@removefromreset{footnote}{chapter}%don't reset footnote numbering

so that footnote numbering will also continue. I did not test it with
equations or other environments, though. I also integrated the setting
of the mainmatter boolean into the redefined appendix command, so that
it can be removed from the document body and becomes transparent to
the document author. All in all this makes a very nice extension and
perhaps others can profit from it, too - what about adding it to the
tufte-common code as a default or as an option? Anyway, thank you very
much for all your help!

Best regards,
Michael
Reply all
Reply to author
Forward
0 new messages