【问题】
Docbook中,之前已经可以实现等的居中对齐了,以及也实现了formal(figure,table,equation等)的标题的中间对齐:
现在对于其中输出的上述的formal的主题内容,即表格table,equation等内容,也想要让其居中对齐,这样才和标题统一。而这部分的需求,对于输出的PDF中,本身由于是自动填充了pdf中的页面的宽度,所以是已经实现了,不需要额外设置,而HTML中,由于默认是左对齐的,所以需要额外设置。
目前的效果是这样的:
希望将HTML中的表格等formal的主体内容,也都是设置为中间对齐。
【解决过程】
1.刚开始不知道如何去设置。
后来想到了,对于原先普通的word文档,其可以另存为HTML网页的,然后可以先去将其中的表格部分设置为中间对齐,然后参考其源码,看看其源码是如何写的,然后再想办法把对应的配置参数,加入到HTML的xsl配置文件中去。
然后就去找了个之前的word,设置某表格为中间对齐,然后另存为HTMl,然后得到其相应源码为:
可以看到,对于表格主体内容对齐的话,是对应的div中添加align为center,即可。
2.然后就去找HTML的xsl配置,哪里对应着这个表格主体内容的div的。
尝试了几次后,得到了正确的位置,即
docbook-xsl-ns-1.76.1\html\formal.xsl
中formal.object的配置部分中的class="{$class}-contents"的div,然后添加了对应align为center:
<!--============================================================================
formal(figure/table/equation/example/...) setting
=============================================================================-->
<!-- follow are copied from docbook-xsl-ns-1.76.1\html\formal.xsl -->
<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"> -->
<p class="title" align="center"> <!-- add align to center of header for table/figure/... -->
<b>
<xsl:copy-of select="$title"/>
</b>
</p>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="formal.object">
<xsl:param name="placement" select="'before'"/>
<xsl:param name="class">
<xsl:apply-templates select="." mode="class.value"/>
</xsl:param>
<xsl:call-template name="id.warning"/>
<xsl:variable name="content">
<div class="{$class}">
<xsl:call-template name="anchor">
<xsl:with-param name="conditional" select="0"/>
</xsl:call-template>
<xsl:choose>
<xsl:when test="$placement = 'before'">
<xsl:call-template name="formal.object.heading"/>
<!-- <div class="{$class}-contents"> -->
<div class="{$class}-contents" align="center" > <!-- add align to center for body of table/figure/.. -->
<xsl:apply-templates/>
</div>
<!-- HACK: This doesn't belong inside formal.object; it
should be done by the table template, but I want
the link to be inside the DIV, so... -->
<xsl:if test="local-name(.) = 'table'">
<xsl:call-template name="table.longdesc"/>
</xsl:if>
<xsl:if test="$spacing.paras != 0"><p/></xsl:if>
</xsl:when>
<xsl:otherwise>
<xsl:if test="$spacing.paras != 0"><p/></xsl:if>
<div class="{$class}-contents"><xsl:apply-templates/></div>
<!-- HACK: This doesn't belong inside formal.object; it
should be done by the table template, but I want
the link to be inside the DIV, so... -->
<xsl:if test="local-name(.) = 'table'">
<xsl:call-template name="table.longdesc"/>
</xsl:if>
<xsl:call-template name="formal.object.heading"/>
</xsl:otherwise>
</xsl:choose>
</div>
<xsl:if test="not($formal.object.break.after = '0')">
<br class="{$class}-break"/>
</xsl:if>
</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="class"><xsl:value-of
select="$class"/>-float</xsl:with-param>
<xsl:with-param name="floatstyle" select="$floatstyle"/>
<xsl:with-param name="content" select="$content"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:copy-of select="$content"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>得到了想要的效果,即HTML中表格等主体内容,也是中间对齐了:
【总结】
想要设置HTML中formal的(除了标题title外的)主体内容也是中间对齐的话,是要找到HTML的xsl中关于formal的设置,是在docbook-xsl-ns-1.76.1\html\formal.xsl中的
<xsl:template name="formal.object">
然后把对应的:
<div class="{$class}-contents">
改为:
<div class="{$class}-contents" align="center" >
即可实现HTML中输出的formal(表格,图片等)的主体内容部分,都是中间对齐了。
转载请注明:在路上 » 【已解决】Docbook中输出HTML的表格设置为居中对齐

