简体   繁体   English

如何在XSL-FO(FOP 2.1)中将图形/表格与页面的顶部或底部对齐

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

In the case figure or table is a bit larger it would be really suitable to move them to the top or the bottom of the page. 如果图形或表格稍大一些,则将它们移至页面顶部或底部确实合适。 The ability to reflow table to the next page with repeating its headers is great but not always what I want. 通过重复表头可以将表重排到下一页的功能很棒,但并不总是我想要的。 In the case table or figure fits well in the page and it is not necessarily anchored to a paragraph, there is no reason to reflow it. 如果表或图形非常适合页面,并且不一定要固定在段落上,则没有理由对其进行重排。 It would be better to make it “floating” outside the body of the page. 最好使其“浮动”在页面主体之外。

This answer is really inspiring but I am not sure how to apply it to my case. 这个答案确实令人鼓舞,但我不确定如何将其应用于我的案子。 I would be happy if I could do it according to a @rendition attribute of the 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>

As Tony Graham commented, FOP does not support before floats yet (strangely enough, it silently swallows them without a warning). 正如Tony Graham所评论的那样, FOP 在浮动之前还不支持 (奇怪的是,它在没有警告的情况下默默地吞下了它们)。

However, you could use footnotes instead to place your tables at the bottom of the pages in which they are referenced. 但是, 您可以改用脚注将表格放在引用它们的页面的底部。 If I remember correctly, FOP favours placing the footnotes in their entirety over adding more "flowing" content, so the result should be the expected one. 如果我没记错的话,FOP宁愿将脚注全部放入而不是添加更多的“流动”内容,因此结果应该是预期的。

FO example: 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>

Resulting output: 结果输出:

PDF截图

The downside of using footnotes is that the constraint on footnote placement is more strict than the one on before floats (which can be placed in a page following their anchor-area, as per section 6.12.2 of the recommentation ), so there could be layout problems (empty areas in the pages) if the input has many tables cited in a sequence of paragraphs. 使用脚注的不利之处在于,脚注放置的约束比浮动前的约束更严格根据建议6.12.2的规定 ,可以将脚注放置在其锚定区域之后的页面中),因此可能存在布局问题(页面中的空白区域),如果输入在一系列段落中引用了很多表。

(disclosure: I am a FOP developer, though not very active nowadays) (公开:我是一名FOP开发人员,尽管现在不是很活跃)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM