Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using a single count for figures and tables in LaTeX

Tags:

latex

I've been given a LaTeX document to edit with the following code for using a single count for figures and tables.

 \makeatletter
 \newcounter{unisequence}
 \def\ucaption{
    \ifx\@captype\@undefined
        \@latex@error{\noexpand\ucaption outside float}\@ehd
        \expandafter\@gobble
    \else
        \refstepcounter{unisequence} 
        \expandafter\@firstofone
    \fi
    {\@dblarg{\@caption\@captype}}
  }
 \def\thetable{\@arabic\c@unisequence}
 \def\thefigure{\@arabic\c@unisequence}
 \makeatother

This works well to give a single counter for captions of tables and figures but, I find that if I click on any of the caption numbers in the .pdf this code generates, I am always returned to the first figure or table in the document rather than the one I want, e.g. clicking on in Table [3] will take me to Table 1 instead.

Does anyone know how to fix this? Or can anyone advise an alternative?

I am a LaTeX newbie.

Thanks

Mr Morgan.

like image 436
Martin O'Shea Avatar asked Oct 05 '10 15:10

Martin O'Shea


2 Answers

If it's of use to anyone, use:

\makeatletter
\renewcommand*{\thetable}{\arabic{table}}
\renewcommand*{\thefigure}{\arabic{figure}}
\let\c@table\c@figure
\makeatother 

In the preamble of your document.

like image 26
Martin O'Shea Avatar answered Nov 15 '22 23:11

Martin O'Shea


Based on https://stackoverflow.com/a/3866061/53974 and https://tex.stackexchange.com/a/127744/1340, we can just (1) make the table counter be the same as the figure counter, and (2) make the table float type be the same as the figure float type, to ensure that the ordering is consistent with the numbering, because:

LaTeX keeps all floats of the same type in order

Code:

\makeatletter
\let\c@table\c@figure % for (1)
\let\ftype@table\ftype@figure % for (2)
\makeatother

Compared to https://stackoverflow.com/a/3866061/53974, this keeps \thetable and \thefigure alone—so the table and figure numbers are kept formatted as-is. This respects per-chapter/section numbering, and it works for me well together with hyperlinking, the subcaption, float and rotating packages, and probably more, on a 160-page document.

like image 193
Blaisorblade Avatar answered Nov 15 '22 23:11

Blaisorblade