3

I have used the appendix package like this.

\usepackage[toc, page]{appendix}

This puts the title 'appendix' on its own page. Now I want to have this title, but I would rather if it put on the same page as the first chapter of the appendix, so you would have it just above chapter title of the first appendix.

I tried to read the manual, but I did not see an option for this.

1
  • There is a title option but that's not what you want, most likely?
    – user31729
    Jun 12, 2017 at 14:27

1 Answer 1

2

A version with patching of \@makechapterhead:

The patch checks whether the chapter number is 1, i.e. meaning the first appendix chapter and insertes the Appendix line accordingly, taking the values of \abovefirstappchapskip etc. into account -- those values can be changed at will.

\documentclass{book}


\usepackage{xpatch}
\usepackage[toc]{appendix}

\makeatletter
\newlength{\abovefirstappchapskip}
\newlength{\belowfirstappchapskip}
\AtBeginEnvironment{appendices}{%
  \xpatchcmd{\@makechapterhead}{%
    \vspace*{50\p@}%
  }{%
    \ifnum1=\c@chapter
    \vskip\abovefirstappchapskip%
    \fi
  }{}{}
  \xpatchcmd{\@makechapterhead}{%
    \parindent \z@ \raggedright \normalfont
  }{%
    \parindent \z@ \raggedright \normalfont
    \ifnum1=\c@chapter
    \begingroup 
    \centering \Huge\bfseries \appendixname
    \vskip\belowfirstappchapskip
    \endgroup
    \fi
  }{}{}
}
\makeatother

\setlength{\abovefirstappchapskip}{30pt}
\setlength{\belowfirstappchapskip}{30pt}

\begin{document}
\tableofcontents

\begin{appendices}
\chapter{Foo}

\chapter{Foobar}

\end{appendices}

\end{document}

enter image description here

4
  • The first solution posted worked well. The solution given after the edit would be preferable but it causes \chapter{Foobar} not to display. I am using lualatex if that possibly makes a difference. Jun 12, 2017 at 14:56
  • @MichaelBuckley: Yes, I forgot \fi in the first \xpatchcmd for \@makechapterhead. Please use the updated code, it should work with lualatex as well now
    – user31729
    Jun 12, 2017 at 15:32
  • This does not seem to do anything if you have \include{appendix} where the appendix is in another .tex. I placed the patch before my \begin{document}. Compiles without a warning or error. But I still have Appendix A and then the chapter with no Appendix title at the very top.
    – Frikster
    Aug 16, 2017 at 1:38
  • @DirkHaupt: Works for me out of the box even with \include although I never claimed it would work with \include (which I basically never use for my purposes). There's nothing I can do for you here
    – user31729
    Aug 16, 2017 at 6:12

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .