我希望将附录标记为“附录 A”、“附录 B”等。但是,当我在 LaTeX 中使用附录时(特别是llncs
文档类,可从以下网址下载)ftp://ftp.springernature.com/cs-proceeding/llncs/llncs2e.zip),我得到的却是“附录 A”、“附录 B”等等。有什么办法可以改变这种情况吗?
更具体地说,这是我的最小工作示例:
\documentclass[envcountsame]{llncs}
\begin{document}
\appendix
\section{Appendix: Foo Bar} %I want this to appear as 'Appendix A: Foo Bar'
\end{document}
答案1
这是一个仅使用低级 LaTeX 宏的解决方案。(将以 开头\makeatletter
和以 结尾的材料复制\makeatother
到文档的序言中。)下面的示例使用了llncs
document 类,但与 document 类配合使用效果同样好article
。
这个技巧就是告诉 LaTeX 将字符串“Appendix”添加到“number”部分的前缀中当在节标题中时但当需要交叉引用“附录 A、B 和 D”时则不然。
如果您希望附录部分标题仅显示“附录 [某封信件]”没有描述性字符串,您可以在执行 之后通过输入\section{}
或--来实现。\section{\null}
\appendix
\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}
答案2
我其实不是在回答这个问题,而是在回答这个问题在附录标题后显示附录编号/计数器当我正要提交答案时,由于与该问题相似,该帖子被关闭了。
封闭式问题是关于article.cls
。
这个问题是关于llncs.cls
,似乎是基于article.cls
。
所以我对封闭式问题的回答可能也对这个问题有用。
如果不是,那就怪那些投票关闭癖者吧。;-)
使用分节命令(无论它们出现在前言、正文还是后记/附录中)通常都会提供一个标题。如果您希望为附录中的章节提供标题,我可以提供以下建议:
\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}
如果您不想提供附录中出现的部分的标题,我可以提供以下内容:
\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}