Mostly what you describe is the standard layout without any package
\documentclass[12pt,a4paper]{report}
\begin{document}
\tableofcontents
\chapter{aaa}
...
\chapter{aaa}
...
\appendix
\chapter{Formula}
The contents...
\chapter{something}
The contents...
\end{document}
this doesn't introduce a separate "Appendices" cover page, the Appendix titles are set as chapters. If you want to make that smaller you could do it just for appendices or (more commonly) change it globally for all chapters.
There are infinitely many variations, this redefines the chapter head to use the same setting as \section
but with \LARGE
instead of \Large
so it doesn't force a page break.
Obviously if you do this a lot you could set things up to add it to the definition of \appendix
so you don't have the redefinition mid-document.
\documentclass[12pt,a4paper]{report}
\begin{document}
\tableofcontents
\chapter{aaa}
...
\chapter{aaa}
...
\makeatletter
\renewcommand\chapter{\@startsection {chapter}{0}{\z@}%
{-3.5ex \@plus -1ex \@minus -.2ex}%
{2.3ex \@plus.2ex}%
{\normalfont\LARGE\bfseries}}
\makeatother
\appendix
\chapter{Formula}
The contents...
\chapter{something}
The contents...
\end{document}
This solution does not use any package (except the OP already has), but adding a \addtocontents{toc}{...}
to the author-defined command \secappendix
.
The following command taking 3 parameters is used to set l@section
. The default value for numwidth
is 2.3em instead of 7em here. One could adjust to suit one's need.
\@dottedtocline{<level>}{<indentation>}{<numwidth>}}
If dotted lines in TOC is to remove, use the following in the preamble.
\makeatletter
\renewcommand\@dotsep{450}
\makeatother
Code
\documentclass{book}
\usepackage{etoolbox}
\usepackage{lipsum}
\usepackage{amsmath}
\numberwithin{equation}{section}
\newcommand*{\secappendix}[1]{%
\setcounter{section}{0}%
\addtocontents{toc}
{\string\renewcommand\string\l@section{\string\@dottedtocline{1}{1.5em}{7em}}}
\renewcommand*{\thesection}{\appendixname\space\thechapter.\Alph{section}}%
\section{#1}
\renewcommand*{\thesection}{\thechapter.\Alph{section}}%
\addtocontents{toc}
{\string\renewcommand\string\l@section{\string\@dottedtocline{1}{1.5em}{2.3em}}}
}
\preto{\chapter}{\renewcommand*{\thesection}{\thechapter.\arabic{section}}}
\usepackage[colorlinks=true]{hyperref}
\begin{document}
\frontmatter
\tableofcontents
\mainmatter
\chapter{Foo}
Here is a link to \ref{app:baz}.
\section{Bar}
\begin{equation}
\label{eq:1}
1 + 1 = 2
\end{equation}
\subsection{Subsection title}
\lipsum[1]
\secappendix{Baz}
\label{app:baz}
\begin{equation}
\label{eq:2}
2 + 2 = 4
\end{equation}
\subsection{Appendix subsection title}
\lipsum[1]
Hyperlink to \ref{eq:2}
\chapter{Chapter 2}
\section{Test}
\subsection{Test subsection title}
\secappendix{TestBaz}
\subsection{TestBaz subsection title}
\end{document}
Edit: The OP wishes to put the author-defined section name into the bookmark as well. To this end, this solution seeks help from bookmark
package and please load it after hyperref
package to avoid crash. Then add \pdfbookmark[section]{\thesection~#1}{#1}
, respectively for <level><bookmark text><internal label>
, into the author-defined macro as shown below.
\usepackage[colorlinks=true]{hyperref}
\usepackage{bookmark} % <-- here
\newcommand*{\secappendix}[1]{%
\setcounter{section}{0}%
\addtocontents{toc}
{\string\renewcommand\string\l@section{\string\@dottedtocline{1}{1.5em}{7em}}}
\renewcommand*{\thesection}{\appendixname\space\thechapter.\Alph{section}}%
\section{#1}
\pdfbookmark[section]{\thesection~#1}{#1} %<-- Here
\renewcommand*{\thesection}{\thechapter.\Alph{section}}%
\addtocontents{toc}
{\string\renewcommand\string\l@section{\string\@dottedtocline{1}{1.5em}{2.3em}}}
}
Final Update: It seems that the OP-defined macro will by itself insert a bookmark whenever \section{#1}
is called, resulting in repeated bookmark if the bookmark
package is used. On the first notice by the OP, an investigation is activated. To remove the redundant bookmark, this solution modifies the OP-defined macro (marked by <-- here) without using bookmark
which causes the redundancy. The objective wanted by OP is achieved and therefore post the full code again to avoid ambiguity.
** Full Code:**
\documentclass{book}
\usepackage{etoolbox}
\usepackage{lipsum}
\usepackage{amsmath}
\numberwithin{equation}{section}
\newcommand*{\secappendix}[1]{%
\setcounter{section}{1} %<-- here
\setcounter{subsection}{0} %<-- here
\addtocontents{toc}
{\string\renewcommand\string\l@section{\string\@dottedtocline{1}{1.5em}{7em}}}
\renewcommand*{\thesection}{\appendixname\space\thechapter.\Alph{section}}%
\section*{\thesection~#1} %<-- here
\phantomsection %<-- here
\addcontentsline{toc}{section}{\thesection~#1} %<-- here
\renewcommand*{\thesection}{\thechapter.\Alph{section}}%
\addtocontents{toc}
{\string\renewcommand\string\l@section{\string\@dottedtocline{1}{1.5em}{2.3em}}}
}
\preto{\chapter}{\renewcommand*{\thesection}{\thechapter.\arabic{section}}}
\usepackage[colorlinks=true]{hyperref}
%\usepackage{bookmark}
\begin{document}
\frontmatter
\tableofcontents
\mainmatter
\chapter{Foo}
Here is a link to \ref{app:baz}.
\section{Bar}
\begin{equation}
\label{eq:1}
1 + 1 = 2
\end{equation}
\subsection{Subsection title}
\lipsum[1]
\secappendix{Baz}
\label{app:baz}
\begin{equation}
\label{eq:2}
2 + 2 = 4
\end{equation}
\subsection{Appendix subsection title}
\subsection{Appendix second subsection title}
\lipsum[1]
Hyperlink to \ref{eq:2}
\chapter{Indentation}
\lipsum[1]
\section{Test}
\lipsum[1]
\subsection{Test subsection title}
\lipsum[1]
\secappendix{TestBaz}
\lipsum[1]
\subsection{TestBaz subsection title}
\subsection{TestBaz second subsection title}
\chapter{Bookmark}
\lipsum[1]
\section{Test2}
\lipsum[1]
\subsection{Test2 subsection title}
\lipsum[1]
\secappendix{Test2}
\lipsum[1]
\subsection{Test2 subsection title}
\subsection{Test2 second subsection title}
\end{document}
Best Answer
Here's a possible solution in which I assumed that the sections corresponding to appendices will be the last sections of their corresponding chapter. I defined an
\appsection
command to change\thesection
so as to obtain the required formatting; this command has to be issued before the appendices for a chapter. Using theetoolbox
package,\chapter
restores the original meaning of\thesection
.In case hyperref is loaded, the above code has to be slightly changed to