4

I wanna display A as Appendix A in TOC, as shown below.

I tried to add \backmatter before \appendix as shown in this post, but cref{label} will display as Section 1. I also used \renewcommand as suggested in the most posts on this site, but it doesn't make any changes. Here is the source code.

\documentclass[twoside,12pt]{article}

\usepackage{cleveref}

\usepackage[english]{babel}
\usepackage[toc, title]{appendix}
\renewcommand\appendixname{Anexo}
%\renewcommand\appendixpagename{Anexos}
\renewcommand\appendixtocname{Appendix}

\begin{document}

\tableofcontents

\section{The main body of the text}
Refer to \cref{appendix} for more information.

\appendix
\section{A complete table.} \label{appendix}
Some text.

\end{document}
8
  • 3
    Are you sure your readers need that extra word to know the appendix just started? You don't have the word Chapter for all the chapters, right? It is an article document, you don't have Section in front of every section entry, right?
    – Johannes_B
    Mar 6 '17 at 17:32
  • If you want to show "Appendix A" instead of just "A" in the ToC, do you want to show the longer string in the actual section-level header as well?
    – Mico
    Mar 6 '17 at 17:34
  • @Johannes_B, I just wanna show Appendix A in my TOC and left the tile blank, like \section{}. Mar 6 '17 at 17:36
  • @Mico An idea comes to my mind. I remove A and put Appendix A into \section{}. Mar 6 '17 at 17:38
  • \appendix\section*{Appendix}\addcontentsline{toc}{section}{Appendix} But that isn't a very good thing to do.
    – Johannes_B
    Mar 6 '17 at 17:39
5

Add the following to your preamble:

\newcommand{\appendixnumberline}[1]{Appendix\space}

\let\oldappendix\appendix
\makeatletter
\renewcommand{\appendix}{%
  \addtocontents{toc}{\let\protect\numberline\protect\appendixnumberline}%
  \renewcommand{\@seccntformat}[1]{Appendix~\csname the##1\endcsname\quad}%
  \oldappendix
}
\makeatother

The above replaces the \numberline macro with a new \appendixnumberline while also updating the way sectional unit counter are formatted when setting the section title. All is included at the start of the \appendix as a form of automation.

enter image description here

If you also use \subsection (and lower) within the appendix, some more work needs to be done to exclude their sectional units from also being prepended with Appendix.

1

I would like to suggest you take a different approach: Instead of overloading any given line in the table of contents, consider inserting a line saying something like "Appendix material" in the ToC right before the first appendix section.

enter image description here

\documentclass[twoside,12pt]{article}
\usepackage[colorlinks,allcolors=blue,linktocpage]{hyperref}
\usepackage[nameinlink]{cleveref} % make \cref look like \autoref

%% Set up some preparatory code -- activated below
%% (see 'The LaTeX Companion,' 2nd. ed., pp. 26f.)
\makeatletter
\def\@seccntformat#1{\@ifundefined{#1@cntformat}%
   {\csname the#1\endcsname\quad}%   default
   {\csname #1@cntformat\endcsname}% enable individual control
}
\makeatother

\begin{document}

\tableofcontents

\bigskip\hrule % just for this example

\section{Uno}
Refer to \Cref{app:a,app:b} for more information.
\section{Due}
More text.
\section{Tre}
Still more text.

\appendix
\addtocontents{toc}{\bigskip\medskip\noindent%
  \textbf{Appendix Material}\par}
% Activate preparatory code for section-level headers
\makeatletter 
\newcommand{\section@cntformat}{Appendix \thesection\quad}
\makeatother

\section{A complete table.} \label{app:a}
Some text.

\section{Another complete table.} \label{app:b}
Other text.

\end{document}

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.