8
Cross-Referencing
8.1 The Purpose of Cross-Referencing
Cross reference is the technical term for
“As I said previously in the last chapter, …”
To get serious for a moment, in a written article we may often have occasion to refer the reader to
something mentioned earlier
-
To tie your argument back to a section,
-
To point the reader to a figure/table in some other section,
-
Let the reader know additional information is in appendix,
2 2 A supplementary material placed at the end of a document and provides additional information which are relevant to the main document but not essential for understanding its core content. -
Referencing equation to follow up on an idea.
Such
cross
referencing
can
be
done
by
hand,
but
if
you
revise
your
document
and
insert
some
new
sections
then
changing
all
cross
references
manually
is
no
easy
task
and
just
a
labour
which
needs
to
be
avoided.
It
is
always
better
to
automate
such
tedious
tasks.
8.2 Making LaTeX do the Work
The basic method of using cross references, see
Section
8.1
for what we mean by cross reference, in LaTeX is simple. Suppose
somewhere in the second section of our article, you want to refer to the first section. We assign a
and at the point in the second section where the
Therefore the reference “see
Section
8.1
…” in the first sentence of this section was produced by including the command \label{intro}
in the command for the first section as follows:
and the command \ref{intro}
at the place of reference in the second section as
The \label{key}
for a section need not be given immediately after the \section{section name}
. It can be given anywhere within
the section.
The first time we run LaTeX on a file named, say, myfile.tex
containing cross references, the reference information is written in
an
myfile.aux
and at the end of the run LaTeX prints a
There is no need for an alarm as it is normal for this to happen. When a document is compiled for the first time, the compiler doesn’t have an idea on where the references are so in the first run it collects all the information and locates all the references, and then a second run gets the references right. The same thing happens when you’ve changed the reference information in any way, say, by adding a new section.
While
the
key
in \label{key}
can
be
any
sequence
of
letters,
digits
or
punctuation
characters,
it
is
convenient
to
use
some
mnemonic.
\label{limcon}
for
a
section
entitled
“Limits
and
Continuity”
rather
than \label{ref98}
.
Also,
when
you
make
a
reference,
it’s
better
to
type ~\ref{limcon}
than \ref{limcon}
to
prevent
the
possibility
of
the
reference
number
falling
off
the
edge.
8.2.1 Referencing Items
In
addition
to
sectioning
commands
such
as \chapter
or \section
,
reference
can
also
be
made
to
an \item
entry
in
an
enumerate
environment,
by
attaching
a \label
.
For
example
the
input [28]:
In the classical syllogism
Statements ( 1 ) and ( 2 ) are the premises and statement ( 3 ) is the conclusion.
Be
careful
about
references
to
tables
or
figures
(i.e.,
floats).
For
them,
the \label
command
should
be
given
after
the \caption
command
or
in
its
argument,
as
in
the
example
below:
\begin{table}[h] \begin{center} \setlength{\extrarowheight}{5pt} \begin{tabular}{|c|c|c|c|} \hline Value of $x$ & 1 & 2 & 3\\ \hline Value of $y$ & 1 & 8 & 27\\ \hline \end{tabular} \caption{Observed values of $x$ and $y$}\label{tabxy} \end{center} \end{table} Two possible relations betweeen $x$ and $y$ satisfying the data in Table\ref{tabxy} are $y=x3$ and $y=6x2-11x+6$
Which produces the following output:
Two possible relations betweeen and satisfying the data in Table 8.1 are and .
Think
of
a \caption
command
within
a
figure
or
table
environment
as
a
sort
of
sectioning
command
within
the
environment.
Therefore,
you
can
have
several \caption
and \label
pairs
within
a
single
figure
or
table
environment.
You
can
also
make
forward
references
in
exactly
the
same
way
by \ref
-ing
to
the
key
of
some
succeeding \label
.
8.2.2 Cross-Referencing in Math
Mathematical
documents
heavily
use
cross
references.
There
are
references
to
theorems
and
equations
and
figures
and
whatnot.
The
method
of
reference
is
exactly
as
before.
Therefore
if
you’ve
defined \newtheorem{theorem}[subsection]
,
then
after
typing
we get: and you can type elsewhere in the document
to get:
The converse of Theorem ?? is false.
References can be made to equations as in the following examples:
gives:
(8.1) |
Changing to in Equation ( 8.1 ) gives the following
If
you
load
the
package
amsmath
,
you
can
use
the
command \eqref
instead
of \ref
to
make
a
reference
to
an
equation.
This
automatically
supplies
the
parentheses
around
the
equation
number
and
provides
an
italic
correction
before
the
closing
parenthesis,
if
necessary.
For example,
produces
Equation ( 8.1 ) gives the following …
References
can
be
made
to
individual
equations
in
multiline
displays
of
equations
produced
by
such
environments
as
align
or
gather
(defined
in
the
amsmath
package).
The \label
command
can
be
used
within
such
a
structure
for
subnumbering
as
in
the
example
below:
8.3 Pointing to a Page using the varioref Package
In
making
a
reference
to
a
table
or
an
equation,
it
is
more
to
convenient
The command:
typesets
the
number
of
the
page
where
the
command \label{key}
was
given.
Therefore,
for
example
in this document produces
To avoid the tedium of repeated by typing
you can define the macro :
and
use \fullref
for
such
references.
However,
the
trouble
is
at
times
the
referred
object
and
the
reference
to
it
fall
on
the
same
page
This
can
be
avoided
by
using
the
package
varioref
[29].
If
you
load
this
package
by
including
the
following
code
snippet, \usepackage{varioref}
,
in
your
preamble,
then
you
can
use
the
command:
to
refer
to
an
object
we’ve
marked
with \label{key}
elsewhere
in
the
document.
The
action
of \vref
varies
according
to
the
page(s)
where
the
referred
object
and
the
references
are
typeset
by
TeX in
the
final
output.
- 1.
-
If
the
object
and
the
reference
are
on
the
same
page,
\vref
produces only a\ref
suppressing\pageref
so that only the number pointing to the object is typeset, without any reference to the page number. - 2.
-
If
the
object
and
the
reference
are
on
different
pages
whose
numbers
differ
by
more
than
one,
\vref
produces both\ref
and\pageref
. - 3.
-
If
the
object
and
the
reference
fall
on
pages
whose
numbers
differ
by
one,
7 7 that is, on successive pages\vref
produces\ref
followed by the phrase “on the preceding page” or “on the following page” depending on whether the object or the reference occurs first. Moreover, in the next occurrence of\vref
in a situation of the same type, the phrases are changed to “on the next page” and the “page before” respectively.
This
is
the
default
behaviour
of \vref
in
the article
class.
If
the
article
class
is
used
with
the twoside
option
or
if
the book
class
is
used,
then
the
behaviour
in
(3)
above
is
a
bit
different.
- 1.
-
If
the
object
and
the
reference
fall
on
the
two
sides
of
the
same
leaf,
the
behavior
of
\vref
is as in (3) above. - 2.
-
If
the
object
and
the
reference
fall
on
pages
forming
a
double
spread
(that
is,
a
page
of
even
number
followed
by
the
next
page),
then
\vref
produces\ref
followed by the phrase “on the facing page”. Moreover, in the next occurence of\vref
in a situation of the same type, the phrases are changed to “on the preceding page” and “on the next page” respectively.
The
phrases
used
in
the
various
cases
considered
above
can
be
customized
by
redefining
the
commands
used
in
generating
them.
For
the article
class
without
the twoside
option,
reference
to
the
previous
page
uses
the
command \reftextbefore
and
reference
to
the
next
page
uses \reftextafter
.
In
the
case
of
the article
class
with
the twoside
option
or
the book
class,
the
commands \reftextfaceafter
and \reftextfacebefore
are
used
in
the
case
of
reference
to
a
page
in
a
double
spread.
The
default
definitions
of
these
commands
are
given
below.
\newcommand{\reftextbefore} {on the \reftextvario{preceding page}{page before}} \newcommand{\reftextafter} {on the \reftextvario{following}{next} page} \newcommand{\reftextfacebefore} {on the \reftextvario{facing}{preceding} page} \newcommand{\reftextfaceafter} {on the \reftextvario{facing}{next}{page}}
In
all
these,
the
two
\reftextvario
are
phrases
alternatively
used
in
the
repeated
use
of
the
reference
as
mentioned
above.
You
can
customize
the
phrases
generated
in
various
situations
by
redefining
these
with
phrases
of
your
choice
in
the
arguments
of \reftextvario
.
If
you
want
to
refer
only
to
a
page
number
using \varioref
,
you
can
use
the
command:
to
produce
the
page
number
of
the
object
marked
with \label{key}
.
The
phrases
used
in
the
various
special
cases
are
the
same
as
described
above,
except
that
when
the
referred
object
and
the
reference
fall
on
the
same
page,
either
the
phrase
“on
this
page”
or
“on
the
current
page”
is
produced.
The
command
used
to
generate
these
is \reftextcurrent
whose
default
definition
is:
You
can
change
the
phrases
“this”
and
“the
current”
globally
by
redefining
this
command.
You
can
also
make
some
local
changes
by
using
the
two
\vpageref
allows.
Thus
you
can
use
the
command:
to
refer
to
the
page
number
of
the
object
marked
with \label{key}
.
The
same
page
phrase
will
be
used
if
the
object
and
the
reference
fall
on
the
same
page
and
the
phrase
other
page
phrase
will
be
used,
if
they
fall
on
different
pages.
Therefore
for
example,
the
command:
given in this document will produce
see the table on page 265
8.4 The cleveref Package
Using standard cross-referencing in LaTeX only produces the label number, a name describing the label such as figure, chapter or equation has to be added manually. The cleveref package overcomes this limitation by automatically producing the label name and number. It further allows cross-referencing ranges of labels and multiple labels of the same or different kinds, including auto-sorting and compression of labels [30].
The
package
implements \cref
for
basic
cross-referencing.
The
command
is
used
in
the
same
way
as
the
standard \ref
command.
Besides
the
label
number
it
also
produces
the
reference
kind.
Here is an example:
\documentclass[11pt]{article} \usepackage{graphicx} \usepackage{amsmath} \usepackage{cleveref} \begin{document} \begin{align} y&=a_1x+b_1\label{eqn:1} \end{align} \noindent Standard equation reference (\textbackslash ref): \ref{eqn:1}\\ Cleveref equation reference (\textbackslash cref): \cref{eqn:1} \begin{figure}[ht]\centering\rule{0.5\linewidth}{0.1\linewidth}\caption{First figure}\label{fig:1}\end{figure} \noindent Standard figure reference (\textbackslash ref): \ref{fig:1}\\ Cleveref figure reference (\textbackslash cref): \cref{fig:1} \end{document}
To
cross-reference
multiple
labels
of
the
same
or
different
kinds,
the \cref
command
is
used.
Labels
are
separated
by
commas
without
white-space (\cref{ref1,ref2,etc.}
).
For
a
range
of
the
same
label
kind,
the
command \crefrange{first}{last}
is
available.
\documentclass[11pt]{article} \usepackage{graphicx} \usepackage{amsmath} \usepackage{cleveref} \begin{document} \begin{align} y&=a_1x+b_1\label{eqn:1}\\ y&=a_2x+b_2\label{eqn:2}\\ y&=a_3x+b_3\label{eqn:3}\\ y&=a_4x+b_4\label{eqn:4} \end{align} \noindent Range example: \crefrange{eqn:1}{eqn:4} \begin{figure}[ht]\centering\rule{0.5\linewidth}{0.1\linewidth}\caption{First figure}\label{fig:1}\end{figure} \noindent Mixed references example: \cref{eqn:1,eqn:3,eqn:4,fig:1} \end{document}
By
default,
label
names
are
produced
with
a
small
initial
letter.
To
capitalize
the
first
letter
at
the
beginning
of
a
sentence,
use \Cref
and \Crefrange
instead.
For capitalization of all label names throughout the document, load the package with the capitalise option.