1

I use the following code for referring to an equation and table.

\let\originaleqref=\eqref
\renewcommand{\eqref}{Equation~\originaleqref}
\newcommand{\tref}[1]{Table (\ref{#1})}

When I refer to an equation, there is no number of chapetr. But when I refer to a table, there is a number of chapter.

enter image description here

enter image description here

Here is a small MWE.

\documentclass[]{OAGM}
%% For the accepted, final version, set this to the correct value:
\OAGMarXiv{1404.3538}

\usepackage{float} % fix the table
\usepackage{bold-extra}
\usepackage{amsmath,bm}
\usepackage{color}
\usepackage{amsmath,amsopn}
\usepackage{bbm}
%\usepackage{hyperref} 
\usepackage{mathrsfs}
\usepackage{tikz,pgfplots}
\usepackage{listings}
\usepackage{color}
%\usepackage{breqn} 
\usepackage{caption}
\usepackage{subcaption}
\usepackage{epstopdf}
%\usepackage[titletoc,toc,title]{appendix}
\usepackage{mathtools} 
\usepackage{tabularx}
\usepackage{booktabs}
\usepackage{natbib }
\usepackage{graphics}
\usepackage{amsfonts}
\usepackage{mathtools}



\begin{document}

\section{1}
\subsection{2}

\begin{tabularx}{\textwidth}{XX}
\toprule
 a & b\\\midrule
 \label{Tab a simple table}\end{tabularx}


I have to cite the table ~\ref{Tab a simple table}

\end{document}
Vivian
  • 647
  • One way would be to redefine the table number, dropping the chapter info, but this effects also the table number in the caption: \renewcommand{\thetable}{\arabic{table}} for example –  Apr 24 '14 at 12:55
  • @ChristianHupfer - A downside of your proposed solution is that it doesn't deal with the fact the table number is probably reset to 0 at the start of each chapter. It's thus not enough to reset \thetable; it's also necessary to change the way the table counter variable is set and incremented. – Mico Apr 24 '14 at 13:00
  • @Mico: I do not want to reset the table number, just drop the chapter output format from \thetable. I agree with you if you meant a continous counting of tables. –  Apr 24 '14 at 13:08
  • @ChristianHupfer - If you only reset the table number's display, there's a huge risk of seriously confusing your readers if you have, say, three chapters and tables in all three chapters: Does a cross-reference to "Table 1" refer to Table 1.1, 2.1, or 3.1? – Mico Apr 24 '14 at 13:12
  • @Mico: Yes, I know, I basically wrote this in my first comment... –  Apr 24 '14 at 13:13

1 Answers1

2

I assume you want to change both the way tables are numbered and the way they are cross-referenced. I further assume you're using a document class such as book or report which numbers table and figure environments per chapter, starting at 1 at the start of each chapter.

To have these environments numbered (and thus also cross-referenced) continuously throughout the document, you could issue the following commands in the preamble:

\usepackage{chngcntr}
\counterwithout{table}{chapter}
\counterwithout{figure}{chapter}

Incidentally, instead of redefining \eqref and defining \tref in the ways you show in your posting, you could load the cleveref package and use its \cref cross-referencing command; \cref will automatically prefix the item's type (e.g., equation, section, table) before the associated number, or numbers.

[Image deleted. It turns out that the OP's problem was quite different from the way he/she had described it initially. See the addendum below for the actual solution.]

\documentclass{report}
\usepackage{chngcntr}
\counterwithout{table}{chapter}
\counterwithout{figure}{chapter}
\usepackage[capitalize,noabbrev]{cleveref} % just for this example
\begin{document}
\chapter{Uno}
\begin{table}\caption{First table}\label{tab:1}\end{table}
\begin{figure}\caption{First figure}\label{fig:1}\end{figure}

\chapter{Due}
\begin{table}\caption{Second table}\label{tab:2}\end{table}
\begin{figure}\caption{Second figure}\label{fig:2}\end{figure}
\begin{figure}\caption{Third figure}\label{fig:3}\end{figure}

\chapter{Tre}
Here are cross-references to \cref{tab:1,tab:2,fig:1,fig:2,fig:3}.
\end{document}

Addendum: After the OP posted a working example, it became clear that the "2.1" that showed up in the cross-reference was not associated with a table object at all, but with a subsection. (The OAGM document class does not feature a \chapter command at all, and it doesn't number table and figure items by section.) Below is a corrected form of the OP's MWE that shows the expected behavior (in terms of table numbers that show up in a cross-reference.)

enter image description here

\documentclass{OAGM}
%% For the accepted, final version, set this to the correct value:
\OAGMarXiv{1404.3538}
%% I've commented out duplicate package loading instructions...
\usepackage{float} % fix the table %% Why??
\usepackage{bold-extra}
\usepackage{amsmath,bm}
\usepackage{color}
\usepackage{amsopn}
\usepackage{bbm}
%\usepackage{hyperref} 
\usepackage{mathrsfs}
\usepackage{tikz,pgfplots}
\usepackage{listings}
%%\usepackage{color}
%\usepackage{breqn} 
\usepackage{caption}
\usepackage{subcaption}
\usepackage{epstopdf}
%\usepackage[titletoc,toc,title]{appendix}
\usepackage{mathtools} 
\usepackage{tabularx}
\usepackage{booktabs}
\usepackage{natbib}
\usepackage{graphicx}
\usepackage{amsfonts}
%%\usepackage{mathtools}

\begin{document}
\section{1}
\subsection{2}\label{subsec:xyz}

\begin{table}
\centering
\begin{tabular}{ll}
\toprule
 a & b\\
\bottomrule
\end{tabular}
\caption{My first table}
\label{tab:1}
\end{table}
Here's a cross-reference to Table~\ref{tab:1}, and here's a cross-reference to Subsection~\ref{subsec:xyz}.
\end{document}
Mico
  • 506,678
  • I have the error message. 'Package chngcntr Error: chapter is not a cnouter'. – Vivian Apr 24 '14 at 14:45
  • @Vivian - Which document class do you employ? – Mico Apr 24 '14 at 15:07
  • I submit the paper to a conference, actually a workshop. So I do not use a document class. – Vivian Apr 24 '14 at 15:53
  • @Vivian: In any LaTeX document, the document class is the argument of the command \documentclass, which (in all likelihood) is the very first instruction in your LaTeX document. – Mico Apr 24 '14 at 15:55
  • yes. The conference asks 'For the final version, do not set any document class options.' – Vivian Apr 24 '14 at 17:17
  • @Vivian - So you've been told not to use any optional arguments with the \documentclass instruction. However, this instruction also takes (exactly) one mandatory argument -- the document class itself. What does it say inside the curly braces of your document's \documentclass instruction? – Mico Apr 24 '14 at 18:34
  • Since the requirement, I use \documentclass[]{OAGM}. The conference name is OAGM. – Vivian Apr 24 '14 at 19:28
  • The OAGM documentclass does not feature a \chapter command, and it also does not number tables in "2.1", "2.2", etc. style. (Instead, they're numbered consecutively, i.e., 1, 2, 3, etc.) Hence, it's not necessary either to load the chngcntr package and issue the \counterwithout statements. Could you please elaborate what you meant when you wrote "But when I refer to a table, there is a number of chapter"? – Mico Apr 24 '14 at 20:00
  • @Yes, of course. Please see figs in the question. – Vivian Apr 24 '14 at 20:53
  • @Vivian - You've been asked several times to post an MWE (minimum working example, starting with \documentclass and ending with \end{document} that generates the problem behavior you want to change. Posting screenshots some code fragments is not sufficient. The OAGM class does not provide the command \chapter, so whatever you're showing in the screenshot can not be a chapter number. Moreover, by itself, the class keeps table numbers simple; some package must be interfering with the numbering. Please post a real MWE if you want people to have a chance to diagnose what's going on. – Mico Apr 24 '14 at 21:28
  • First I am sorry that I did not provide a MWE. At first, I really try to make one. But there are errors.And I have provided cls also. So I did not provide a MWE. – Vivian Apr 24 '14 at 21:58
  • Hi. I write one. It is strange. At the beginning, it does not have the number of chapter. But later, it has. I try to find the problem but I do not find the problem. – Vivian Apr 24 '14 at 22:15
  • Thanks for posting a compilable example. Your cross-reference to table ~\ref{Tab a simple table}, which generates "1.1", does not point to a table object but to the subsection numbered 1.1. Why? Because you don't actually have a table environment with a \caption command. Hence the command \label{Tab a simple table} actually points to the item whose number was most recently incremented via \refstepcounter, which happens to be a subsection counter. I'll post a corrected version of your MWE at the end of my answer. – Mico Apr 24 '14 at 22:32
  • Is there any method which I do not need to add table? Because I use \textsuperscript{\ref{1}} in the table, it will be wrong if I add table. – Vivian Apr 25 '14 at 08:08
  • 1
    I suddenly found that I do no need to add {table} environment. I put \label behind \captionof, then it works. – Vivian Apr 25 '14 at 08:55
  • you can try it. I do not know why it is Ok now. – Vivian Apr 25 '14 at 09:13