Cross-Referencing Appendices – Reference Appendix Objects as ‘A.1’

appendicescross-referencingnumbering

Consider a document using elsearticle package, and involving an appendix:

\documentclass{elsarticle}

\begin{document}

... briefly explained in~\ref{sec:subAppendix}

\appendix
\section{Appendix}
\subsection{Sub-appendix}
\label{sec:subAppendix}

\end{document}

When one refers this appendix object within the text:

... briefly explained in~\ref{sec:subAppendix}.

The number assigned to the object is printed with a word 'Appendix' as follows:

... briefly explained in Appendix A.1.

How can we suppress/remove the word 'Appendix', and make the appendix object appears like in the following?:

... briefly explained in A.1.

Best Answer

elsarticle defines \thesection as \appendixname \Alph{section} within \appendix -- as such, \thesubsection expands to \appendix \Alph{section}.\arabic{subsection}, finally being Appendix A.1 etc.

While this might alright for the typesetting, the references might become tedious and lengthy.

Redefinition of \p@subsection by gobbling the content first and re-injection of the pure \Alph{section}.\arabic{subsection} will remove this for the references.

See https://tex.stackexchange.com/a/397724/31729 for a similar approach.

Another possibility is to refine \thesection for the appendix.

\documentclass{elsarticle}

\makeatletter
\def\@gobbleappendixname#1\csname thesubsection\endcsname{\Alph{section}.\arabic{subsection}}
\renewcommand{\p@subsection}{\@gobbleappendixname}
\makeatother

\begin{document}



... briefly explained in~\ref{sec:subAppendix}

\appendix
\section{Appendix}

\subsection{Sub-appendix} 

\label{sec:subAppendix}

\end{document}

enter image description here

Regarding the complaints of the OP:

\documentclass{elsarticle}


\makeatletter
\def\@gobbleappendixname#1\csname thesubsection\endcsname{\Alph{section}.\arabic{subsection}}
\g@addto@macro{\appendix}{\renewcommand{\p@subsection}{\@gobbleappendixname}}
\makeatother



\begin{document}

\section{Foo} \label{firstsection}

\subsection{Foo subsection} \label{foosubsection}

... briefly explained in~\ref{sec:subAppendix} or in \ref{firstsection} or in \ref{firstappendixsection} or in \ref{foosubsection}

\appendix




\section{Appendix} \label{firstappendixsection}

\subsection{Sub-appendix} 

\label{sec:subAppendix}

\end{document}