Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Referring to the body below, I would expect ~\ref{atts} to produce Table 1, but instead, it gives just 1.

What is the issue here?

share|improve this question

3 Answers 3

You have to use some package that knows what you are referring. I suggest cleveref:

\documentclass[twoside,11pt]{article}
\usepackage{cleveref}

\begin{document}

\begin{table}[ht]
\caption{Categories and example of attributes}
\label{atts}
\centering
\begin{tabular}{l p{8.0cm} l}
\hline
Variable & Items & Category \\
\hline
Built-up area  & Inside built-up area; outside built-up area & !!!CAT!!! \\
Type of road  & Highway; district or province road & !!!CAT!!! \\
Type of road lanes  & Road with one road lane; road with separated road lanes & !!!CAT!!! \\
Intersection  & Near intersection; outside intersection & !!!CAT!!! \\
Location characteristic  & Road works; bridge; tunnel; railroad; roundabout & !!!CAT!!! \\
Road factors  & Bad road surface; faulty signals; faulty lighting; road works; queue; downhill; curve; bad visibility & !!!CAT!!! \\
Miscellaneous  & Accident following accident; aquaplaning; sun blinded; school; recreation centre; bus stop; person swung out of vehicle; no safety belt; no helmet; no child seat; cargo on roadway before accident; cargo on roadway because of accident; fire after accident; comments & !!!CAT!!! \\
Total number of deaths  & 0; 1; 2; 3; 4; 5 & !!!CAT!!! \\ [1ex]
\hline
\end{tabular}
\end{table}

~\Cref{atts} is bad.

\end{document}

enter image description here

For details, refer to the documentation -- execute texdoc cleveref from command prompt.

share|improve this answer

Since you did not specify any example, I just have to guess: The \ref{} command does not know if you are referring to a table or figure. There are however packages that can determine this from the label. Have a look at prettyref.

A while ago I compiled a larger example for testing the package which first uses the standard referencing commands before using the prettyref commands in the end:

\documentclass[ngerman]{scrartcl}
\usepackage[latin1]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{babel}

\usepackage{blindtext}
\usepackage{varioref}
\usepackage{prettyref}

\newrefformat{eq}{\textup{(\ref{#1})}}
\newrefformat{lem}{Lemma \ref{#1}}
\newrefformat{thm}{Theorem \ref{#1}}
\newrefformat{cha}{Kapitel \ref{#1}}
\newrefformat{sec}{Abschnitt \ref{#1}}
\newrefformat{tab}{Tabelle \ref{#1} auf Seite \pageref{#1}}
\newrefformat{fig}{Abbildung \ref{#1} auf Seite \pageref{#1}}
\usepackage[]{showlabels}

\begin{document}

\section{Erster Abschnitt}\label{sec:erst}

\blindtext[3]

\begin{figure}%
\rule{\columnwidth}{5cm}
\caption{Hallo Welt!}%
\label{fig:test1}%
\end{figure}

\blindtext[1]

\section{Zweiter Abschnitt}

\blindtext[5]

\begin{figure}%
\rule{\columnwidth}{5cm}
\caption{Hallo Welt!}%
\label{fig:test2}%
\end{figure}

\blindtext[4]

Siehe Abbildung \ref{fig:test1} auf Seite \pageref{fig:test1}

Siehe die Abbildung \vpageref{fig:test1}

Siehe Abbildung \vref{fig:test1}

Siehe Abbildung \ref{fig:test2} auf Seite \pageref{fig:test2}

Siehe Abbildung \vpageref{fig:test2}

Siehe Abbildung \vref{fig:test2}

Siehe Abbildungen \vrefrange{fig:test1}{fig:test2}

Siehe die Abbildungen \vpagerefrange{fig:test1}{fig:test2}

\prettyref{fig:test1}

\prettyref{sec:erst}

\end{document}
share|improve this answer
up vote 0 down vote accepted

The exact problem was traced to typos at my end. The answers provided here are helpful from their part, but my case was resolved by type correction.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.