You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在XSL中设置上标属性?附代码与效果需求

Fixing Superscript in Your XSL-FO Code

Hey there! Let's get that "th" superscript looking just right for your address text. Looking at your current code, the main issues are likely the fixed font size and potential inconsistencies in how your FO processor handles vertical alignment. Here's a refined version that should give you the expected output:

<fo:block>
  <fo:inline text-decoration="underline" font-weight="bold">
    29
    <fo:inline 
      vertical-align="super" 
      font-size="75%" 
      baseline-shift="super"
      font-weight="inherit">
      th
    </fo:inline>
    St,
  </fo:inline>.
</fo:block>

Key adjustments I made:

  • Relative font size: Swapped font-size="5pt" for 75% — this lets the superscript scale proportionally with the parent text (your bold, underlined "29") instead of being locked to a tiny fixed size that might look out of place if your base font changes.
  • Dual vertical alignment control: Added baseline-shift="super" alongside vertical-align="super". Some XSL-FO processors (like Apache FOP) prioritize baseline-shift for precise superscript positioning, so using both ensures broader compatibility.
  • Inherit bold styling: Added font-weight="inherit" to make sure the "th" matches the bold weight of the surrounding text, avoiding a thin, mismatched superscript.
  • Cleaner structure: Indented the code for readability, which makes it easier to tweak later if needed.

If you still see odd spacing around the superscript, try adding a line-height value to the parent fo:block (e.g., line-height="1.4") to give enough room for the raised text without messing up the line spacing.

内容的提问来源于stack exchange,提问作者Hanuman

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.25 03:38:39