3

Say I have

\begin{theorem}\label{thm:Fermat}
This is a theorem about Fermat.
\end{theorem}

and the output is Theorem 5.2. This is a theorem about Fermat.

Now I want to reference it by \ref{thm:Fermat}, but this only returns 5.2 and not Theorem 5.2. What can I do to make it return Theorem 5.2 ?

I found the ntheorem package with \thref, but using the ntheorem package my theorem-sytles do not seem to work anymore (i.e. I would have to rewrite all of them). Could I circumvent this issue somehow? But perhaps there is an easier solution? A potentially small example would be very much appreciated.

Phil-ZXX
  • 1,747

2 Answers2

6

If you only need theorem referencing (and no figure, table, listing etc.), you can use the theoremref package. The latest version on CTAN is already compatible with hyperref.

\documentclass{article}
\usepackage{amsthm, theoremref, hyperref}
\newtheorem{theorem}{Theorem}
\begin{document}
\begin{theorem}\thlabel{thm:Fermat}
This is a theorem about Fermat.
\end{theorem}
\thref{thm:Fermat} is very good.
\end{document}

Another option is the \autoref command from hyperref. For more flexible solutions, see Cross-reference packages: which to use, which conflict?.

marczellm
  • 11,809
5

I would use the cleveref package for this, as you can use the regular \label command and customize the appearance of the reference very easily using \crefname and friends.

You might like the reference to appear differently when referencing the theorem at the beginning of the sentence, or midway through a sentence- cleveref allows for this easily.

screenshot

Here's a complete MWE

% arara: pdflatex
% !arara: indent: {overwrite: on}
\documentclass{article}
\usepackage{amsthm}
\usepackage{hyperref}
\usepackage{cleveref}

\newtheorem{theorem}{Theorem}
% each of the following has two versions
%   \crefname{environmentname}{singular}{plural}, to be used mid-sentence
%   \Crefname{environmentname}{singular}{plural}, to be used at the beginning of a sentence
\crefname{theorem}{theorem}{theorems}
\Crefname{theorem}{Theorem}{Theorems}

\begin{document}
\begin{theorem}\label{thm:Fermat}
    This is a theorem about Fermat.
\end{theorem}
\begin{itemize}
    \item \Cref{thm:Fermat} is very good.
    \item And also \cref{thm:Fermat} is very good.
\end{itemize}
\end{document}
cmhughes
  • 100,947