[Tex/LaTex] Having ‘Appendix A’ instead of ‘A Appendix’

appendiceslncsnumbering

I would like to have my appendices labelled 'Appendix A', 'Appendix B', etc. However, when I use appendices in LaTeX (specifically llncs document class, downloadable at ftp://ftp.springernature.com/cs-proceeding/llncs/llncs2e.zip), I instead get ''A Appendix', 'B Appendix' and so on. Is there any way to change that?

More specifically, this is my minimal working example:

\documentclass[envcountsame]{llncs}

\begin{document}
\appendix
\section{Appendix: Foo Bar} %I want this to appear as 'Appendix A: Foo Bar'
\end{document}

Best Answer

Here's a solution that uses only low-level LaTeX macros. (Copy the material starting with \makeatletter and ending with \makeatother to your document's preamble.) The example below employs the llncs document class, but works equally well with the article document class.

The trick, such as it is, consists of telling LaTeX to prefix the String "Appendix" to the section "number" when in a section header but not when cross-references to, say, "appendices A, B, and D" are needed.

If you want the appendix section header to read just "Appendix [some letter]" without a descriptive string, you can do so by typing \section{} or \section{\null} -- after having executed \appendix, naturally.

enter image description here

\documentclass{llncs}

\makeatletter
%% The "\@seccntformat" command is an auxiliary command
%% (see pp. 26f. of 'The LaTeX Companion,' 2nd. ed.)
\def\@seccntformat#1{\@ifundefined{#1@cntformat}%
   {\csname the#1\endcsname\quad}  % default
   {\csname #1@cntformat\endcsname}% enable individual control
}
\let\oldappendix\appendix %% save current definition of \appendix
\renewcommand\appendix{%
    \oldappendix
    \newcommand{\section@cntformat}{\appendixname~\thesection\quad}
}
\makeatother
\usepackage{cleveref} % just for this example
\begin{document}

\section{Hello}

As we will show in \cref{app:a,app:b,app:d}, \dots

\appendix %% appendices 
\section{Postfix 1} \label{app:a}
\section{Postfix 2} \label{app:b}
\section{Postfix 3} \label{app:c}
\section{Postfix 4} \label{app:d}
\end{document}