Page LayoutDisplay "Appendix" before "A" in toc

Information and discussion about page layout specific issues (e.g. header and footer lines, page formats, page numbers).
Post Reply
latex101
Posts: 3
Joined: Wed May 19, 2010 12:05 pm

Display "Appendix" before "A" in toc

Post by latex101 »

Hi,

I am using the article class and want to name my appendices
Appendix A Theory
A.1 One theory
A.2 Another theory
etc.

I want this to be displayed both in the table of contents and in the text itself. I found this code on the web

Code: Select all

\appendix
\makeatletter
\def\@seccntformat#1{\csname Pref@#1\endcsname \csname the#1\endcsname\quad}
\def\Pref@section{Appendix~}
\makeatother
\include{appendix_a}
which displays my appendix titles the way I want them in the text, but the table of contents still say

A Theory
A.1 One theory

How do I get the word "Appendix" to be displayed before "A Theory" in the table of contents?

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

gmedina
Posts: 2313
Joined: Wed Jul 11, 2007 11:45 pm

Display "Appendix" before "A" in toc

Post by gmedina »

Hi,

you can use the features implemented by the appendix package; a little example:

Code: Select all

\documentclass{article}
\usepackage{appendix}

\begin{document} 
\tableofcontents

\appendixtitleon
\appendixtitletocon
\begin{appendices}
\section{First appendix}
\subsection{First}
\subsection{Second}
\section{Second appendix}
\subsection{First}
\subsection{Second}
\end{appendices}

\end{document}
1,1,2,3,5,8,13,21,34,55,89,144,233,...
latex101
Posts: 3
Joined: Wed May 19, 2010 12:05 pm

Re: Display "Appendix" before "A" in toc

Post by latex101 »

Thank you, that fixed it!

While we're at it.. is it possible to get the words "Figure" and "Table" to be displayed in the table of contents, in the article class?
Now it says:
List of figures
1.1 A figure
1.2 Another figure

and I want it to say
List of figures
Figure 1.1 A figure
Figure 1.2 Another figure

The same goes for tables.
User avatar
gmedina
Posts: 2313
Joined: Wed Jul 11, 2007 11:45 pm

Display "Appendix" before "A" in toc

Post by gmedina »

Add the following lines to the preamble (change the lengths according to your needs):

Code: Select all

\usepackage{tocloft}

\addtolength{\cftfignumwidth}{1cm} 
\renewcommand{\cftfigpresnum}{Figure }
\addtolength{\cfttabnumwidth}{1cm} 
\renewcommand{\cfttabpresnum}{Table }
1,1,2,3,5,8,13,21,34,55,89,144,233,...
latex101
Posts: 3
Joined: Wed May 19, 2010 12:05 pm

Display "Appendix" before "A" in toc

Post by latex101 »

Thanks again, you're a genious!

Just wondering: Why does it only work if

Code: Select all

\usepackage{tocloft}
is placed directly under

Code: Select all

\documentclass[a4paper, english, 12pt]{article}
.

If I have declare my other packages first

Code: Select all

\documentclass[a4paper, english, 12pt]{article}

\usepackage{babel, fancyhdr, amsmath, amsfonts, amssymb, graphicx, float, enumerate, hyperref, subfig, pdfpages, appendix}

\usepackage{tocloft}
I get an error message that says
"Package tocloft Note: The document has section divisions.

! Latex Error: Command \c@lofdepth already defined."
User avatar
gmedina
Posts: 2313
Joined: Wed Jul 11, 2007 11:45 pm

Display "Appendix" before "A" in toc

Post by gmedina »

The problem is due to the fact that the subfig package defines the lofdepth and lotdepth counters so you must either load tocloft before subfig or load tocloft with the subfigure option (i.e., \usepackage[subfigure]{tocloft} )to avoid conflicts.
1,1,2,3,5,8,13,21,34,55,89,144,233,...
Post Reply