[Tex/LaTex] Cross reference to Appendix doesn’t work (showing Section)

appendicescross-referencing

I followed How to refer Appendix in a paper? and tried to refer to an appendix in the main body of the text, but it shows Section 1 instead of Appendix A. Here is the source code.

\documentclass[twoside,12pt]{article}

\usepackage{cleveref}

\begin{document}

Refer to \cref{appendix} for more information.

\section{Conclusion}
Draw conclusions here.

\appendix
\section*{Appendix A} \label{appendix}
Some text.

\end{document} 

How do I display the reference text as Appendix A?

Best Answer

Here's a way to refer to starred sections (for the appendix, however!)

Redefine \section to step a counter for the starred version as well -- this can be fed to cleveref with appropiate cref-names.

Alternatively, the command \nameref from hyperref package is clever enough itself to provide the correct name even for starred sections.

Best, don't use starred sections here, this will remove the necessity of numbering them by hand.

\documentclass[twoside,12pt]{article}

\usepackage{xparse}
\usepackage{hyperref}
\usepackage{cleveref}

\newcounter{starredsection}%

\makeatletter
\let\latex@@section\section

\AtBeginDocument{%
  \RenewDocumentCommand{\section}{som}{%
    \IfBooleanTF{#1}{%
      \refstepcounter{starredsection}%
      \latex@@section*{#3}%
    }{%
      \IfValueTF{#2}{%
        \latex@@section[#2]{#3}%
      }{%
        \latex@@section{#3}%
      }%
    }%
  }%
}
\makeatother


\crefname{starredsection}{appendix}{appendices}
\Crefname{starredsection}{Appendix}{Appendices}


\begin{document}

Refer to \cref*{appendix} or \nameref*{appendixother} for more information.

\section{Conclusion}
Draw conclusions here.

\appendix
\section*{Appendix A} \label{appendix}

\section*{Appendix B} \label{appendixother}

Some text.

\end{document} 

enter image description here