阶段 5 · 图表、表格与文献 37 / 48 ≈ 15 分钟读完

LaTeX 浮动体定位:h t b p、float 宏包与几种逃生手段

浮动体是挂在一张清单上的盒子,而这张清单由断页器来清账,清账时检查的是四个你可以改的数字。这一课跟着一个浮动体从 \begin{figure} 一路走到印在纸上的那一页——缓放清单、顶槽与底槽、浮动体单页——然后说明 h t b p ! 真正允许的是什么、内核里哪些参数决定结果,以及为什么 [H] 通常是走错的那条逃生通道。

    浮动体是挂在清单上的一个盒子

    LaTeX 读到 \begin{figure}[htbp] 时并没有放置任何东西。它开一个盒子(\@currbox,从空闲盒池 \@freelist 里取),把材料灌进去,再把这个盒子登记到一张清单上:普通浮动体进 \@deferlist,跨栏的 figure* 与 table* 进 \@dbldeferlist。这条命令做的就这么多,其余一切发生在输出例程里,也就是正在组装某一栏的时候。

    每一栏开头,内核先问 \@tryfcolumn:缓放的这些盒子够不够铺满整整一栏浮动体?不够的话,\@startcolumn 就从 \@deferlist 里挑盒子填顶槽和底槽,分别记进 \@toplist 与 \@botlist,并据此缩小留给文字的空间 \@colroom。文字随后被收集,\@makecol 把顶部的浮动体、文字、底部的浮动体粘成一个竖盒,交给 \@outputpage 送出,浮动体之间用 \floatsep,浮动体与文字之间用 \textfloatsep。

    由此推出的两件事,几乎解释了所有「我的图跑掉了」的抱怨。第一,浮动体只能落在源码里它出现的那个位置或之后:命令被读到之前那个盒子还不存在,LaTeX 无法把它往回挪去陪某句更早的话。第二,一个浮动体一旦进入缓放,就要和同批缓放者争下一页那几个槽位,而胜负由下一节那些数值检验决定,与你写的放置字母顺序无关。

    也值得记住浮动体为何存在。TeX 拒绝在浮动体中间断页,因为半张图的坏处远大于图挪到下页的好处。这条保证就是你为「它可以被搬动」付的价钱,也正是 [H] 一把丢掉的东西。

    The four slots a float may occupy on a page, the fractions that bound them, and the lists the output routine drains them from ONE TEXT PAGE, H = textheight (220 mm ON A4 ARTICLE) top slot 1 (t) counted by topnumber top slot 2 text h placement: the box sits in here, surrounded by intextsep, and counts against totalnumber text left must be at least theta H bottom slot (b) bottomnumber, botroom = beta H toproom = tau H tau = topfraction = 0.7 so 154 mm of float at the top botroom = beta H = 66 mm A FLOAT PAGE (p) no text at all made only when the deferred boxes reach fpmin = rho H rho = floatpagefraction = 0.5 in article.cls stack spacing: fptop, fpsep, fpbot THE LISTS @freelist empty boxes to fill @deferlist waiting for the next column break @dbldeferlist figure* and table* top of a page only @toplist chosen for this page @botlist chosen for this page @midlist the h survivors combined by @makecol, shipped by @outputpage Escape hatches act at different points: [!ht] changes the permissions of one box, FloatBarrier drains the queue at a point in the text, clearpage ships out everything and starts a new page, and [H] removes the box from this pipeline entirely.
    一个浮动体能占的四个槽位,以及每次断栏时输出例程从哪几张清单里把它们放掉。

    h、t、b、p 与 ! 究竟允许了什么

    内核把这些字母写成一组许可,而不是优先级顺序:h 允许在正文当前位置、t 允许在文字页顶部、b 允许在该页底部、p 允许在单独的浮动体页。写 [htbp] 的意思是「这四条里哪条都行」;LaTeX 既不会从左到右挨个试,也不会偏爱第一个字母。

    h 实践上是四者中最弱的,因为它必须在浮动体被读到的那一刻通过一道很紧的检验:盒子要塞得进本栏剩下的空间,且至少给文字留下 \textfraction 那么多。超过半栏高的图在一段话中间几乎不可能满足这条,于是有了那句经典提示:LaTeX Warning: `h' float specifier changed to `ht'——LaTeX 是在告诉你它驳回了你的请求,改试顶槽。

    ! 的含义是「对这个浮动体跳过数值型浮动参数」,也就是 \topfraction、\bottomfraction 与 \textfraction 不再对这个盒子做检验。它变不出一个已经放满的槽位,对 p 也完全无效,后者受自己的 \floatpagefraction 检验管。所以 [!ht] 该读作「塞得下就放这里,否则放本页顶部」,是个合理请求;[h!] 则只是一种情绪。

    一类浮动体的默认值写在 \fps@figure 与 \fps@table 里:不写可选参数时,\begin{figure} 用的就是这两个宏的内容(标准类里图是 tp,表也是 tp,所以光秃秃一个 \begin{table} 本来就被允许漂到下一页)。要让全文改默认,机制是 \renewcommand{\fps@figure}{htbp}——内核里并没有公开的 \floatplacement 命令,宣称提供这类命令的宏包不过是在包装这个宏。

    h_{\mathrm{float}} > H_{\mathrm{remaining}} \;\Longleftrightarrow\; \text{the h specifier is widened to ht}
    h_{\mathrm{float}} > H_{\mathrm{remaining}} \;\Longleftrightarrow\; \text{the h specifier is widened to ht}
    密集的论文里 [t] 之所以胜过 [h],不是品味问题:全高的图只有下一页的顶槽才稳定地放得下。

    真正说了算的那几个数值

    每一项放置检验,都是拿一个高度去和本栏高度 H 的某个分数作比(内核里的 \@colht,在栏开头时等于 \textheight)。顶部所有槽合起来可占 \topfraction⁠×⁠H,底部合起来占 \bottomfraction⁠×⁠H,而至少 \textfraction⁠×⁠H 必须留给文字。计数器给数量封顶:topnumber、bottomnumber 和 totalnumber(后者把插在文中那一栏的浮动体也算在内)。

    浮动体单页走的是另一道检验。内核算出 \@fpmin = \floatpagefraction × H,只有缓放清单上的盒子加起来不少于这个值,\@tryfcolumn 才肯用清一色的浮动体去填一页。这就是孤零零一张图能在队列里蹲上两页的原因:article.cls 把 \floatpagefraction 定为 0.5,一张 60 mm 的图挣不到一整页只放它。

    这些默认值来自文档类而不是内核,而标准 article 的那一套保守得像 1986 年的书,不像 2026 年的论文:topnumber 2、\topfraction 0.7、bottomnumber 1、\bottomfraction 0.3、totalnumber 3、\textfraction 0.2、\floatpagefraction 0.5。既然 \textfraction 是 0.2,任何高于栏高 80% 的浮动体就根本无法放进文字页的顶槽——这一点每个人都迟早要吃一次惊。

    解法是导言区里的一整块参数,而不是同一个个字母较劲:把 \topfraction 提到 0.85,把 \textfraction 降到 0.07,把 \floatpagefraction 提到略低于 \topfraction(浮动页与顶槽抢的是同一批盒子,两者必须自洽),再把 totalnumber 抬到 5。本节那段可编译示例就是这块参数,出厂值写在注释里。若把 \floatpagefraction 设得比 \topfraction 还高,你就会收到那句著名的 LaTeX Warning: Text page 5 contains only floats,外加一页空白。

    R_{\mathrm{top}} = \tau H,\quad R_{\mathrm{bot}} = \beta H,\quad H_{\mathrm{text}} \ge \theta H
    R_{\mathrm{top}} = \tau H,\quad R_{\mathrm{bot}} = \beta H,\quad H_{\mathrm{text}} \ge \theta H
    症状与病因对上号:Too many column floats 是 totalnumber 用尽;一个浮动体在队列里卡好几页,则是 \floatpagefraction 或 \topfraction 正在忠实执行你设的值。
    \documentclass[a4paper,10pt]{article}
    \usepackage[T1]{fontenc}
    \usepackage{graphicx,booktabs,caption}
    \usepackage{placeins}       % \FloatBarrier; option "section" = barrier per section
    
    % ---- the numbers LaTeX tests against (article.cls defaults in brackets)
    \setcounter{topnumber}{3}            % [2]  floats allowed at the top
    \renewcommand{\topfraction}{0.85}    % [.7] fraction of the column they may take
    \setcounter{bottomnumber}{2}         % [1]  floats allowed at the bottom
    \renewcommand{\bottomfraction}{0.7}  % [.3]
    \setcounter{totalnumber}{5}          % [3]  floats on one page, h included
    \renewcommand{\textfraction}{0.07}   % [.2] minimum fraction that must be text
    \renewcommand{\floatpagefraction}{0.75} % [.5] how full a float page must be
    
    % two-column spans
    \setcounter{dbltopnumber}{2}
    \renewcommand{\dbltopfraction}{0.85}
    \renewcommand{\dblfloatpagefraction}{0.75}
    
    % the gap a float leaves around itself
    \setlength{\floatsep}{14pt plus 4pt minus 3pt}
    \setlength{\textfloatsep}{14pt plus 4pt minus 3pt}
    \setlength{\intextsep}{14pt plus 4pt minus 3pt}
    
    \captionsetup{font=small,skip=6pt}
    
    \begin{document}
    \section{Results}
    As Figure~\ref{fig:one} shows\dots
    \end{document}

    把浮动体留在正文附近:几件趁手的工具

    \FloatBarrier 出自 placeins 宏包,是那种人人想要却叫不出名字的工具:它禁止任何浮动体出现在这一点之后却尚未被安置,换句话说,它在栅栏前把缓放清单清空。每节结尾放一道——\usepackage[section]{placeins} 会在每个 \section 处自动插一道——图就不会晃进下一章。它变不出空间,所以被它冲刷的那一页底部可能留出一大段空白;这是约定的交换,也远好过一张图出现在离首次提及三页之外。

    \clearpage 更硬:它结束当前页,并把剩下所有浮动体送上浮动页。章末用它正合适,LaTeX 自己在 \tableofcontents 或 \bibliography 之前跑的就是它。\afterpage{\clearpage}(afterpage 宏包)是委婉版:本页照原样收完,到下一个断页点再全部冲刷——这正是「这页空了一半、图还卡在队列里」的标准答案。

    \suppressfloats[t] 与 \suppressfloats[b] 是细粒度工具:它们只关掉指定的那个槽,且仅对当前页的剩余部分有效。当一页顶部的浮动体已经吃满视觉配额、再塞一个会显得荒谬时就用它。它是局部声明,所以要紧跟在你想保护的材料之后,而不是放进导言区。

    \enlargethispage{2\baselineskip} 买到的是本页的物理高度,而这有时恰恰是 h 放置被拒的真实原因:没有任何规则被违反,只是高度预算不够。配上 [!ht] 一起用,并记住它只作用一页、一重排就失效——它是清样阶段的工具,理由要写进源码注释里。

    Source order versus printed order: a float can only move forwards, so a figure written between two paragraphs may land at the top of the next page SOURCE, TOP TO BOTTOM para 1 ... begin{figure}[htbp] fig:A Figure A, 92 mm tall para 2 ... begin{table}[htbp] tab:X Table X, 24 mm tall section{Discussion} FloatBarrier (automatic with placeins option section) begin{figure}[H] fig:B Figure B, pinned PAGE 1 AS SHIPPED top slot: Table X moved up here paras 1 and 2 Figure A does not fit in the room left after textfraction is served, so h fails and the box is deferred warning: h changed to ht Discussion, first lines nothing may pass the barrier Figure B: exactly where written, and unbreakable PAGE 2 AS SHIPPED top slot: Figure A taken from @deferlist at the start of the new column text continues Discussion is now two paragraphs away from the figure it cites, which is why you refer to it as Figure~\ref{fig:A} never as "the figure above" Moving a float earlier in the source is the one edit that always changes the outcome: a float is only ever allowed to travel forwards from where it was written.
    几种逃生手段各自的作用点:栅栏清队列,clearpage 收掉整页,suppressfloats 关掉一个槽,enlargethispage 买高度。

    [H] 为什么几乎都是错的

    float 宏包的 [H] 说明符并不放置浮动体。它把你写的材料当作普通、不浮动的内容,就排在你敲下的那个位置上——靠一个 \par 和一个盒子完成。盒子是作为一个整体构造的,断页器不能把它劈开;而这恰恰是浮动体的定义性特征。所以 [H] 不是「浮动,但就放这里」,而是「根本不再浮动,后果我自己承担」。

    后果具体且可复现。材料塞不进本页剩下的空间,你会得到一个 overfull \vbox,内容淌进下边距或者躲到页脚后面;材料比整页还高时,甚至可能直接丢掉。它前面的文字不会被拉伸,于是上面那段提前收尾留下一个洞,任何关于 \raggedbottom 的解释都说服不了审稿人。而一份到处用 [H] 的文档,等于放弃了整套浮动算法——每张图都变成你自己的责任,每次改动、每一页都算。

    [H] 真正合适的场景只有两种:一小段作为论证环节、必须夹在两段之间的图;以及在讲 LaTeX 的文档里把代码清单或表格当作它自身的示例。即便如此也更推荐 caption 宏包的 \captionof(或者轻量版 capt-of):一个居中盒加 \captionof{figure}{...} 就给你编号、\label、图清单条目,以及周围合法的断页,而整套浮动机制完全不参与。

    如果真实的抱怨其实是「图应该出现在提到它的那句话所在的那一页」,解法通常是那整块参数加上每节结尾一道 \FloatBarrier,而不是 [H]。更老的 nonfloat 宏包与 floatrow 这一层,都是从浮动代码一侧去攻同一个问题,而不是从「举一侧」;其中 floatrow 还顺带给出按行控制题注位置、以及两类浮动体并排的能力——注意 floatrow 与 subcaption 并非设计为同时加载,成组图表请在这两套里选一套。

    \documentclass[a4paper]{article}
    \usepackage{graphicx}
    \usepackage{caption}      % provides \captionof
    \usepackage{float}        % provides [H]
    \usepackage{needspace}    % \needspace: only place it if room remains
    \usepackage{afterpage}    % \afterpage{\clearpage}
    \begin{document}
    
    % (a) Ask for here, but let the page breaker have the last word.
    \begin{figure}[!ht]
      \centering
      \includegraphics[width=0.6\textwidth]{curve}
      \caption{Preferred form: the bang ignores the fractions, not the page.}
      \label{fig:one}
    \end{figure}
    
    % (b) A barrier at the end of the section: nothing may float past it.
    \FloatBarrier
    
    % (c) No float at all: a centred box plus \captionof keeps the counter,
    %     the number, the LOF entry and a legal page break around it.
    \begin{center}
      \includegraphics[width=0.6\textwidth]{block2}
      \captionof{figure}{Pinned exactly here, and still called Figure 2.}
      \label{fig:pinned}
    \end{center}
    
    % (d) The float package's [H]: typeset as ordinary material, cannot break,
    %     so an over-tall [H] float walks into the bottom margin.
    \needspace{8\baselineskip}   % guard: move on if too little room is left
    \begin{figure}[H]
      \centering
      \includegraphics[width=0.9\textwidth]{wide}
      \caption{Exactly here, at the price of the page breaker.}
    \end{figure}
    
    \end{document}

    双栏、跨栏浮动体,与那一页的延迟

    figure* 与 table* 是独立的浮动类别,有自己那张清单(\@dbldeferlist)、自己的计数器(dbltopnumber)和自己的分数(\dbltopfraction、\dblfloatpagefraction)。它们能放页顶或上浮动页;标准类根本不理会 h 和 b 这两个字母,所以 \begin{figure*}[htbp] 会静悄悄地变成一个 [t] 请求。

    晚一页是结构造成的,不是疏忽。跨栏浮动体只能放进一页仍在收集中的页面,而双栏输出例程在两栏都齐的那一刻就把这一页送出。第 3 页左栏还在搭建时才出现的 figure* 挤不进第 3 页,只能落在第 4 页顶部。职业习惯因此是:把 figure* 写在讨论它的文字之前一节,并在行文里用编号指代它,而不是说「上图」。

    底部放置的跨栏浮动体是内核真的不支持的那一件事,为此有两个宏包:stfloats 给 figure* 与 table* 补上底部选项,较新的 dblfloatfix 则更彻底地修补跨栏浮动体的顶部与底部放置。任选其一就够,不要两个都加载;此后要重新检查文末那些浮动页,因为跨栏页的构造代码与文字页不是同一套。

    单栏文档里 figure* 不算错误,但是个陷阱:带星号的环境只在类以双栏模式运行时才有意义,在单栏 article 里它们退化成普通浮动体,放置结果变得难以理解。而如果你想要的只是「正文栏的宽度」,你本来就有——去调图片的尺寸,不要去换环境。

    \documentclass[twocolumn,a4paper]{article}
    \usepackage{graphicx}
    \usepackage{stfloats}       % allows bottom placement of figure* / table*
    \usepackage{dblfloatfix}    % alternative: fixes top/bottom spans in 2-column
    
    \setcounter{dbltopnumber}{2}
    \renewcommand{\dbltopfraction}{0.85}
    \renewcommand{\dblfloatpagefraction}{0.75}
    
    \begin{document}
    
    \section{Method}
    % A span float may go at the top of a page (or with stfloats, at the
    % bottom), or on a float page -- never "here" in the middle of a column.
    \begin{table*}[t]
      \centering
      \caption{Parameter estimates for all four rigs.}
      \label{tab:all}
      \begin{tabular}{lrrrr}
        A & B & C & D \\ \hline
        1 & 2 & 3 & 4
      \end{tabular}
    \end{table*}
    
    % If the span is announced in the left column of page 3 it lands on page 4,
    % because the page must be gathered before it can be shipped out.
    Table~\ref{tab:all} therefore appears one page later than you wrote it.
    
    \end{document}

    间距:改的是观感而不是位置

    五个长度决定了已经就位的浮动体长什么样。\floatsep 是两个相邻浮动体之间的胶水,\textfloatsep 是顶部或底部浮动体与正文之间的胶水,\intextsep 是插在文中的(h)浮动体上下两侧的空间。三者按设计都可伸缩——14pt plus 4pt minus 3pt——一页看起来失衡却并不坏,就是它们在起作用:胶水本来就在干胶水该干的事。

    浮动页还自有一组三个:\@fptop、\@fpsep、\@fpbot,负责把一摞浮动体摆在 p 页上。默认值是前面一个 fill、中间可伸缩胶水、后面再一个 fill,所以浮动页是顶对齐的;要让三张矮图别被摊满整张纸,办法就是 \setlength{\@fpbot}{0pt plus \fil} 这一类改写。

    题注与它的材料之间隔着 \abovecaptionskip 和 \belowcaptionskip,而 caption 宏包把它们连同 skip=、position=、font=、labelfont=、justification=、singlelinecheck= 一起暴露成键。标准类里 \belowcaptionskip 很小,而图下方的题注要的是上方那道空隙——于是「题注粘在图上」这个经典抱怨是导言区一行的事,不必在每张图下面贴一个 \vspace。

    最后是整页层面:\flushbottom(book 的默认)会拉伸每一页的胶水,让所有栏在同一高度收尾,而这恰恰会把一个略大了一点的浮动体放大成段落之间清晰可见的白河。\raggedbottom(article 的默认)则允许一页短着收。浮动体很多的手稿里,两者来回切一下,立刻能看出问题是在放置上,还是在你允许周围存在的那份伸缩性上。

    \sum_{k=1}^{n} h_{k} + (n-1)s \;\ge\; \rho_{\mathrm{fp}}\,H \qquad (s = \text{float separation})
    \sum_{k=1}^{n} h_{k} + (n-1)s \;\ge\; \rho_{\mathrm{fp}}\,H \qquad (s = \text{float separation})
    空隙不要靠浮动体内部的 \vspace 去补:上面每一项检验比的都是浮动体自身的高度,手工加的一段 skip 会改变它能被放到哪里。

    那些提示分别意味着什么,怎么处置

    LaTeX Warning: \`h' float specifier changed to \`ht'. 你的 h 没通过那道容纳检验。三条路:接受它(字母本来就是这个意思)、把图改矮,或者照那段示例去抬 \textfraction/\topfraction。不要条件反射地加 !:感叹号移掉的是分数检验,移不掉的是空间。

    ! LaTeX Error: Too many column floats. 等着安置的浮动体多过 totalnumber 在一栏里允许的数量,通常是因为某道 \FloatBarrier 或 \clearpage 把盒子拦在了那里。抬 totalnumber、在放置里允许 p,或者把栅栏挪个位置。

    LaTeX Warning: Text page 5 contains only floats. 浮动页检验通过了,可这一页除浮动体外什么都没有:要么 \floatpagefraction 相对于你手上的浮动体量来说太低,要么某个 ! 强行按下了算法本来会拒绝的放置。把 \floatpagefraction 提上去,并且别再强按。

    Overfull \vbox,报告为 "detected at position N in output routine" 或 "while shipping out page N"。 建页时有一个不能断的东西被塞进了竖列表:一个 [H] 浮动体、一个高过一页的 minipage,或者放错位置的 \parbox。把 [H] 换成 [ht] 浮动体;位置确实要紧时,就干脆不放进任何浮动体而改用 \captionof。还有一件事在图死活不出现在正文附近时该先试:写在提及它那段之后的浮动体只能往前漂,所以去挪源码——这是唯一屡试不爽的改法。

    \theta H = 0.2 \times 220\,\mathrm{mm} = 44\,\mathrm{mm} \quad \text{of text still required}
    \theta H = 0.2 \times 220\,\mathrm{mm} = 44\,\mathrm{mm} \quad \text{of text still required}
    整套调试的顺序:读第一条提示而不是最后一条;参数块对全文检查一次;然后去源码里挪那个浮动体。永远不要为了赌运气去重排那几个字母。

    本课速查

    每节抽一行关键代码:点小节名跳到对应位置,代码一键复制。

    小节 关键代码
    h_{\mathrm{float}} > H_{\mathrm{remaining}} \;\Longleftrightarrow\; \text{the h specifier is widened to ht}
    \documentclass[a4paper,10pt]{article}
    \documentclass[a4paper]{article}
    \documentclass[twocolumn,a4paper]{article}
    \sum_{k=1}^{n} h_{k} + (n-1)s \;\ge\; \rho_{\mathrm{fp}}\,H \qquad (s = \text{float separation})
    \theta H = 0.2 \times 220\,\mathrm{mm} = 44\,\mathrm{mm} \quad \text{of text still required}

    常见错误

    • 把 float 宏包的 [H] 当成通用方针。它不是浮动体,不能跨页断开,过高的一只会从纸尾走出去。
    • 把 [htbp] 读成优先级列表。这些字母是许可,你写的顺序什么都改变不了,唯一受影响的是 h 失败时你看到的那句提示。
    • 先用 [!h] 强行按下每一个浮动体,再在题注里补一个 \vspace{-2cm}。负值 skip 改的是浮动体的高度,于是下一个浮动体能去哪里也跟着变了。
    • 抬了 \topfraction 却不抬 \floatpagefraction,或者把两者的次序设反,于一页只有浮动体的页冒出来,日志里写着 Text page contains only floats。
    • 双栏文档里指望 figure* 理会 h 或 b:跨栏浮动体只有页顶和浮动页两个去处,除非你加载 stfloats 或 dblfloatfix。
    • 把浮动体写在讨论它的那段之后,然后怪 LaTeX。浮动体只会往前走。
    • 同时加载 floatrow 与 subcaption,再去追随之而来的题注错误:它们是同一件活的两种替代方案。

    关于本课的常见问题

    怎么让图和提到它的那段文字留在同一页?
    源码里把浮动体紧跟在提到它的那段之后,放置写 [!ht],然后全文一次设好上限:topnumber 3、topfraction .85、textfraction .07、floatpagefraction .75、totalnumber 5。再在每个 \section 结尾加一道 \FloatBarrier,不让任何东西漂过标题。这个组合把图留在本页的成功率,远高于任何针对单张图的花样。
    H 说明符与 h 的区别到底在哪里?
    h 是请浮动算法把盒子放在当前位置,放得下就放,放不下就进队列;H 绕过整个算法,把材料当作普通不浮动的内容排出来,这意味着它不会跨页断开,也可能溢出下边距。H 是一道命令,h 是一份许可。
    FloatBarrier 是什么,非要靠 placeins 吗?
    \FloatBarrier 由 placeins 定义,是一个任何浮动体都不许越过的点:仍在缓放的东西会在它之前全部安置,图因此不再漂进下一节。加载时带上 section 选项,每个 \section 处就自动有一道栅栏。内核没有等价命令;\clearpage 是一件钝得多的工具,它还会顺手结束整页。
    为什么我的图出现在写完它之后两页?
    因为中间每一页它都放不下,而队列在每个断栏点是严格按顺序清账的。要么是图高过 topfraction,要么是 floatpagefraction 不肯单独给它一页。把分数抬上去、把图缩小,或者在源码里把浮动体往前挪。
    怎么阻止 LaTeX 把图单独排成一页?
    根本不给它这个许可:把 p 从放置列表里去掉,只写 [ht] 或 [!ht]。如果它仍然落在一张近乎空白的页上,那是缓放队列太满;查一下 totalnumber,并考虑用 \FloatBarrier 让前面的页消化积压。
    有办法只放题注而完全不浮动吗?
    有,而且位置真要紧时这是最干净的答案:图放进 center 环境,题注用 caption 宏包的 \captionof{figure}{...}(或更小的 capt-of 宏包)。计数器、编号、交叉引用和图清单条目一样不少,而断页器仍可照常在其周围正常断开正文。

    实时演示:直接编辑 LaTeX,立刻看渲染结果

    预览随输入实时更新——不妨故意写坏一次,看看报错长什么样。

    KaTeX 错误
    试一个例子

    继续读

    同一个东西的三个入口:记法本身、讲它的那一课、以及真正用它写东西的一篇文章。