最新消息:20210917 已从crifan.com换到crifan.org

【已解决】如何设置Docbook中的图片的标题为中间对齐

Docbook crifan 1989浏览 0评论

【问题】

docbook中的图片被设置为了center对齐:

HTML中图片标题是左对齐

接着也就想要把图片(和其他表格等)的标题,也设置为中间对齐,这样也才方便阅读。

【解决过程】

1.找到FO中有figure的设置:

figure.properties

所以去试试。但是没看出怎么改。

2. 后参考:Title fonts and sizes,去试试。

然后给HTML和PDF都添加了这个配置:

<!--============================================================================
formal(figure/table/equation/example/...) setting
=============================================================================-->
<!-- http://www.sagehill.net/docbookxsl/TitleFontSizes.html#FormalTitleProperties -->
<xsl:attribute-set name="formal.title.properties" 
                   use-attribute-sets="normal.para.spacing">
  <xsl:attribute name="font-weight">bold</xsl:attribute>
  <xsl:attribute name="font-size">12pt</xsl:attribute>
  <xsl:attribute name="hyphenate">false</xsl:attribute>
  <xsl:attribute name="space-after.minimum">0.4em</xsl:attribute>
  <xsl:attribute name="space-after.optimum">0.6em</xsl:attribute>
  <xsl:attribute name="space-after.maximum">0.8em</xsl:attribute>
  
  <xsl:attribute name="text-align">center</xsl:attribute>
</xsl:attribute-set>

然后生成的PDF中,图片的标题是中间对齐了:

pdf中 figure的title是中间对齐了

但是HTML中的图片的标题,还是左对齐。

3.后来又把上述设置,单独给FO了,然后对于HTML,又找到了

docbook-xsl-ns-1.76.1\html\formal.xsl

中相关的设置,然后添加了对应的text-align,变成:

<!--============================================================================
formal(figure/table/equation/example/...) setting
=============================================================================-->
<xsl:template name="formal.object.heading">
  <xsl:param name="object" select="."/>
  <xsl:param name="title">
    <xsl:apply-templates select="$object" mode="object.title.markup">
      <xsl:with-param name="allow-anchors" select="1"/>
    </xsl:apply-templates>
  </xsl:param>

  <xsl:choose>
    <xsl:when test="$make.clean.html != 0">
      <xsl:variable name="html.class" select="concat(local-name($object),'-title')"/>
      <div class="{$html.class}">
        <xsl:copy-of select="$title"/>
      </div>
    </xsl:when>
    <xsl:otherwise>
      <p class="title" text-align="center">
        <b>
          <xsl:copy-of select="$title"/>
        </b>
      </p>
    </xsl:otherwise>
  </xsl:choose>
</xsl:template>

然后生成的HTML中,还是没有中间对齐效果。

然后就想到了,顺便去看看生成的源码,然后发现,HTML语法高亮的源码中:

<p class="title" align="center"><b>图 1.4. Nand Flash引脚功能说明</b></p>

text-align是没有语法高亮的,所以突然想到了,HTML中,对应的text-align的是align,所以就去改为:

<!--============================================================================
formal(figure/table/equation/example/...) setting
=============================================================================-->
<xsl:template name="formal.object.heading">
  <xsl:param name="object" select="."/>
  <xsl:param name="title">
    <xsl:apply-templates select="$object" mode="object.title.markup">
      <xsl:with-param name="allow-anchors" select="1"/>
    </xsl:apply-templates>
  </xsl:param>

  <xsl:choose>
    <xsl:when test="$make.clean.html != 0">
      <xsl:variable name="html.class" select="concat(local-name($object),'-title')"/>
      <div class="{$html.class}">
        <xsl:copy-of select="$title"/>
      </div>
    </xsl:when>
    <xsl:otherwise>
      <p class="title" align="center">
        <b>
          <xsl:copy-of select="$title"/>
        </b>
      </p>
    </xsl:otherwise>
  </xsl:choose>
</xsl:template>

然后生成的HTML中,对应的图片等的标题,就都是中间对齐显示了:

 

HTML中图片的标题也可以是中间对齐了

【总结】

对于想要给figure的标题设置为中间对齐的话:

(1)对于PDF:

对应的FO中的配置为:

<!--============================================================================
formal(figure/table/equation/example/...) setting
=============================================================================-->
<!-- http://www.sagehill.net/docbookxsl/TitleFontSizes.html#FormalTitleProperties -->
<xsl:attribute-set name="formal.title.properties" 
                   use-attribute-sets="normal.para.spacing">
  <xsl:attribute name="font-weight">bold</xsl:attribute>
  <xsl:attribute name="font-size">12pt</xsl:attribute>
  <xsl:attribute name="hyphenate">false</xsl:attribute>
  <xsl:attribute name="space-after.minimum">0.4em</xsl:attribute>
  <xsl:attribute name="space-after.optimum">0.6em</xsl:attribute>
  <xsl:attribute name="space-after.maximum">0.8em</xsl:attribute>
  
  <xsl:attribute name="text-align">center</xsl:attribute>
</xsl:attribute-set>

其中上述除了text-align部分的配置,是在

docbook-xsl-ns-1.76.1\fo\formal.xsl

中拷贝出来的。

(2)对于HTML:

对应的html的配置是:

<!--============================================================================
formal(figure/table/equation/example/...) setting
=============================================================================-->
<xsl:template name="formal.object.heading">
  <xsl:param name="object" select="."/>
  <xsl:param name="title">
    <xsl:apply-templates select="$object" mode="object.title.markup">
      <xsl:with-param name="allow-anchors" select="1"/>
    </xsl:apply-templates>
  </xsl:param>

  <xsl:choose>
    <xsl:when test="$make.clean.html != 0">
      <xsl:variable name="html.class" select="concat(local-name($object),'-title')"/>
      <div class="{$html.class}">
        <xsl:copy-of select="$title"/>
      </div>
    </xsl:when>
    <xsl:otherwise>
      <p class="title" align="center">
        <b>
          <xsl:copy-of select="$title"/>
        </b>
      </p>
    </xsl:otherwise>
  </xsl:choose>
</xsl:template>

其中除了align="center"之外,都是从:

docbook-xsl-ns-1.76.1\html\formal.xsl

拷贝出来的。

转载请注明:在路上 » 【已解决】如何设置Docbook中的图片的标题为中间对齐

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
92 queries in 0.193 seconds, using 23.34MB memory