[Tex/LaTex] Displaying pinyin over Chinese characters, without impacting word spacing

cjkspacingxecjkxetex

I want to display pinyin (romanized form) over Chinese characters. However, the two methods I know (using stackrel or tabular both change the spacing between characters. This demonstrates the problem:

\documentclass[a5paper]{article}
\usepackage{ctexcap}
\usepackage{stackrel}
\setCJKmainfont{Adobe Heiti Std}
\newcommand{\mymacroone}[1]{$\stackrel{a}{\textrm{#1}}$}
\newcommand{\mymacrotwo}[1]{\begin{tabular}{l}a\\#1\end{tabular}}
\begin{document}
    \Huge \noindent 床前明月光,疑是地上霜。举头望明月,低头思故乡。 \\
    \mymacroone{床}\mymacroone{前}\mymacroone{明}\mymacroone{月}\mymacroone{光},\mymacroone{疑}\mymacroone{是}\mymacroone{地}\mymacroone{上}\mymacroone{霜}。\mymacroone{举}\mymacroone{头}\mymacroone{望}\mymacroone{明}\mymacroone{月},\mymacroone{低}\mymacroone{头}\mymacroone{思}\mymacroone{故}\mymacroone{乡}。 \\
    \mymacrotwo{床}\mymacrotwo{前}\mymacrotwo{明}\mymacrotwo{月}\mymacrotwo{光},\mymacrotwo{疑}\mymacrotwo{是}\mymacrotwo{地}\mymacrotwo{上}\mymacrotwo{霜}。\mymacrotwo{举}\mymacrotwo{头}\mymacrotwo{望}\mymacrotwo{明}\mymacrotwo{月},\mymacrotwo{低}\mymacrotwo{头}\mymacrotwo{思}\mymacrotwo{故}\mymacrotwo{乡}。 \\
\end{document}

Each of the three lines should be displaying the same.

  • With stackrel, the words are spaced too closely together. This problem is not created by stackrel. It is from having math mode with textrm{} inside.
  • With tabular, the words are spaced too far apart, they do not properly break at the end of the line, and it has a strange vertical and horizontal alignment problems. Using stackrel would be ideal.

How can I place pinyin above Chinese characters without changing the spacing between the characters (at least in situations where the pinyin is shorter than the characters)?

Best Answer

Now I add another answer using LI Qing's xpinyin package.

It's rather easy to use:

\documentclass{ctexart}

\usepackage{xpinyin}

\begin{document}
\Huge\sffamily

\begin{pinyinscope}
床前明月光,疑是地上霜。举头望明月,低头思故乡。
\end{pinyinscope}

\xpinyin*{床前明月光,疑是地上霜。举头望明月,低头思故乡。}

\end{document}

enter image description here