5

In my tex document I have 3 environments for Definition, Theorem and Lemma.

The numbering of them should be continuous as follows:

Definition 1.1
Theorem 1.2
Lemma 1.3
Definition 1.4
...

I got it by the following:

\newtheorem{defn}{Definition}[chapter]
\newtheorem{theorem}[defn]{Theorem}
\newtheorem{lemma}[defn]{Lemma}

\def\defnautorefname{Def.}
\def\theoremautorefname{Thm.}
\def\lemmaautorefname{Lem.}

So far so good. Then I want to make reference to each of them using \autoref, for instance:

\autoref{defn:1}    
\autoref{theorem:1}    
\autoref{lemma:1}

But what I obtain is only:

Def. 1.1
Def. 1.2
Def. 1.3

and NOT as I would like to have:

Def. 1.1
Thm. 1.2
Lem. 1.3

My full code:

\documentclass[a4paper,11pt]{report}

\usepackage[english]{babel}
\usepackage[T1]{fontenc}
\usepackage{ucs}
\usepackage[utf8x]{inputenc}


\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{amssymb}
\usepackage{hyperref}

\newtheorem{defn}{Definition}[chapter]
\newtheorem{theorem}[defn]{Theorem}
\newtheorem{lemma}[defn]{Lemma}


\def\defnautorefname{Def.}
\def\theoremautorefname{Thm.}
\def\lemmaautorefname{Lem.}


\parindent0pt


\begin{document}

\chapter{Chapter 1}

\begin{defn}
 \label{defn:1}
 Def 1
\end{defn}


\begin{theorem}
 \label{theorem:1}
 Theorem 1
\end{theorem}


\begin{lemma}
 \label{lemma:1}
 Lemma 1
\end{lemma}


\begin{defn}
 \label{defn:2}
 Lemma 1
\end{defn}




Here should be Definition: \autoref{defn:1}

Here should be Theorem: \autoref{theorem:1}

Here should be Lemma: \autoref{lemma:1}

\end{document}
lockstep
  • 250,273

1 Answers1

5

The cleveref package provides the \cref macro, which is even more clever [pun intended] than \autoref. For instance, it can take multiple arguments. In addition, \cref is better than \autoref at figuring out which label to use when several environments share a common counter, as is the case with definition, theorem, and lemma in your example

In the following example, the cleveref package is loaded with the option nameinlink. This makes both the label and the number part of the hypertarget, mimicking the look of cross-references generated by \autoref.

enter image description here

\documentclass[a4paper,11pt]{report}

\usepackage[english]{babel}
\usepackage[T1]{fontenc}
%%\usepackage{ucs} % don't use it; it's deprecated
\usepackage[utf8]{inputenc}

\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{amssymb}
\usepackage[colorlinks]{hyperref}
\usepackage[nameinlink]{cleveref}

\newtheorem{defn}{Definition}[chapter]
\newtheorem{theorem}[defn]{Theorem}
\newtheorem{lemma}[defn]{Lemma}

\crefname{defn}{definition}{definitions}
\Crefname{defn}{Definition}{Definitions}


%\def\defnautorefname{Def.}
%\def\theoremautorefname{Thm.}
%\def\lemmaautorefname{Lem.}

\setlength{\parindent}{0pt}

\begin{document}

\setcounter{chapter}{1}
\begin{defn} \label{defn:1} Def 1 \end{defn}
\begin{theorem} \label{theorem:1} Theorem 1 \end{theorem}
\begin{lemma} \label{lemma:1} Lemma 1 \end{lemma}
\begin{defn} \label{defn:2} Definition 2 \end{defn}

Here are two Definitions: \Cref{defn:1,defn:2}

Here is a Theorem: \Cref{theorem:1}

Here is a Lemma: \Cref{lemma:1}

\end{document}
Mico
  • 506,678