Question

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}
Was it helpful?

Solution

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!

OTHER TIPS

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.

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.

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top