如何将 figure/table 对齐到 XSL-FO 页面的顶部或底部 (FOP 2.1)

How to align figure/table to the top or bottom of the page in XSL-FO (FOP 2.1)

如果图或table有点大,将它们移动到页面的顶部或底部真的很合适table。通过重复 headers 将 table 重排到下一页的能力很棒,但并不总是我想要的。如果 table 或图形非常适合页面并且不一定锚定到段落,则没有理由重排它。最好让它“漂浮”在页面body之外。

This answer 真的很鼓舞人心,但我不确定如何将它应用到我的案例中。如果我能根据 table.

@rendition 属性来做,我会很高兴
<fo:layout-master-set>
    <fo:simple-page-master master-name="PageMaster.Title-Page" page-height="{$paper-height}" page-width="{$paper-width}" margin-left="{$margin-left}" margin-right="{$margin-right}" margin-top="{$margin-top}" margin-bottom="{$margin-bottom}">
        <fo:region-body/>
    </fo:simple-page-master>
    <fo:simple-page-master master-name="PageMaster.CopyRight-Page" page-height="{$paper-height}" page-width="{$paper-width}" margin-left="{$margin-left}" margin-right="{$margin-right}" margin-top="{$margin-top}" margin-bottom="{$margin-bottom}">
        <fo:region-body display-align="after"/>
    </fo:simple-page-master>
    <fo:simple-page-master master-name="PageMaster.TOC" page-height="{$paper-height}" page-width="{$paper-width}" margin-left="{$margin-left}" margin-right="{$margin-right}" margin-top="18mm" margin-bottom="{$margin-bottom}">
        <fo:region-body margin="0mm 0mm 0mm 60mm"/>
    </fo:simple-page-master><!-- Whole page left and right masters -->
    <fo:simple-page-master master-name="PageMaster.Page-Right.First" page-height="{$paper-height}" page-width="{$paper-width}" margin-left="{$margin-left}" margin-right="{$margin-right}" margin-top="{$margin-top}" margin-bottom="{$margin-bottom}">
        <fo:region-body margin="8mm 0mm 20mm 0mm" column-count="2" column-gap="5mm"/>
        <fo:region-before region-name="Region-Before-Right" extent="10mm" display-align="after"/>
        <fo:region-after region-name="Region-After-First" extent="20mm" display-align="before"/>
    </fo:simple-page-master>
    <fo:simple-page-master master-name="PageMaster.Page-Left" page-height="{$paper-height}" page-width="{$paper-width}" margin-left="{$margin-left}" margin-right="{$margin-right}" margin-top="{$margin-top}" margin-bottom="{$margin-bottom}">
        <fo:region-body margin="8mm 0mm 20mm 0mm" column-count="2" column-gap="5mm"/>
        <fo:region-before region-name="Region-Before-Left" extent="10mm" display-align="after"/>
    </fo:simple-page-master>
    <fo:simple-page-master master-name="PageMaster.Page-Right" page-height="{$paper-height}" page-width="{$paper-width}" margin-left="{$margin-left}" margin-right="{$margin-right}" margin-top="{$margin-top}" margin-bottom="{$margin-bottom}">
        <fo:region-body margin="8mm 0mm 20mm 0mm" column-count="2" column-gap="5mm"/>
        <fo:region-before region-name="Region-Before-Right" extent="10mm" display-align="after"/>
    </fo:simple-page-master>
    <fo:simple-page-master master-name="PageMaster.Blank" page-height="{$paper-height}" page-width="{$paper-width}" margin-left="{$margin-left}" margin-right="{$margin-right}" margin-top="{$margin-top}" margin-bottom="{$margin-bottom}">
        <fo:region-body margin="8mm 0mm 20mm 0mm" column-count="2" column-gap="5mm"/>
    </fo:simple-page-master><!-- Sequence of even / odd pages -->
    <fo:page-sequence-master master-name="Content-Pages">
        <fo:repeatable-page-master-alternatives>
            <fo:conditional-page-master-reference master-reference="PageMaster.Blank" blank-or-not-blank="blank"/>
            <fo:conditional-page-master-reference master-reference="PageMaster.Page-Right.First" odd-or-even="odd" page-position="first"/>
            <fo:conditional-page-master-reference master-reference="PageMaster.Page-Left" odd-or-even="even"/>
            <fo:conditional-page-master-reference master-reference="PageMaster.Page-Right" odd-or-even="odd"/>
        </fo:repeatable-page-master-alternatives>
    </fo:page-sequence-master>
</fo:layout-master-set>

正如 Tony Graham 评论的那样,FOP 不支持 before floats yet(奇怪的是,它会在没有警告的情况下默默地吞下它们)。

但是,您可以使用脚注代替将您的表格放在引用它们的页面底部。如果我没记错的话,FOP 倾向于将脚注完整地放置而不是添加更多 "flowing" 内容,因此结果 应该 是预期的结果。

FO 示例:

<?xml version="1.0" encoding="UTF-8"?>
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
    <fo:layout-master-set>
        <fo:simple-page-master master-name="simple" page-width="14.85cm" page-height="21cm">
            <fo:region-body margin="1in"/>
        </fo:simple-page-master>
    </fo:layout-master-set>

    <fo:page-sequence master-reference="simple">
        <fo:flow flow-name="xsl-region-body" text-align="justify">
            <fo:block>Maecenas lectus nisl, pulvinar at tincidunt a, semper sit amet nibh. Morbi at dolor quis sem porta volutpat. Quisque eget magna lectus. Donec laoreet congue enim ut ullamcorper. Ut vestibulum consequat neque rhoncus laoreet.</fo:block>
            <fo:block>Here is a block referring to a <fo:footnote><fo:inline font-weight="bold">TABLE 1</fo:inline><fo:footnote-body>
                <fo:block font-weight="bold">TABLE 1:</fo:block>
                <fo:table width="100%" table-layout="fixed">
                    <fo:table-column column-width="30%"/>
                    <fo:table-column column-width="70%"/>
                    <fo:table-body>
                        <fo:table-row>
                            <fo:table-cell><fo:block>A</fo:block></fo:table-cell>
                            <fo:table-cell><fo:block>132</fo:block></fo:table-cell>
                        </fo:table-row>
                        <fo:table-row>
                            <fo:table-cell><fo:block>B</fo:block></fo:table-cell>
                            <fo:table-cell><fo:block>556638</fo:block></fo:table-cell>
                        </fo:table-row>
                        <fo:table-row>
                            <fo:table-cell><fo:block>C</fo:block></fo:table-cell>
                            <fo:table-cell><fo:block>574</fo:block></fo:table-cell>
                        </fo:table-row>
                        <fo:table-row>
                            <fo:table-cell><fo:block>D</fo:block></fo:table-cell>
                            <fo:table-cell><fo:block>8893</fo:block></fo:table-cell>
                        </fo:table-row>
                    </fo:table-body>
                </fo:table>
            </fo:footnote-body></fo:footnote>; the table should be in the same page as the bolded part.</fo:block>
            <fo:block>This is another block of content. Lorem ipsum dolor sit amet, consectetur adipiscing elit. In tincidunt ipsum eget nisl iaculis fringilla. Pellentesque sagittis quam tellus, ac varius nisl rutrum non. Phasellus eget imperdiet velit.</fo:block>
            <fo:block>Aenean eleifend, arcu et feugiat facilisis, diam orci luctus lectus, id laoreet ex risus sed nunc. Proin eget scelerisque orci. Donec porttitor tellus libero, a molestie orci vestibulum mattis. Ut eu massa ac massa sagittis molestie. Quisque viverra ipsum vel mauris laoreet aliquet.</fo:block>
            <fo:block>Maecenas lectus nisl, pulvinar at tincidunt a, semper sit amet nibh. Morbi at dolor quis sem porta volutpat. Quisque eget magna lectus. Donec laoreet congue enim ut ullamcorper. Ut vestibulum consequat neque rhoncus laoreet.</fo:block>
            <fo:block> Sed ipsum massa, maximus eget posuere et, pellentesque accumsan nulla. Vestibulum erat mauris, imperdiet at mattis in, rhoncus eget orci. Nullam rhoncus hendrerit magna. </fo:block>  
        </fo:flow>
    </fo:page-sequence>
</fo:root>

结果输出:

使用脚注的缺点是对脚注放置的限制比浮动之前的限制更严格(可以放在页面以下 他们的锚点区域,根据 section 6.12.2 of the recommentation),因此如果输入在一系列段落中引用了许多表,则可能存在布局问题(页面中的空白区域)。

(披露:我是FOP开发者,虽然现在不是很活跃)