3

I have a LaTeX document where I'd like the numbering of floats (tables and figures) to be in one numeric sequence from 1 to x rather than two sequences according to their type. I'm not using lists of figures or tables either and do not need to.

My documentclass is report and typically my floats have captions like this:

\caption{Breakdown of visualisations created.}
\label{tab:Visualisation_By_Types}
Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Mr Morgan
  • 543
  • 4
  • 7
  • 17

4 Answers4

3

A quick way to do it is to put \addtocounter{table}{1} after each figure, and \addtocounter{figure}{1} after each table.

It's not pretty, and on a longer document you'd probably want to either include that in your style sheet or template, or go with cristobalito's solution of linking the counters.

Andy
  • 2,764
  • 6
  • 24
  • 33
2

The differences between the figure and table environments are very minor -- little more than them using different counters, and being maintained in separate sequences.

That is, there's nothing stopping you putting your {tabular} environments in a {figure}, or your graphics in a {table}, which would mean that they'd end up in the same sequence. The problem with this case (as Joseph Wright notes) is that you'd have to adjust the \caption, so that doesn't work perfectly.

Try the following, in the preamble:

\makeatletter
\newcounter{unisequence}
\def\ucaption{%
   \ifx\@captype\@undefined
     \@latex@error{\noexpand\ucaption outside float}\@ehd
     \expandafter\@gobble
   \else
     \refstepcounter{unisequence}% <-- the only change from default \caption
     \expandafter\@firstofone
   \fi
   {\@dblarg{\@caption\@captype}}%
}
\def\thetable{\@arabic\c@unisequence}
\def\thefigure{\@arabic\c@unisequence}
\makeatother

Then use \ucaption in your tables and figures, instead of \caption (change the name ad lib). If you want to use this same sequence in other environments (say, listings?), then define \the<foo> the same way.

My earlier attempt at this is in fact completely broken, as the OP spotted: the getting-the-lof-wrong is, instead of being trivial and only fiddly to fix, absolutely fundamental (ho, hum).

(For the afficionados, it comes about because \advance commands are processed in TeX's gut, but the content of the .lof, .lot, and .aux files is fixed in TeX's mouth, at expansion time, thus what was written to the files was whatever random value \@tempcnta had at the point \caption was called, ignoring the \advance calculations, which were then dutifully written to the file, and then ignored. Doh: how long have I know this but never internalised it!?)

Dutiful retention of earlier attempt (on the grounds that it may be instructively wrong):

No problem: try putting the following in the preamble:

\makeatletter
\def\tableandfigurenum{\@tempcnta=0
    \advance\@tempcnta\c@figure
    \advance\@tempcnta\c@table
    \@arabic\@tempcnta}
\let\thetable\tableandfigurenum
\let\thefigure\tableandfigurenum
\makeatother

...and then use the {table} and {figure} environments as normal. The captions will have the correct 'Table/Figure' text, but they'll share a single numbering sequence.

Note that this example gets the numbers wrong in the listoffigures/listoftables, but (a) you say you don't care about that, (b) it's fixable, though probably mildly fiddly, and (c) life is hard!

Norman Gray
  • 11,978
  • 2
  • 33
  • 56
  • Thanks. This does work to an extent. My article has a large number of table and figures and I find the numbering jumps from 14 to 16 and that references to tables and figures in the body text of the article are out of step, e.g. Figure 49 displays... But Figure 49 is actually Figure 11? I am assuming no changes are made to the body text references or to the caption or label text of tables and figures. – Mr Morgan Jun 28 '10 at 22:43
  • I think I may have found a better way. The problems I experienced with that are (1) it doesn't work with cleveref (which looks at the counter type to distinguish) and (2) it numbers things continuously instead of within a chapter. Instead, I use the aliascnt package, then I do `\let\c@table\@undefined` and then `\newaliascnt{table}{figure}`. Repeat with each counter you want to be in sequence with figures, e.g. `\let\c@thm\@undefined`, `\newaliascnt{thm}{figure}`. (You'll need to `\makeatletter`, `\makeatother` around the `\let`s, of course.) Works for me. Can anyone think of any problems? – EvanED Jul 16 '13 at 18:54
1

I can't remember the syntax, but you're essentially looking for counters. Have a look here, under the custom floats section. Assign the counters for both tables and figures to the same thing and it should work.

cristobalito
  • 4,192
  • 1
  • 29
  • 41
0

I'd just use one type of float (let's say 'figure'), then use the caption package to remove the automatically added "Figure" text from the caption and deal with it by hand.

Joseph Wright
  • 2,857
  • 22
  • 32