Since you like it, one can go further and improve support for complex ruby as follows:
ruby
{display:inline-table;
text-align:center;}
ruby > rt, rtc
{display:table-caption;}
ruby > rb, rbc, ruby > rt + rt, rtc + rtc
{display:table-row;}
rb, rbc, rt, rtc
{white-space:nowrap;}
rtc + rtc > rt, rbc > rb
{display:table-cell;}
rtc + rtc > rt[rbspan]
{column-span:attr(rbspan);}
ruby > rt, rtc
{font-size:0.5em;
line-height:1.2em;}
rp
{display:none;}
This improves horisontal alignment of ruby text placed under the base. Unfortunately this implementation does not handle text placed above the base as perfectly (due to display:table-caption used to format it). Here is
XHTML example and
PDF output.
To settle issue with complex annotations placed above the base one can write alternative implementation that handles horisontal alignment of ruby text better. Note however that if in previous two style sheets vertical alignment of ruby base was bullet proof regardless its content, this implementation assumes that ruby carries only simple content (no other complex layouts nested inside):
ruby
{display:inline-table;
text-align:center;
border-collapse:collapse;
/* border collapse mechanism
will be used to adjust vertical alignment */
vertical-align:middle;
/* if ruby text contains text only
and there are two ruby annotations
(one placed above the base and one below)
then vertical centering roughly aligns baseline of
base with baseline of parent */
border-bottom:solid 0.75em transparent;
/* o.75em is height of ruby text (0.5×1.2em = 0.6em)
plus space between baseline and text-bottom (about 0.15em)
this extra border is counter-weight used
to restore vertical centering broken
by presence of ruby text
(in case if there is only one ruby annotation,
if there are two annotations
then counter-weight is no longer
necessary and can be annihilated
using border collapse mechanism) */}
ruby > rt, rtc
{display:table-header-group;}
/* used to move first ruby
container above the base */
ruby > rb, rbc, ruby > rt + rt, rtc + rtc
{display:table-row;}
/* base and second ruby
are formatted as table-rows */
ruby > rt + rt, rtc + rtc
{border-bottom:hidden;}
/* if there are two annotations then extra
border is no longer necessary
and can be annihilated
using border collapse mechanism */
rb, rbc, rt, rtc
{white-space:nowrap;}
/* prohibits line breaks inside ruby text */
rtc > rt, rbc > rb
{display:table-cell;}
/* used to distribute annotations
in table like manner */
rtc > rt[rbspan]
{column-span:attr(rbspan);}
/* ruby text may span several cells */
ruby > rt, rtc
{font-size:0.5em;
line-height:1.2em;}
/* font-size of ruby text is reduced */
rp
{display:none;}
/* fallback markup is no longer necessary */
Here is
XHTML example of complex ruby and
PDF output.