Question

I'm working with DockBook 4.5 and RenderX's XEP on Ubuntu 13.04. The DocBook translation are provided by Ubuntu.

I'm floating an image to the right (it works using XEP, but no FOP), and I need to add a margin to the image. It appears DocBook does not use a margin, so the text is jammed into the image.

DocBook has a page on Figure floats. Unfortunately, it makes no sense to me and the HTML examples don't apply.

DocBook also has a FO Parameter Reference page, but it does not list a property that includes all of figures, floats, and margins.

I tried adding the following overrides to my custom book-style.xsl (it was previously 0):

<xsl:attribute name="margin-left">6pt</xsl:attribute>
<xsl:attribute name="margin-right">6pt</xsl:attribute>

But it resulted in a number of errors:

Document book.xml does not validate
compilation error: file book-style.xsl line 16 element attribute
element attribute only allowed within a template, variable or param
compilation error: file book-style.xsl line 17 element attribute
element attribute only allowed within a template, variable or param
...

How does one specify a float margin for a figure or image?

Was it helpful?

Solution

As touched upon in a comment by the OP, just using the following is enough to introduce a margin on figures that float right or left:

<xsl:attribute-set name="figure.properties">
 <xsl:attribute name="margin-left">6pt</xsl:attribute>
 <xsl:attribute name="margin-right">6pt</xsl:attribute>
</xsl:attribute-set>

I think my original answer (below) was unnecessarily complicated.


The template named floater (see http://www.sagehill.net/docbookxsl/SideFloats.html#CustomSideFloat) outputs the fo:float formatting object. This template takes start.indent and end.indent parameters with default values of 0. These default values are unfortunately not changed when the figure template calls floater, resulting in the problem that you see.

You only need a small fix in the template matching figure to make it work (see the comment in the code below). So add the following to your customization layer:

<xsl:template match="figure">
  <xsl:variable name="param.placement"
              select="substring-after(normalize-space($formal.title.placement),
                                      concat(local-name(.), ' '))"/>

  <xsl:variable name="placement">
    <xsl:choose>
      <xsl:when test="contains($param.placement, ' ')">
        <xsl:value-of select="substring-before($param.placement, ' ')"/>
      </xsl:when>
      <xsl:when test="$param.placement = ''">before</xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="$param.placement"/>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:variable>

  <xsl:variable name="figure">
    <xsl:choose>
      <xsl:when test="@pgwide = '1'">
        <fo:block xsl:use-attribute-sets="pgwide.properties">
          <xsl:call-template name="formal.object">
            <xsl:with-param name="placement" select="$placement"/>
          </xsl:call-template>
        </fo:block>
      </xsl:when>
      <xsl:otherwise>
        <xsl:call-template name="formal.object">
          <xsl:with-param name="placement" select="$placement"/>
        </xsl:call-template>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:variable>

  <xsl:variable name="floatstyle">
    <xsl:call-template name="floatstyle"/>
  </xsl:variable>

  <xsl:choose>
    <xsl:when test="$floatstyle != ''">
      <xsl:call-template name="floater">
        <xsl:with-param name="position" select="$floatstyle"/>
        <xsl:with-param name="content" select="$figure"/>

        <!-- The following two lines added to introduce a 10pt 'margin' for floats (right or left) -->
        <xsl:with-param name="start.indent">10pt</xsl:with-param> 
        <xsl:with-param name="end.indent">10pt</xsl:with-param>

      </xsl:call-template>
    </xsl:when>
    <xsl:otherwise>
      <xsl:copy-of select="$figure"/>
    </xsl:otherwise>
  </xsl:choose>
</xsl:template>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top