9

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.

4 Answers 4

6

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.

4

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.

3
  • This solution ignores per-chapter/section numbering. Oct 4, 2016 at 22:32
  • Why not just \makeatletter \let\c@table\c@figure \makeatother ? It seems to work perfectly for me, and doesn't break other things I had set up in this 160-page draft thesis: per-chapter numbering, subfigures with the subcaption package, hyperlinks... Apr 6, 2017 at 16:01
  • Edit: also \let\ftype@table\ftype@figure from stackoverflow.com/questions/3865036/… makes things better. Apr 6, 2017 at 21:21
0

Off the top of my head, this is a problem of the snippet you have there not generating the correct reference. See here, for instance: http://en.wikibooks.org/wiki/LaTeX/Hyperlinks

0

Combining the code in the query with a previous answer worked wonderfully for me - thank you.

To get the figures and tables numbered consecutively within chapters with chapter numbers too, I replaced two lines in the answer snippet by

\renewcommand*{\thetable}{\arabic{chapter}.\arabic{table}}
\renewcommand*{\thefigure}{\arabic{chapter}.\arabic{figure}}
2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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