[Tex/LaTex] Appendix reference numbers and titles

appendiceschapterscross-referencingnumbering

My issue is related to adding the Appendix using \chapter. I am defining Appendix as follows:

\chapter{My Appendix Title} % Main appendix title
\label{AppendixTemplate} 
% My Appendix content here. 

Calling it in the main.tex using

\appendix
\input{Appendices/Appendix/AppendixTemplate}

Referring it in any other chapter like

the system is further detailed in Appendix~\ref{app:AppendixTemplate}

Now Questions:

  1. the TOC only shows, "My Appendix Title" without Appendix A. I want it to be like "Appendix A. My Appendix Title".

  2. In another chapter, where it is cited it output is "the system I further detailed in Appendix 1." It should be "the system I further detailed in Appendix A."

Best Answer

The following MWE works for a book.

\documentclass{book} 
\usepackage{lipsum} % to generate filler text
\usepackage{tocloft}
\setlength\cftsecnumwidth{72pt} % adds space for the word Appendix
 \renewcommand{\cftsecaftersnum}{.} % if you want a period (or whatever punctuation after the appendix letter

\begin{document}
\tableofcontents

% \mainmatter % removed to shorten the example image
\section{Section Title} 
\lipsum[1]

\appendix
\gdef\thesection{Appendix \Alph{section}}
\section{foo} 
\lipsum[1]

\gdef\thesection{Appendix \Alph{section}}
\section{foo2}
\lipsum[1]

\end{document}

table_of_contents_example