如何在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"for75%— 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"alongsidevertical-align="super". Some XSL-FO processors (like Apache FOP) prioritizebaseline-shiftfor 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
相关产品推荐
相关产品推荐

