(笔记:这是这个问题)
我用cgloss4e
它来写下一些语言示例。其中一些示例不适合一行,因此我尝试将其内容分散到多行,但这些行属于同一编号示例。
问题。当我将内容分散到多行上时,段落之间的间距似乎发生了意想不到的变化。
例子。
\documentclass{report}
\usepackage{xcolor}
\usepackage{polyglossia}
\usepackage[AutoFallBack=true]{xeCJK}[2018/02/27]
\setCJKmainfont[FallBack=NotoSansCJKtc-Regular]{NotoSerifCJKtc-Regular}
% NOTE: download NotoSerifCJKtc-Regular font from here
% https://www.google.com/get/noto/help/cjk/
\usepackage{xpinyin}
\usepackage{gb4e}
\let\eachwordtwo=\pinyin
\newcommand{\glit}[1]{\nobreak\glt {\it ``{#1}''}}
\makeatletter
\newcommand*\glosscolor[1]{\gdef\@glcolor{#1}}
\glosscolor{red}
\AtBeginDocument{\colorlet{savedcol}{.}}
\def\@glosscolor{savedcol}
\newcommand{\clt}{\gdef\@glosscolor{\@glcolor}\color{\@glosscolor}}
\newcommand{\clf}{\gdef\@glosscolor{savedcol}\color{\@glosscolor}}
\gdef\getwords(#1,#2)#3 #4\\% #1=linebox, #2=\each, #3=1st word, #4=remainder
{\setbox#1=\vbox{\hbox{#2{\strut\color{\@glosscolor}#3} }% adds space
\unvbox#1%
}%
\def\more{#4}%
\ifx\more\empty\let\more=\donewords
\else\let\more=\getwords
\fi
\more(#1,#2)#4\\%
}
\gdef\donewords(#1,#2)\\{\gdef\@glosscolor{savedcol}}
\makeatother
\begin{document}
Normal spacing:
\begin{exe}
\ex
\glll
你 \clt 為甚麼 \clf 學 中文 ? \\
ni3 \clt wei4shen2me \clf xue2 Zhong1wen2 ? \\
You \clt why \clf study Chinese ? \\
\glit
{Why do you study Chinese?}
\ex
\glll
\clt 因為 \clf 我 在 中國 工作 \\
\clt Yin1wei4 \clf wo3 zai4 Zhong1guo2 gong1zuo4 \\
\clt Because \clf I in China working \\
\glit
{Because I am working in China}
\end{exe}
Incorrect spacing:
\begin{exe}
\ex
\glll
你 \clt 為甚麼 \clf 學 中文 ? \\
ni3 \clt wei4shen2me \clf xue2 Zhong1wen2 ? \\
You \clt why \clf study Chinese ? \\
\glit
{Why do you study Chinese?}
\glll
\clt 因為 \clf 我 在 中國 工作 \\
\clt Yin1wei4 \clf wo3 zai4 Zhong1guo2 gong1zuo4 \\
\clt Because \clf I in China working \\
\glit
{Because I am working in China}
\end{exe}
\end{document}
输出。
通常,命令所括起来的行glit
会直接放置在三行示例的下方。
但是,当我删除ex
因为我想要多个具有相同数字的三行时,间距会发生变化。在上图中,可以清楚地看到句子“因为我在中国工作”放置在距离其对应文本较远的位置。
理想情况下,我希望能够使多个glll
组属于同一ex
编号示例,而不存在这些间距问题。
问题。为什么会发生这种情况?我该如何解决?
答案1
不必要的垂直间距是由flushleft
环境引起的。请参见这个答案了解描述。
新答案
由于我们要修补很多命令,我建议使用etoolbox
包。这种方法使你的序言代码更简洁,更容易理解。而且,你不需要复制完整的原始定义来cgloss4e.sty
进行调整。
\documentclass{report}
\usepackage{xcolor}
\usepackage[english]{babel}
% Not needed for this problem
%\usepackage{polyglossia}
%\usepackage[AutoFallBack=true]{xeCJK}[2018/02/27]
%\setCJKmainfont[FallBack=SimSun-ExtB]{SimSun}
% Removed!
% Removed!
% Removed!
\usepackage{xpinyin}
\usepackage{gb4e}
\let\eachwordtwo=\pinyin
%\newcommand{\glit}[1]{\nobreak\glt {\it ``{#1}''}}
% I changed your original definition of \glit:
\newcommand{\glit}[1]{\glt ``\emph{#1}''\par}
\usepackage{etoolbox}% https://ctan.org/pkg/etoolbox
\makeatletter% Group everything to save the trouble
% My patches:
\patchcmd{\gll}% The command to be patched
{\begin{flushleft}}% Code to be replaced
{\begingroup\raggedright}% New code
{}{}
\patchcmd{\glll}% The command to be patched
{\begin{flushleft}}% Code to be replaced
{\begingroup\raggedright}% New code
{}{}
\patchcmd{\gl@stop}% The command to be patched
{\end{flushleft}}% Code to be replaced
{\endgroup}% New code
{}{}
% Your color customization:
\newcommand*\glosscolor[1]{\gdef\@glcolor{#1}}
\glosscolor{red}
\AtBeginDocument{\colorlet{savedcol}{.}}
\def\@glosscolor{savedcol}
\newcommand{\clt}{\gdef\@glosscolor{\@glcolor}\color{\@glosscolor}}
\newcommand{\clf}{\gdef\@glosscolor{savedcol}\color{\@glosscolor}}
% Your patch written in the style of \patchcmd:
\patchcmd{\getwords}% The command to be patched
{\strut#3}% Code to be replaced
{\strut\color{\@glosscolor}#3}% New code
{}{}
\gdef\donewords(#1,#2)\\{\gdef\@glosscolor{savedcol}}
\makeatother
\begin{document}
Normal spacing:
\begin{exe}
\ex
\glll
a \clt aaa \clf a aa ? \\
ni3 \clt wei4shen2me \clf xue2 Zhong1wen2 ? \\
You \clt why \clf study Chinese ? \\
\glit
{Why do you study Chinese?}
\ex
\glll
\clt aa \clf a a aa aa \\
\clt Yin1wei4 \clf wo3 zai4 Zhong1guo2 gong1zuo4 \\
\clt Because \clf I in China working \\
\glit
{Because I am working in China}
\end{exe}
Incorrect spacing (now corrected):
\begin{exe}
\ex
\glll
a \clt aaa \clf a aa ? \\
ni3 \clt wei4shen2me \clf xue2 Zhong1wen2 ? \\
You \clt why \clf study Chinese ? \\
\glit
{Why do you study Chinese?}
\glll
\clt aa \clf a a aa aa \\
\clt Yin1wei4 \clf wo3 zai4 Zhong1guo2 gong1zuo4 \\
\clt Because \clf I in China working \\
\glit
{Because I am working in China}
\end{exe}
\end{document}
原始答案
为了解决这个问题,我使用了一个补丁:
\makeatletter
\def\gll% % Introduces 2-line text-and-gloss.
{\begingroup\raggedright
\ifx\@gsingle1% conditionally force single spacing (hpk/MC)
\vskip\baselineskip\def\baselinestretch{1}%
\@selfnt\vskip-\baselineskip\fi%
\bgroup
\twosent
}
\def\glll% % Introduces 3-line text-and-gloss.
{\begingroup\raggedright
\ifx\@gsingle1% conditionally force single spacing (hpk/MC)
\vskip\baselineskip\def\baselinestretch{1}%
\@selfnt\vskip-\baselineskip\fi%
\bgroup
\threesent
}
\def\gl@stop{{\hskip -\glossglue}\unhbox\gline\endgroup}
\makeatother
为了获得正确的段落分隔符,我还改变了您的定义\glit
:
\newcommand{\glit}[1]{\nobreak\glt {\it ``{#1}''}\par}
完整的 MWE:
\documentclass{report}
\usepackage{xcolor}
\usepackage[english]{babel}
% Not needed for your problem
%\usepackage{polyglossia}
%\usepackage[AutoFallBack=true]{xeCJK}[2018/02/27]
%\setCJKmainfont[FallBack=SimSun-ExtB]{SimSun}
% Removed!
% Removed!
% Removed!
\usepackage{xpinyin}
\usepackage{gb4e}
\let\eachwordtwo=\pinyin
%\newcommand{\glit}[1]{\nobreak\glt {\it ``{#1}''}}
% I changed your original definition
\newcommand{\glit}[1]{\nobreak\glt {\it ``{#1}''}\par}
\makeatletter
% My patches:
\def\gll% % Introduces 2-line text-and-gloss.
{\begingroup\raggedright
\ifx\@gsingle1% conditionally force single spacing (hpk/MC)
\vskip\baselineskip\def\baselinestretch{1}%
\@selfnt\vskip-\baselineskip\fi%
\bgroup
\twosent
}
\def\glll% % Introduces 3-line text-and-gloss.
{\begingroup\raggedright
\ifx\@gsingle1% conditionally force single spacing (hpk/MC)
\vskip\baselineskip\def\baselinestretch{1}%
\@selfnt\vskip-\baselineskip\fi%
\bgroup
\threesent
}
\def\gl@stop{{\hskip -\glossglue}\unhbox\gline\endgroup}
% Your patches:
\newcommand*\glosscolor[1]{\gdef\@glcolor{#1}}
\glosscolor{red}
\AtBeginDocument{\colorlet{savedcol}{.}}
\def\@glosscolor{savedcol}
\newcommand{\clt}{\gdef\@glosscolor{\@glcolor}\color{\@glosscolor}}
\newcommand{\clf}{\gdef\@glosscolor{savedcol}\color{\@glosscolor}}
\gdef\getwords(#1,#2)#3 #4\\% #1=linebox, #2=\each, #3=1st word, #4=remainder
{\setbox#1=\vbox{\hbox{#2{\strut\color{\@glosscolor}#3} }% adds space
\unvbox#1%
}%
\def\more{#4}%
\ifx\more\empty\let\more=\donewords
\else\let\more=\getwords
\fi
\more(#1,#2)#4\\%
}
\gdef\donewords(#1,#2)\\{\gdef\@glosscolor{savedcol}}
\makeatother
\begin{document}
Normal spacing:
\begin{exe}
\ex
\glll
a \clt aaa \clf a aa ? \\
ni3 \clt wei4shen2me \clf xue2 Zhong1wen2 ? \\
You \clt why \clf study Chinese ? \\
\glit
{Why do you study Chinese?}
\ex
\glll
\clt aa \clf a a aa aa \\
\clt Yin1wei4 \clf wo3 zai4 Zhong1guo2 gong1zuo4 \\
\clt Because \clf I in China working \\
\glit
{Because I am working in China}
\end{exe}
Incorrect spacing:
\begin{exe}
\ex
\glll
a \clt aaa \clf a aa ? \\
ni3 \clt wei4shen2me \clf xue2 Zhong1wen2 ? \\
You \clt why \clf study Chinese ? \\
\glit
{Why do you study Chinese?}
\glll
\clt aa \clf a a aa aa \\
\clt Yin1wei4 \clf wo3 zai4 Zhong1guo2 gong1zuo4 \\
\clt Because \clf I in China working \\
\glit
{Because I am working in China}
\end{exe}
\end{document}
边注
SimSun
SimSun
是北京中意电子有限公司的商标,已独家授权给微软。在 Windows 操作系统之外使用可能被视为商标侵权。如果您想要“衬线”风格的 CJK 字体,请考虑使用来源宋体2017 年发布的字体,免费且开源。您也可以从Google Noto 字体网站。
如果你想使用其他开源 CJK 字体,请查看中文开源字体集(从你的字符笔画来看,网站是香港繁体中文的甚
)。