CTeX-org / ctex-kit

Macro Packages and Scripts for Chinese TeX users
965 stars 124 forks source link

ctexart 生成的 pdf 中长标题的行间距比 baselineskip 的值大 #699

Closed lrtfm closed 4 months ago

lrtfm commented 4 months ago

下面是一个长标题的例子, 当把标题字体和段落字体设置一致的时候, 标题的行距明显大于段落的行距. 但是输出显示 baselineskip 是相同的, 这是为什么? 怎么能调整一致?

\documentclass{ctexart}

\ctexset{%
    section={%
        format=\large,
        hang=false,
    }
}
\newcommand{\lhead}{很长很长很长很长很长很长很长很长}
\newcommand{\llhead}{\lhead\lhead\lhead\lhead\lhead}
\newcommand{\mytest}{\llhead 的句子 baselineskip=\the\baselineskip}

\begin{document}

\section{\mytest}
{\large\mytest}
\end{document}

使用 xelatex 编译的结果如下:

长标题行间距

从这里可以明显看出 \section{\mytest} 的行间距比段落 {\large\mytest} 的行间距要大.

muzimuzhi commented 4 months ago

标题的行距是正常的,是 {\large\mytest} 的行距偏小了。用 {\large\mytest\par} 就得到正常的、\large 时的行距了。

{\large\mytest} 相当于 {\large\mytext}\par,这是在段落中间修改字号和行距。这时候最终应用的 \baselineskip\normalsize 时的行距。(也许在 texdoc texbytopic 有讲,我没去找。)

下面的例子里,\Huge 的输出效果更为明显:

\documentclass{article}

\newcommand{\lhead}{XXX XXX XXX XXX XXX \newline}
\newcommand{\llhead}{\noindent\lhead\lhead\lhead\lhead\lhead}

\begin{document}
{\large\llhead}\par
{\large\llhead\par}

{\Huge\llhead}\par
{\Huge\llhead\par}
\end{document}

image image

muzimuzhi commented 4 months ago

TeX 里,每个段落内部的行距是固定值,它是段落结束时 \baselineskip 的值。

参考这个回答 https://tex.stackexchange.com/a/45398

And there is another problem with this setup: you change the \baselineskip midway as you are changing the font size for the description. But again TeX only looks once at the \baselineskip for a paragraph (when it hits \par). Thus your first two lines would already be in the smaller baselineskip but with a larger font.

lrtfm commented 4 months ago

感谢您的解释. 根据您的提示, 我看了下 texdoc texbytopic , 在 15.4 节有如下说明:

The amount of leading cannot be changed in the middle of a paragraph, because the value for \baselineskip that is used is the one that is current when the paragraph is finally broken and added to the main vertical list. The same holds for the \lineskip and \lineskiplimit.