GeneralCustomizing table referencing

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
meho_r
Posts: 823
Joined: Tue Aug 07, 2007 5:28 pm

Customizing table referencing

Post by meho_r »

Hi,

Let's say we have this situation:

1. In a doc we're using unnumbered chapters, section etc. (\setcounter{secnumdepth}{-4})

2. We need tables to start with 1. But, if we use counters already defined, we get 0.1, 0.2 etc. Which is the best way to do this? Defining a new counter?

3. We're using caption and varioref packages.

The goal: To have tables started from 1 (no matter in which part of the doc first table appears) and to have them referenced in text as "Table 1" for the first one, "Table 2" for the second etc., and not "Table 0.1", "Table 0.2" etc.

Help, please...

Here's what I tried, but couldn't figure out how to solve referencing problem:

Code: Select all

\documentclass[12pt]{scrbook}
\usepackage{tabularx,booktabs,varioref}
\usepackage[font={footnotesize,rm,bf},textfont={md}]{caption}

\newcounter{tabela}
\setcounter{tabela}{0}

\DeclareCaptionFormat{nb}{TABELA\nobreakspace\refstepcounter{tabela}\thetabela:\nobreakspace#3}
\captionsetup[table]{format=nb}

\begin{document}

\begin{table}
\caption{Test table A}\label{tab:Test_table_A}
\begin{tabularx}{\linewidth}{XXX}
\toprule
A & B & C \\
D & E & F \\
\bottomrule
\end{tabularx}
\end{table}

Reference to the first table:~\vref{tab:Test_table_A}

\begin{table}
\caption{Test table B}\label{tab:Test_table_B}
\begin{tabularx}{\linewidth}{XXX}
\toprule
A & B & C \\
D & E & F \\
\bottomrule
\end{tabularx}
\end{table}

Reference to the second table:~\vref{tab:Test_table_B}
\end{document}

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

meho_r
Posts: 823
Joined: Tue Aug 07, 2007 5:28 pm

Customizing table referencing

Post by meho_r »

Finally, figured it out. I simply changed thetable counter:

Code: Select all

\renewcommand{\thetable}{\arabic{table}}
It should be mentioned (maybe) that this is needed only for Koma-SCRIPT class. With book class there shouldn't be problems.
User avatar
Stefan Kottwitz
Site Admin
Posts: 10345
Joined: Mon Mar 10, 2008 9:44 pm

Re: Customizing table referencing

Post by Stefan Kottwitz »

Hi,

if you don't need chapters, you could use article or scrartcl. The 0 appeared because there wasn't a chapter started.
Furthermore some classes reset the table counter at the start of each chapter, just keep that in mind.

Stefan
LaTeX.org admin
meho_r
Posts: 823
Joined: Tue Aug 07, 2007 5:28 pm

Re: Customizing table referencing

Post by meho_r »

Thanks for the reply. I need chapters (even parts). The funny thing is that there is a chapter started, only without number. I looked at koma-script manual and founded some traces that led me to the "thetable" counter. I tested it and counter looks consistent and continues in the parts/chapters following the chapter first table appeared in.
Post Reply