user219882
user219882

Reputation: 15844

XSL-FO - figure and caption alignment

I was hoping that the following code would align the block with caption and image to the center but it's still aligned to the left. I was trying the same thing with a table layout and it didn't help either.

<fo:block text-align="center">
    <fo:block text-align="left">
        <fo:external-graphic src="url('{imagedata/@fileref}')" content-width="scale-to-fit"
                scaling="uniform">
            <xsl:choose>
                <xsl:when test="imagedata/@width">
                    <xsl:attribute name="width"><xsl:value-of select="imagedata/@width" /></xsl:attribute>
                </xsl:when>
                <xsl:otherwise>
                    <xsl:attribute name="width">60%</xsl:attribute>
                </xsl:otherwise>
            </xsl:choose>
        </fo:external-graphic>
        <fo:block font-weight="bold" space-after="0.5cm">
            <xsl:text>Figure </xsl:text>
            <xsl:value-of select="count(preceding::imageobject) + 1" />
            <xsl:text>: </xsl:text>
            <xsl:value-of select="caption" />
        </fo:block>
    </fo:block>
</fo:block>

Upvotes: 0

Views: 5240

Answers (2)

AechoLiu
AechoLiu

Reputation: 18428

I saw an example, in antennahourse.com.

It use display-align="center" to center image in block.


Sample pdf

Sample image

Codes

    <fo:block space-before="1.2em">The arrangement of the loaded graphics in fo:block can be adjusted by display-align, text-align. The following example shows the center arrangement by specifying display-align="center", text-align="center".</fo:block>
<fo:block>
   <fo:external-graphic src="./sunflower.jpg" border-style="dotted" border-width="thin" width="9.0cm" height="6.0cm" content-width="5.0cm" content-height="3.5cm" display-align="center" text-align="center" />
  </fo:block>

Upvotes: 0

Paul
Paul

Reputation: 4259

You have nested center and left on your alignment of the first two blocks.

This should correct it:

<fo:block text-align="center">
  <fo:block text-align="center">
    ...
  </fo:block>
</fo:block>

Upvotes: 1

Related Questions