# Cross-reference to appendix sections in elsarticle document class

I am trying to reference a result given in the appendix, but cleveref is giving "Appendix Appendix" (doubling it). A way to solve this problem is to add \def\appendixname{}

Not surprisingly, this also eliminates the name "Appendix" from the section title. How can I solve the problem while still keeping "Appendix" in the section title?

MWE:

main.tex

\documentclass[final,times,letterpaper,authoryear,12pt]{elsarticle}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{indentfirst}
\usepackage{amscd}
\usepackage{mathrsfs}
\usepackage{ulem}
\usepackage{bbm}
\usepackage{hyperref}
\usepackage{tikz}
\usetikzlibrary{calc}
\usepackage{setspace}
\usepackage{color}

\usepackage{subfiles}
\usepackage{graphicx}
\usepackage{lmodern}
\usepackage{kpfonts}
\usepackage{etex,etoolbox}
\usepackage{amsthm,amssymb}
\usepackage{thmtools}
\usepackage{environ}
\crefname{lem}{lemma}{lemmas}
\crefname{prop}{Proposition}{Propositions}
\crefname{thr}{Theorem}{Theorems}
\crefname{cor}{Corollary}{Corollaries}
\crefname{ass}{Assumption}{Assumptions}
\crefname{df}{Definiton}{Definitons}
\usepackage{enumitem}
\usepackage{caption}
\usepackage{subcaption}
\usepackage[letterpaper,layout=letterpaper]{geometry}

\begin{document}

\subfile{testa}
\appendix
\subfile{appendix}
\subfile{appendixb}

\end{document}


testa.tex

\documentclass[main.tex]{subfiles}
\begin{document}

\section{Introduction}
This is an introduction. From now on we will hold Result A and B as true. We prove Result A in \Cref{regsol} and we prove Result B in \Cref{regsolB}.


appendix.tex

\documentclass[main.tex]{subfiles}
\def\appendixname{}

\begin{document}

\section{Proof of Result A}\label{regsol}
We show that...

\end{document}


appendixb.tex

\documentclass[main.tex]{subfiles}
\begin{document}

\section{Proof of Result B}\label{regsolB}
We show that...

\end{document}
\end{document}


The elsarticle document class redefines the \thesection macro in a quick and unfortunately rather dirty way when \appendix is executed:

\gdef\thesection{\appendixname\@Alph\c@section}%


This prefixes word "Appendix" to the (alpha-stye) section "number" (A, B, C, etc.) That's what's causing the cross-reference call-outs generated by cleveref to contain the string "Appendix" twice.

A quick fix would consist of using the instruction \creflabel instead of \cref when making cross-references to sections located in the appendix part of the document.

A more elaborate fix, i.e., one which lets you continue to use \Cref, involve would inserting the following code block immediately after the \appendix instruction:

\gdef\thesection{\Alph{section}} % corrected redefinition of "\thesection"
\makeatletter
\renewcommand\@seccntformat[1]{Appendix \csname the#1\endcsname.\hspace{0.5em}}
\makeatother


A separate comment: The preamble of your document is, to put it delicately, not organized all that well. For instance, you provide the option times to the \documentclass instruction; this option tells LaTeX to load the "Times Roman" font. Later, you load the lmodern font package, which loads the "Latin Modern" font family, followed by a loading of the kpfonts font package, which loads a clone of the "Palatino" font family. Which font family do you want? You may want to go through the preamble and determine which packages are really needed.

Here's an MWE that illustrates the workings of the "more elaborate fix" shown above. (Note that I've simplified the preamble and the body of the document in order to focus on the essentials.)

\documentclass[letterpaper,12pt]{elsarticle}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{geometry}

\begin{document}

\section{Introduction}

We prove Result A in \Cref{regsol} and we prove Result B in \Cref{regsolB}.

\appendix
%% now insert the new code block
\gdef\thesection{\Alph{section}}
\makeatletter
\renewcommand\@seccntformat[1]{Appendix \csname the#1\endcsname.\hspace{0.5em}}
\makeatother

\section{Proof of Result A}\label{regsol}
We show that \dots

\section{Proof of Result B}\label{regsolB}
We show that \dots

\end{document}

• Could you spot any other inconsistency/problem besides the fonts? – capadocia Jun 5 '15 at 14:38
• @capadocia - For sure, don't load a package twice -- see amssymb -- and do make an effort to load the hyperref and cleveref packages last. Since I don't know anything about the contents your document, I'm not in a position to judge whether the other packages you load are really needed. I somehow doubt, though, that all of them are needed. That's why I suggested you go through the preamble and test the need of each package. – Mico Jun 5 '15 at 14:50