如何在 LaTeX 中对浮点数进行一致编号?

发布于 2024-09-07 16:50:29 字数 231 浏览 5 评论 0原文

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

我的文档类是报告,通常我的浮动有这样的标题:

\caption{Breakdown of visualisations created.}
\label{tab:Visualisation_By_Types}

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}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

唐婉 2024-09-14 16:50:54

我只使用一种类型的浮动(比方说“图形”),然后使用标题包从标题中删除自动添加的“图形”文本并手动处理它。

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.

简单 2024-09-14 16:50:51

我不记得语法了,但你本质上是在寻找计数器。看看这里,在自定义浮动部分下。将表格和数字的计数器分配给同一事物,它应该可以工作。

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.

╄→承喏 2024-09-14 16:50:42

图形环境和表格环境之间的差异非常小——只不过是使用不同的计数器并以不同的顺序维护而已。

也就是说,没有什么可以阻止您将 {tabular} 环境放入 {figure} 中,或将图形放入 {table} 中,这意味着它们最终会以相同的顺序结束。这种情况的问题(正如 Joseph Wright 指出的那样)是您必须调整 \caption,这样就不能完美地工作。

在序言中尝试以下操作:

\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

我之前的尝试实际上完全被打破了,正如OP所发现的那样:犯错不是微不足道的,而且修复起来很麻烦,而是绝对根本的(嗬,哼)。

(对于爱好者来说,这是因为 \advance 命令是在 TeX 的内部处理的,但是 .lof、.lot、 和 .aux 文件的内容是固定在TeX 的嘴,在扩展时,因此写入文件的内容是调用 \caption\@tempcnta 所具有的随机值,忽略 \提前计算,然后尽职地写入文件,然后忽略 Doh:我知道这一点有多久了,但从未内化它!?)

尽职地保留早期的尝试(因为它可能是有启发性的错误。 ):

没问题:尝试在序言中添加以下内容:

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

...然后使用 {table}{figure} 环境作为普通的。标题将具有正确的“表格/图”文本,但它们将共享一个编号序列。

请注意,这个例子在数字列表/表列表中得到了错误的数字,但是(a)你说你不关心这个,(b)它是可以修复的,尽管可能有点繁琐,并且(c)生活很艰难!

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!

白日梦 2024-09-14 16:50:39

一种快速的方法是在每个数字后面放置 \addtocounter{table}{1} ,在每个表格后面放置 \addtocounter{figure}{1}

它并不漂亮,在较长的文档中,您可能希望将其包含在样式表或模板中,或者采用 cristobalito 的链接计数器的解决方案。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文