5

How can I place some text centered below other text on the line?

I want to create similar to results to what is found in the ruby package, but instead of placing text above, the extra text is put below the baseline text. In the source code (see ruby.sty), I think I have found the code which places #2 above #1 in \ruby{}{}:

{\@tempdimc \f@size\p@
\@tempdimc \rubysize\@tempdimc
\sbox\z@{\vrule\@height.7\baselineskip\@depth\z@\@width\z@ #1}
\sbox\@tempboxa{\fontsize{\@tempdimc}{1.2\@tempdimc}\selectfont
    \vrule\@height\z@\@depth.3\baselineskip\@width\z@ #2}
  • It is possible that ruby.sty already provides this feature, but I could not find any mention of this in the documentation (see ruby.txt).

I have also tried these, but the results are a bit different:

  • $\stackrel[below]{above}{middle}$, but I do not need any text above.

  • $\underbrace{above}_{\hbox{below}}$, but I do not need the underbrace.

I would prefer if the format and distance copied that of \ruby{}{}.

4

This may require some tweaking when using different font sizes, but it seems sufficient in terms of the standard article document class, as shown in the following minimal example:

\ruby duplicate with top/bottom text

\documentclass{article}
\usepackage{ruby}% http://ctan.org/pkg/cjk
\usepackage{lmodern}% http://ctan.org/pkg/lm

\makeatletter
\newcommand{\rubytop}[2]{%
  \@tempdimc \f@size\p@
  \begin{tabular}[b]{@{}c@{}}
    \fontsize{.4\@tempdimc}{.48\@tempdimc}\selectfont%
    \setlength{\normalbaselineskip}{0pt}#1\\[-4.3pt]
    #2
  \end{tabular}%
}
\newcommand{\rubybot}[2]{%
  \@tempdimc \f@size\p@
  \begin{tabular}[t]{@{}c@{}}
    #2\\[-6.7pt]
    \fontsize{.4\@tempdimc}{.48\@tempdimc}\selectfont%
    \setlength{\normalbaselineskip}{0pt}#1
  \end{tabular}%
}
\makeatother

\begin{document}
one \ruby{one}{two} two \ruby{two}{one} one \rubytop{one}{two} two \rubybot{two}{one} one
\end{document}

The two new commands provided are \rubytop{<top>}{<bot>} and \rubybot{<bot>}{<top>}. The former duplicates \ruby{<bot>}{<top>} but uses a tabular, while the latter reverses the process.

ruby is not required if using \rubytop and \rubybot, nor does it have all the other fancy \ruby add-ons (like kern checking). The macros merely duplicate the output.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.