9

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}
7
  • Just as a note: not everyone will have llncs installed. It would be better to make this a compilable example (using the article class, for example). The solution that works for article will likely work for llncs. That said, intentionally deviating from the style of a journal doesn't exactly make the publisher giggle with joy; the style exists for a reason. Feb 17, 2014 at 3:39
  • I use llncs as a general format, but I understand what you mean. Changing my minimum working example to reflect this.
    – Koz Ross
    Feb 17, 2014 at 3:43
  • I my opinion, it is better to use a chapter as appendix and rename \chaptername. Then use sections as the several parts of appendix -- I also agree with Sean Allred's statement about llncs.
    – user31729
    Feb 17, 2014 at 3:44
  • I withdraw my statement about appendix as chapter -- it is not necessary.
    – user31729
    Feb 17, 2014 at 4:08
  • @SeanAllred You're wrong. llncs class is quite unique, so what works for article might not work for llncs. Feb 17, 2014 at 6:33

2 Answers 2

10

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}
1
  • A follow-up comment: This answer employs the the llncs document class, because that's what the OP was using. This answer works just as well with other document classes, notably the article class.
    – Mico
    May 20, 2020 at 4:02
4

I am actually not answering this question but the question Show Appendix Number/Counter After Appendix Title which was closed due to similarity with this question while I was about to submit my answer.

The closed question is about article.cls.
This question is about llncs.cls which seems to be based on article.cls.

So my answer to the closed question probably is useful for this question, too.

If it is not, blame the vote-for-closing-fetishists. ;-)


With sectioning-commands (no matter whether they appear in the frontmatter or in the mainmatter or in the backmatter/appendix) you usually provide a title. In case you wish to provide titles with sections that occur in the appendix, I can offer this:

\documentclass[12pt]{article}
% \let\savedcontentsline=\contentsline
\usepackage[bookmarksnumbered, colorlinks]{hyperref}
\pagestyle{headings}

\makeatletter
\@ifundefined{texorpdfstring}{\let\texorpdfstring\@firstoftwo}{}
\@ifundefined{hyper@makecurrent}{}{%
  \usepackage{xpatch}%
  \newcommand*\Hy@subsectionstring{subsection}%
  \newcommand*\Hy@subsubsectionstring{subsubsection}%
  \newcommand*\Hy@subsecapp{subsection}%
  \newcommand*\Hy@subsubsecapp{subsubsection}%
  \xpatchcmd{\hyper@makecurrent}{%
    \ifx\Hy@param\Hy@chapterstring\let\Hy@param\Hy@chapapp\fi
  }{%
    \ifx\Hy@param\Hy@chapterstring\let\Hy@param\Hy@chapapp\fi
    \ifx\Hy@param\Hy@subsectionstring\let\Hy@param\Hy@subsecapp\fi
    \ifx\Hy@param\Hy@subsubsectionstring\let\Hy@param\Hy@subsubsecapp\fi
%    \show\Hy@param
  }{%
    \@latex@info{Command \string\hyper@makecurrent patched successfully}%
    \message{Command \string\hyper@makecurrent patched successfully\on@line}%
  }{%
    \@latex@error{Command \string\hyper@makecurrent not patched successfully}%
                 {You're in trouble here.}%
  }%
}%
\newcommand\labelfork[2]{%
  \ifx\thepage\relax\expandafter\@firstoftwo\else\expandafter\@secondoftwo\fi{#1}{#2}%
}%
\newcommand\appendix@l@section[2]{%
  \ifnum\c@tocdepth >\z@ 
    \addpenalty\@secpenalty
    \addvspace{1.0em \@plus\p@}%
    \setlength\@tempdima{\appendixtocwidth}%
    \begingroup
    \parindent\z@
    \rightskip\@pnumwidth
    \parfillskip-\@pnumwidth
    \leavevmode
    \bfseries
    \advance\leftskip\@tempdima
    \hskip-\leftskip
    #1%
    \nobreak\hfil
    \nobreak\hb@xt@\@pnumwidth{\hss#2\kern-\p@\kern\p@}\par
    \endgroup
  \fi 
}%
\newcommand\appendix@l@subsection{%
 %\@dottedtocline {2}{1.5em}{2.3em}
 \@dottedtocline{2}{1.5em}{\dimexpr0.8em+\appendixtocwidth\relax}%
}%
\newcommand\appendix@l@subsubsection{%
 %\@dottedtocline {3}{3.8em}{3.2em}
 \@dottedtocline{3}{3.8em}{\dimexpr1.7em+\appendixtocwidth\relax}%
}%
\newcommand\appendixlatsections{%
  \let\l@section=\appendix@l@section
  \let\l@subsection=\appendix@l@subsection
  \let\l@subsubsection=\appendix@l@subsubsection
}%
\newcommand\doappendixstuff{%
  \renewcommand\thesection{%
    \texorpdfstring{\noexpand\labelfork{}{\appendixname\protect~}}{\appendixname\space}%
    \@Alph\c@section
    \texorpdfstring{\noexpand\labelfork{}{:}}{:}%
  }%
  \renewcommand\thesubsection{%
    \texorpdfstring{\noexpand\labelfork{}{\appendixname\protect~}}{\appendixname\space}%
    \@Alph\c@section.\number\value{subsection}%
    \texorpdfstring{\noexpand\labelfork{}{:}}{:}%
  }%
  \renewcommand\thesubsubsection{%
    \texorpdfstring{\noexpand\labelfork{}{\appendixname\protect~}}{\appendixname\space}%
    \@Alph\c@section.\number\value{subsection}.\number\value{subsubsection}%
    \texorpdfstring{\noexpand\labelfork{}{:}}{:}%
  }%
  \let\Hy@subsecapp\Hy@appendixstring
  \let\Hy@subsubsecapp\Hy@appendixstring
  \begingroup
  \bfseries
  \settowidth\@tempdima{\appendixname~A:~}%
  \addtocontents{toc}{\string\def\string\appendixtocwidth{\the\@tempdima}}%
  \addtocontents{toc}{\string\appendixlatsections}%
  \endgroup
  % \addtocontents{toc}{\protect\savedcontentsline{section}{{\large Appendices}}{}\protected@file@percent}%
}%
\makeatother

\begin{document}

\tableofcontents

\section{Introduction}
\subsection{Intro's subsection}
\subsubsection{Intro's subsubsection}

I would like to reference the appendix with A,B,C as this Appendix: \ref{ap:a}, but in the appendix in the finish of the page I want the letter A after the word Appendix just one time.

\subsection{Referencing}

\noindent\verb|\ref{ap:a}|: \ref{ap:a}

\noindent\verb|\ref{ap:a.1}|: \ref{ap:a.1}

\noindent\verb|\ref{ap:a.1.1}|: \ref{ap:a.1.1}

\noindent\verb|\ref{ap:b}|: \ref{ap:b}

\noindent\verb|\ref{ap:c}|: \ref{ap:c}

\noindent\verb|\nameref{ap:a}|: \nameref{ap:a}

\noindent\verb|\nameref{ap:a.1}|: \nameref{ap:a.1}

\noindent\verb|\nameref{ap:a.1.1}|: \nameref{ap:a.1.1}

\noindent\verb|\nameref{ap:b}|: \nameref{ap:b}

\noindent\verb|\nameref{ap:c}|: \nameref{ap:c}

\noindent\verb|\autoref{ap:a}|: \autoref{ap:a}

\noindent\verb|\autoref{ap:a.1}|: \autoref{ap:a.1}

\noindent\verb|\autoref{ap:a.1.1}|: \autoref{ap:a.1.1}

\noindent\verb|\autoref{ap:b}|: \autoref{ap:b}

\noindent\verb|\autoref{ap:c}|: \autoref{ap:c}

\noindent\verb|\hyperref[ap:a]{\autoref*{ap:a}: \nameref*{ap:a}}|:\\ \hyperref[ap:a]{\autoref*{ap:a}: \nameref*{ap:a}}

\noindent\verb|\hyperref[ap:a.1]{\autoref*{ap:a.1}: \nameref*{ap:a.1}}|:\\ \hyperref[ap:a.1]{\autoref*{ap:a.1}: \nameref*{ap:a.1}}

\noindent\verb|\hyperref[ap:a.1.1]{\autoref*{ap:a.1.1}: \nameref*{ap:a.1.1}}|:\\ \hyperref[ap:a.1.1]{\autoref*{ap:a.1.1}: \nameref*{ap:a.1.1}}

\noindent\verb|\hyperref[ap:b]{\autoref*{ap:b}: \nameref*{ap:b}}|:\\ \hyperref[ap:b]{\autoref*{ap:b}: \nameref*{ap:b}}

\noindent\verb|\hyperref[ap:c]{\autoref*{ap:c}: \nameref*{ap:c}}|:\\ \hyperref[ap:c]{\autoref*{ap:c}: \nameref*{ap:c}}

\newpage

\appendix
\doappendixstuff

\section{First appendix}
\label{ap:a}

\subsection{First appendix's first sub-appendix}
\label{ap:a.1}

\subsubsection{First appendix's first sub-appendix's first subsub-appendix}
\label{ap:a.1.1}

\subsection{First appendix's second sub-appendix}

\section{Second appendix}
\label{ap:b}

\section{Third appendix}
\label{ap:c}

\end{document}

enter image description here

enter image description here

enter image description here

In case you wish not to provide titles with sections that occur in the appendix, I can offer this:

\documentclass[12pt]{article}
% \let\savedcontentsline=\contentsline
\usepackage[bookmarksnumbered, colorlinks]{hyperref}
\pagestyle{headings}

\makeatletter
\@ifundefined{texorpdfstring}{\let\texorpdfstring\@firstoftwo}{}
\@ifundefined{hyper@makecurrent}{}{%
  \usepackage{xpatch}%
  \newcommand*\Hy@subsectionstring{subsection}%
  \newcommand*\Hy@subsubsectionstring{subsubsection}%
  \newcommand*\Hy@subsecapp{subsection}%
  \newcommand*\Hy@subsubsecapp{subsubsection}%
  \xpatchcmd{\hyper@makecurrent}{%
    \ifx\Hy@param\Hy@chapterstring\let\Hy@param\Hy@chapapp\fi
  }{%
    \ifx\Hy@param\Hy@chapterstring\let\Hy@param\Hy@chapapp\fi
    \ifx\Hy@param\Hy@subsectionstring\let\Hy@param\Hy@subsecapp\fi
    \ifx\Hy@param\Hy@subsubsectionstring\let\Hy@param\Hy@subsubsecapp\fi
%    \show\Hy@param
  }{%
    \@latex@info{Command \string\hyper@makecurrent patched successfully}%
    \message{Command \string\hyper@makecurrent patched successfully\on@line}%
  }{%
    \@latex@error{Command \string\hyper@makecurrent not patched successfully}%
                 {You're in trouble here.}%
  }%
}%
\newcommand\labelfork[2]{%
  \ifx\thepage\relax\expandafter\@firstoftwo\else\expandafter\@secondoftwo\fi{#1}{#2}%
}%
\newcommand\appendix@l@section[2]{%
  \ifnum\c@tocdepth >\z@ 
    \addpenalty\@secpenalty
    \addvspace{1.0em \@plus\p@}%
    \setlength\@tempdima{\appendixtocwidth}%
    \begingroup
    \parindent\z@
    \rightskip\@pnumwidth
    \parfillskip-\@pnumwidth
    \leavevmode
    \bfseries
    \advance\leftskip\@tempdima
    \hskip-\leftskip
    #1%
    \nobreak\hfil
    \nobreak\hb@xt@\@pnumwidth{\hss#2\kern-\p@\kern\p@}\par
    \endgroup
  \fi 
}%
\newcommand\appendix@l@subsection{%
 %\@dottedtocline {2}{1.5em}{2.3em}
 \@dottedtocline{2}{1.5em}{\dimexpr0.8em+\appendixtocwidth\relax}%
}%
\newcommand\appendix@l@subsubsection{%
 %\@dottedtocline {3}{3.8em}{3.2em}
 \@dottedtocline{3}{3.8em}{\dimexpr1.7em+\appendixtocwidth\relax}%
}%
\newcommand\appendixlatsections{%
  \let\l@section=\appendix@l@section
  \let\l@subsection=\appendix@l@subsection
  \let\l@subsubsection=\appendix@l@subsubsection
}%
\newcommand\doappendixstuff{%
  \renewcommand\thesection{%
    \texorpdfstring{\noexpand\labelfork{}{\appendixname\protect~}}{\appendixname\space}%
    \@Alph\c@section
  }%
  \renewcommand\thesubsection{%
    \texorpdfstring{\noexpand\labelfork{}{\appendixname\protect~}}{\appendixname\space}%
    \@Alph\c@section.\number\value{subsection}%
  }%
  \renewcommand\thesubsubsection{%
    \texorpdfstring{\noexpand\labelfork{}{\appendixname\protect~}}{\appendixname\space}%
    \@Alph\c@section.\number\value{subsection}.\number\value{subsubsection}%
  }%
  \newcommand\savedsection{}%
  \newcommand\savedsubsection{}%
  \newcommand\savedsubsubsection{}%
  \let\savedsection=\section
  \let\savedsubsection=\subsection
  \let\savedsubsubsection=\subsubsection
  \renewcommand*\section{\savedsection{}\protected@edef\@currentlabelname{\thesection}}%
  \renewcommand*\subsection{\savedsubsection{}\protected@edef\@currentlabelname{\thesubsection}}%
  \renewcommand*\subsubsection{\savedsubsubsection{}\protected@edef\@currentlabelname{\thesubsubsection}}%
  \let\Hy@subsecapp\Hy@appendixstring
  \let\Hy@subsubsecapp\Hy@appendixstring
  \begingroup
  \bfseries
  \settowidth\@tempdima{\appendixname~A}%
  \addtocontents{toc}{\string\def\string\appendixtocwidth{\the\@tempdima}}%
  \addtocontents{toc}{\string\appendixlatsections}%
  \endgroup
  % \addtocontents{toc}{\protect\savedcontentsline{section}{{\large Appendices}}{}\protected@file@percent}%
}%
\makeatother

\begin{document}

\tableofcontents

\section{Introduction}
\subsection{Intro's subsection}
\subsubsection{Intro's subsubsection}

I would like to reference the appendix with A,B,C as this Appendix: \ref{ap:a}, but in the appendix in the finish of the page I want the letter A after the word Appendix just one time.

\subsection{Referencing}

\noindent\verb|\ref{ap:a}|: \ref{ap:a}

\noindent\verb|\ref{ap:a.1}|: \ref{ap:a.1}

\noindent\verb|\ref{ap:a.1.1}|: \ref{ap:a.1.1}

\noindent\verb|\ref{ap:b}|: \ref{ap:b}

\noindent\verb|\ref{ap:c}|: \ref{ap:c}

\noindent\verb|\nameref{ap:a}|: \nameref{ap:a}

\noindent\verb|\nameref{ap:a.1}|: \nameref{ap:a.1}

\noindent\verb|\nameref{ap:a.1.1}|: \nameref{ap:a.1.1}

\noindent\verb|\nameref{ap:b}|: \nameref{ap:b}

\noindent\verb|\nameref{ap:c}|: \nameref{ap:c}

\noindent\verb|\autoref{ap:a}|: \autoref{ap:a}

\noindent\verb|\autoref{ap:a.1}|: \autoref{ap:a.1}

\noindent\verb|\autoref{ap:a.1.1}|: \autoref{ap:a.1.1}

\noindent\verb|\autoref{ap:b}|: \autoref{ap:b}

\noindent\verb|\autoref{ap:c}|: \autoref{ap:c}

\newpage

\appendix
\doappendixstuff

\section
\label{ap:a}

\subsection
\label{ap:a.1}

\subsubsection
\label{ap:a.1.1}

\subsection

\section
\label{ap:b}

\section
\label{ap:c}

\end{document}

enter image description here

enter image description here

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .