问题:
如果文本中没有标点符号,中文单词可以垂直对齐,但是,如果我添加标点符号,标点符号就会错位,例如 使用XeLatex编译,代码:
%!TeX program = XeLaTeX
\documentclass{article}
\documentclass{article}
\usepackage{xeCJK}
\setCJKmainfont{Noto Sans CJK TC}
\usepackage[overlap,CJK]{ruby}
\usepackage{setspace}
\usepackage{geometry}
\usepackage{parskip}
% Margin Settings
\geometry{
a4paper,
total={170mm,257mm},
left=25mm,
right=25mm,
top=30mm,
bottom=20mm
}
% Chinese Pinyin Setttings
\renewcommand\rubysep{-3em}
\renewcommand{\CJKglue}{\hskip 14}
\renewcommand\rubysize{0.6}
\let\oldruby\ruby
\def\ruby#1#2{\oldruby{#1}{#2}\futurelet\next\addCJKglue}
\def\addCJKglue{\ifx\next\ruby \CJKglue \fi}
\newcommand{\myruby}[2]{\renewcommand\rubysep{-3em}{\chn\ruby{#1}{\textsf{#2}}}}
\newenvironment{chineseenvcustom}[2][2]
{
\begin{spacing}{#1}
\huge \justifying\renewcommand{\CJKglue}{\hskip #2}}
{\end{spacing}}
\begin{document}
\begin{chineseenvcustom}{12}
\ruby{彌}{Mí}\ruby{勒}{Lè}\ruby{世}{Shì}\ruby{尊}{Zūn}~\ruby{,}{}\ruby{既}{Jì}\ruby{慈}{Cí}\ruby{隆}{Lóng}\ruby{即}{Jí}\ruby{世}{Shì}~\ruby{,}{}\ruby{悲}{Bēi}\ruby{臻}{Zhēn}\ruby{後}{Hòu}\ruby{劫}{Jié}~\ruby{,}{}\ruby{依}{Yī}\ruby{事}{Shì}\ruby{題}{Tí}\ruby{名}{Míng}\ruby{弗}{Fú}\ruby{敢}{Gǎn}\ruby{移}{Yí}\ruby{易}{Yì}~\ruby{.}{}\ruby{承}{Chéng}\ruby{此}{Cǐ}\ruby{念}{Niàn}\ruby{力}{Lì}~\ruby{,}{}\ruby{欲}{Yù}\ruby{守}{Shǒu}\ruby{護}{Hù}\ruby{三}{Sān}\ruby{寶}{Bǎo}~\ruby{,}{}\ruby{令}{Lìng}\ruby{魔}{Mó}\ruby{隱}{Yǐn}\ruby{蔽}{Bì}~\ruby{.}{}\ruby{摧}{Cūi}\ruby{伏}{Fú}\ruby{自}{Zì}\ruby{大}{Dà}\ruby{增}{Zēng}\ruby{上}{Shàng}\ruby{慢}{Màn}\ruby{者}{Zhě}~\ruby{,}{}\ruby{未}{Wèi}\ruby{種}{Zhòng}\ruby{善}{Shàn}\ruby{根}{Gēn}\ruby{者}{Zhě}~\ruby{,}{}\ruby{今}{Jīn}\ruby{當}{Dāng}\ruby{令}{Lìng}\ruby{種}{Zhòng}~\ruby{.}{}\ruby{已}{Yǐ}\ruby{種}{Zhòng}\ruby{善}{Shàn}\ruby{根}{Gēn}\ruby{者}{Zhě}~\ruby{,}{}\ruby{今}{Jīn}\ruby{令}{Lìng}\ruby{增}{Zēng}\ruby{長}{Zhǎng}~\ruby{.}{}\ruby{若}{Ruò}\ruby{計}{Jì}\ruby{有}{Yǒu}\ruby{所}{Suǒ}\ruby{得}{Dé}~\ruby{,}{}\ruby{住}{Zhù}\ruby{諸}{Zhū}\ruby{見}{Jiàn}\ruby{者}{Zhě}~\ruby{,}{}\ruby{皆}{Jiē}\ruby{悉}{Xī}\ruby{令}{Lìng}\ruby{發}{Fā}\ruby{捨}{Shě}\ruby{離}{Lí}\ruby{之}{Zhī}\ruby{心}{Xīn}~\ruby{.}{}\ruby{樂}{Lè}\ruby{小}{Xiǎo}\ruby{法}{Fǎ}\ruby{者}{Zhě}~\ruby{,}{}\ruby{令}{Lìng}\ruby{不}{Bù}\ruby{疑}{Yí}\ruby{大}{Dà}\ruby{法}{Fǎ}~\ruby{.}{}\ruby{樂}{Lè}\ruby{大}{Dà}\ruby{法}{Fǎ}\ruby{者}{Zhě}~\ruby{,}{}\ruby{令}{Lìng}\ruby{生}{Shēng}\ruby{歡}{Huān}\ruby{喜}{Xǐ}~\ruby{.}{}
\end{chineseenvcustom}
\end{document}
问题:
能不能让标点符号不占空格,比如放在前一个字符的右上角,那么非标点符号的汉字也能对齐。
参考:
同样的问题:有没有不占用空间的标点符号?。但是因为我用rudy给汉字添加拼音,所以那里建议的方法不再起作用了。
任何帮助都值得赞赏,提前谢谢您:)
答案1
您可以添加一个特殊助手\punct
,它用于代替 ruby 来表示标点符号。这将阻止 \futurelet 检测 ruby,从而抑制粘连。在 中\punct
,\rlap
可用于“隐藏”标记的宽度:
%!TeX program = XeLaTeX
\documentclass{article}
\usepackage{xeCJK}
\setCJKmainfont{Noto Sans CJK TC}
\usepackage[overlap,CJK]{ruby}
\usepackage{setspace}
\usepackage{geometry}
\usepackage{parskip}
% Margin Settings
\geometry{
a4paper,
% total={170mm,257mm}, % If you provide the paper size and margins, additionally specifying the text area size doesn't make sense: It will be calculated automatically.
left=25mm,
right=25mm,
top=30mm,
bottom=20mm
}
% Chinese Pinyin Setttings
\renewcommand\rubysep{-3em}
\renewcommand{\CJKglue}{\hskip 14pt} % \hskip doesn't work without a unit
\renewcommand\rubysize{0.6}
\let\oldruby\ruby
\let\justifying\relax% You used \justifying but that command isn't defined, so I added this to avoid errors. You probably want to delete this line.
\newcommand\punct[1]{% This is the important part: \rlap hides the width, \futurelet... like in \ruby ensures that after the mark glue is inserted as if the mark wasn't there
\rlap{#1}%
\futurelet\next\addCJKglue
}
\def\ruby#1#2{\oldruby{#1}{#2}\futurelet\next\addCJKglue}
\def\addCJKglue{\ifx\next\ruby \CJKglue \fi}
\newcommand{\myruby}[2]{\renewcommand\rubysep{-3em}{\chn\ruby{#1}{\textsf{#2}}}}
\newenvironment{chineseenvcustom}[2][2]
{%
\rightskip=0pt plus 1em\relax% This avoids overfull boxes by allowing some flexibility at the right border
\begin{spacing}{#1}%
\huge \justifying\renewcommand{\CJKglue}{\hskip #2pt\relax}}
{\end{spacing}}
\begin{document}
\begin{chineseenvcustom}{12}
\ruby{彌}{Mí}\ruby{勒}{Lè}\ruby{世}{Shì}\ruby{尊}{Zūn}{}\punct{,}\ruby{既}{Jì}\ruby{慈}{Cí}\ruby{隆}{Lóng}\ruby{即}{Jí}\ruby{世}{Shì}\punct{,}\ruby{悲}{Bēi}\ruby{臻}{Zhēn}\ruby{後}{Hòu}\ruby{劫}{Jié}\punct{,}\ruby{依}{Yī}\ruby{事}{Shì}\ruby{題}{Tí}\ruby{名}{Míng}\ruby{弗}{Fú}\ruby{敢}{Gǎn}\ruby{移}{Yí}\ruby{易}{Yì}\punct{.}\ruby{承}{Chéng}\ruby{此}{Cǐ}\ruby{念}{Niàn}\ruby{力}{Lì}\punct{,}\ruby{欲}{Yù}\ruby{守}{Shǒu}\ruby{護}{Hù}\ruby{三}{Sān}\ruby{寶}{Bǎo}\punct{,}\ruby{令}{Lìng}\ruby{魔}{Mó}\ruby{隱}{Yǐn}\ruby{蔽}{Bì}\punct{.}\ruby{摧}{Cūi}\ruby{伏}{Fú}\ruby{自}{Zì}\ruby{大}{Dà}\ruby{增}{Zēng}\ruby{上}{Shàng}\ruby{慢}{Màn}\ruby{者}{Zhě}\punct{,}\ruby{未}{Wèi}\ruby{種}{Zhòng}\ruby{善}{Shàn}\ruby{根}{Gēn}\ruby{者}{Zhě}\punct{,}\ruby{今}{Jīn}\ruby{當}{Dāng}\ruby{令}{Lìng}\ruby{種}{Zhòng}\punct{.}\ruby{已}{Yǐ}\ruby{種}{Zhòng}\ruby{善}{Shàn}\ruby{根}{Gēn}\ruby{者}{Zhě}\punct{,}\ruby{今}{Jīn}\ruby{令}{Lìng}\ruby{增}{Zēng}\ruby{長}{Zhǎng}\punct{.}\ruby{若}{Ruò}\ruby{計}{Jì}\ruby{有}{Yǒu}\ruby{所}{Suǒ}\ruby{得}{Dé}\punct{,}\ruby{住}{Zhù}\ruby{諸}{Zhū}\ruby{見}{Jiàn}\ruby{者}{Zhě}\punct{,}\ruby{皆}{Jiē}\ruby{悉}{Xī}\ruby{令}{Lìng}\ruby{發}{Fā}\ruby{捨}{Shě}\ruby{離}{Lí}\ruby{之}{Zhī}\ruby{心}{Xīn}\punct{.}\ruby{樂}{Lè}\ruby{小}{Xiǎo}\ruby{法}{Fǎ}\ruby{者}{Zhě}\punct{,}\ruby{令}{Lìng}\ruby{不}{Bù}\ruby{疑}{Yí}\ruby{大}{Dà}\ruby{法}{Fǎ}\punct{.}\ruby{樂}{Lè}\ruby{大}{Dà}\ruby{法}{Fǎ}\ruby{者}{Zhě}\punct{,}\ruby{令}{Lìng}\ruby{生}{Shēng}\ruby{歡}{Huān}\ruby{喜}{Xǐ}\punct{.}
\end{chineseenvcustom}
\end{document}