7

Consider the following document:

\documentclass[11pt,a4paper,twoside]{book}
 \usepackage[titletoc,toc,page]{appendix}
 \begin{document}

 \setcounter{tocdepth}{2} 
 \setcounter{secnumdepth}{3} 
 \tableofcontents

 \chapter{First chapter}

 \begin{appendices}
  \chapter[]{Name of appendix}
  \label{ap1}
   blah blah
 \end{appendices}

\end{document}

This produces in the TOC:

Contents

1 First chapter......3
Appendices...........5
Appendix A...........7

and in the body of the document:

Chapter 1
First chapter

Appendices

Appendix A
Name of appendix
blah blah

I don't want to give a name to the appendix, I find it irrelevant. But I'm forced to do it with the \chapter[]{Name of appendix} command.

Is there a way not to have to give each appendix a name? This is the result I want in the body of the document (the TOC stays the same):

Chapter 1
First chapter

Appendices

Appendix A
blah blah

Now, I know I can just leave the \chapter[]{} command empty and so the title won't show, but I'm looking for a more integral solution and not just an ugly hack.

PD: this question originated here.


EDIT

I'm sorry but I'd forgotten my document is in spanish so I didn't add the specific packages. This is what the document looks like now with Werner's new definitions added:

\documentclass[11pt,a4paper,twoside]{book}

\makeatletter
\newcommand{\nonameappendix}{%
\def\@makechapterhead##1{%
  \vspace*{50\p@}%
  {\parindent \z@ \raggedright \normalfont
    \ifnum \c@secnumdepth >\m@ne
      \if@mainmatter
        \huge\bfseries \@chapapp\space \thechapter
        \par\nobreak
        %\vskip 20\p@ % <--- Removed
      \fi
    \fi
    %\interlinepenalty\@M % <--- Removed
    %\Huge \bfseries ##1\par\nobreak % <--- Removed
    \vskip 40\p@
  }}%
\def\chaptermark##1{%
      \markboth {\MakeUppercase{%
        \ifnum \c@secnumdepth >\m@ne
          \if@mainmatter
            \@chapapp\ \thechapter%
          \fi
        \fi
        }}{}}}
\makeatother
\newcommand{\newappendix}{\chapter[]{}}%
\usepackage[titletoc,toc,page]{appendix}

\usepackage[latin1]{inputenc}
\usepackage[spanish,activeacute]{babel}

\begin{document}

\setcounter{tocdepth}{2} 
\setcounter{secnumdepth}{3} 
\tableofcontents

\chapter{First chapter}

\renewcommand{\appendixtocname}{Ap\'endices}
\renewcommand{\appendixpagename}{Ap\'endices}
\begin{appendices}

  \nonameappendix
  \newappendix
  \label{ap1}
  \include{apendiceA}

\end{appendices}

\end{document}

where the apendiceA.tex file has nothing but text (ie: no chapter commands, no labels, etc..)

The issues I'm having with this is:

1-I get Apéndice A. in the TOC (notice the dot at the end). This is really minor but it still bugs me.

2- In the body of the document, after the Apéndice A title is displayed the text only begins in the next page. This is more serious.

Gabriel
  • 2,203
  • @percusse The problem with \chapter[]{} is the formatting. It will display "Appendix A" in a font that is smaller than the usual title font and then there will be a big vertical space after it. Also, it will add "Appendix A." (with a dot at the end) to the ToC. – Caramdir Jun 29 '12 at 22:23
  • if you want to add stuff to the toc you can use the \addcontentsline command – cmhughes Jun 29 '12 at 22:30
  • if there's only one appendix, forget about appendices and just use \chapter*{Appendix} along with \addcontentsline{toc}{chapter}{Appendix} (with the correct spanish title, of course). – barbara beeton Jun 30 '12 at 15:44
  • In the example there's only one appendix, but there can (will) be more. – Gabriel Jun 30 '12 at 15:49

1 Answers1

6

Here's an option that provides \nonameappendix and \newappendix. The first command sets up the chapter heading macros (removing the inclusion of a name in the chapter title), effectively treating it like a \chapter*. The second command does \chapter[]{} for convenience.

enter image description here

\documentclass[11pt,a4paper,twoside]{book}
\usepackage{lipsum}% http://ctan.org/pkg/lipsum
\makeatletter
\newcommand{\nonameappendix}{%
\def\@makechapterhead##1{%
  \vspace*{50\p@}%
  {\parindent \z@ \raggedright \normalfont
    \ifnum \c@secnumdepth >\m@ne
      \if@mainmatter
        \huge\bfseries \@chapapp\space \thechapter
        \par\nobreak
        %\vskip 20\p@ % <--- Removed
      \fi
    \fi
    %\interlinepenalty\@M % <--- Removed
    %\Huge \bfseries ##1\par\nobreak % <--- Removed
    \vskip 40\p@
  }}%
\def\chaptermark##1{%
      \markboth {\MakeUppercase{%
        \ifnum \c@secnumdepth >\m@ne
          \if@mainmatter
            \@chapapp\ \thechapter%
          \fi
        \fi
        }}{}}}
\makeatother
\newcommand{\newappendix}{\chapter[]{}}%
\usepackage[titletoc,toc,page]{appendix}% http://ctan.org/pkg/appendix
\begin{document}

\setcounter{tocdepth}{2} \setcounter{secnumdepth}{3} \tableofcontents

\chapter{First chapter}

\begin{appendices} \nonameappendix \newappendix \label{ap1} \lipsum[1]

\newappendix \lipsum[2] \end{appendices}

\end{document}​

There's also the requirement modification to \chaptermark which typically sets APPENDIX <num>.\ TITLE in the header. It now just sets APPENDIX <num>. This is also modified by \nonameappendix, with definitions taken from book.cls.

Werner
  • 603,163
  • For consistency with standard chapter titles, I think \Huge would be a better size of the title. – Caramdir Jun 29 '12 at 23:12
  • @CaramdirI thank you very much for your efforts. I applied your answer but unfortunately I'd forgotten the document is in spanish. Please see the EDIT section where I've added more info. – Gabriel Jun 30 '12 at 14:03
  • 1
    @Gaba_p: That's not me, that's Werner, who gave the answer. – Caramdir Jun 30 '12 at 15:47