如何一致地在LaTeX中对浮点数进行编号? [英] How to number floats in LaTeX consistently?

查看:82
本文介绍了如何一致地在LaTeX中对浮点数进行编号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个LaTeX文档,我希望浮点数(表格和图形)的编号是从1到x的一个数字序列,而不是根据其类型的两个序列.我也不使用数字或表格列表,也不需要.

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}

推荐答案

图形环境与表环境之间的差异很小,仅使用不同的计数器并以单独的顺序进行维护.

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

也就是说,没有什么可以阻止您将{tabular}环境放置在{figure}中,或者将图形放置在{table}中,这意味着它们将以相同的顺序结束.这种情况的问题(如Joseph Wright所述)是,您必须调整\caption,以至于无法正常工作.

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

然后在表格和数字中使用\ucaption,而不是\caption(更改名称ad lib).如果要在其他环境(例如清单?)中使用相同的序列,请以相同的方式定义\the<foo>.

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.

正如OP所指出的那样,我先前的尝试实际上完全被破坏了:错误的举动是绝对根本的(ho,哼),而不是琐碎的且只是轻率地解决.

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).

(对于狂热爱好者来说,这是因为\advance命令是在TeX的肠道中处理的,但是.lof,.lot,和.aux 文件的内容在TeX的嘴中是固定的,在扩展时,写入文件的是调用\caption时调用随机值\@tempcnta的任何内容,而忽略了\advance计算,然后将其忠实地写入文件,然后忽略.我知道多久了但从未将其内部化!?)

(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

...,然后照常使用{table}{figure}环境.标题将具有正确的表格/图"文本,但它们将共享一个编号顺序.

...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.

请注意,此示例在listoffigures/listoftables中弄错了数字,但是(a)您说您对此并不在意,(b)它是可修复的,尽管可能有点轻率,并且(c)日子很艰难!

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!

这篇关于如何一致地在LaTeX中对浮点数进行编号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆