![控制定理环境和标准文本之间的间距](https://linux22.com/image/456036/%E6%8E%A7%E5%88%B6%E5%AE%9A%E7%90%86%E7%8E%AF%E5%A2%83%E5%92%8C%E6%A0%87%E5%87%86%E6%96%87%E6%9C%AC%E4%B9%8B%E9%97%B4%E7%9A%84%E9%97%B4%E8%B7%9D.png)
我正在用来thmtools
排版定理。
我想要的输出如下:
\hrule
我的问题是关于控制定理环境上方和下方的 s之间的间距。
我希望 s 与定理上下段落之间的间距hrule
与两个相邻段落之间的间距相同。
我当前的 thmtools 代码是:
\declaretheoremstyle[
...definitions about fonts..
preheadhook=\vskip\parskip\hrule\relax,
postfoothook=\hrule\relax,
spaceabove=10pt,
spacebelow=10pt
]{definition}
\declaretheorem[name=Theorem,numberwithin=chapter,style=definition]{theorem}
我不确定postfoothook
和的 latex 代码是否preheadhook
正确。一方面,如果我不进行更改\parskip
(即使用默认值 0pt),则 hrules 会打印在上面和下面的文本旁边,正如预期的那样。
但是如果我传递一个值,如\setlength{\parskip}{12pt}
,我不认为 hrules 和上面和下面的段落之间的分离确实是 12 pts(在使用我的 pdf 阅读器测量距离后)。
我错了吗?我该如何更系统地检查?传递给这两个钩子的 latex 命令是什么,这样我才能正确执行?
我的代码:
\documentclass{book}
\usepackage{amsthm,thmtools,kantlipsum}
\setlength{\parskip}{12pt}
\setlength{\parindent}{0pt}
\declaretheoremstyle[
headfont=\normalfont\bfseries,
notefont=\normalfont\bfseries,
headpunct={},
postheadspace=\newline,
bodyfont = \normalfont,
postfoothook=\hrule\relax,
preheadhook=\vskip\parskip\hrule\relax,
spaceabove=10pt,
spacebelow=10pt
]{definition}
\declaretheorem[name=Theorem,numberwithin=chapter,style=definition]{theorem}
\begin{document}
%\chapter{Introduction}
\kant[1-2]
\begin{theorem}
Pellentesque massa placerat duis ultricies lacus sed turpis tincidunt id. Sagittis nisl rhoncus.
\end{theorem}
\kant[3][1-3]
\end{document}
答案1
为了测量垂直间隙,在选定的位置添加了一些间隙\tikzmark
,然后使用手动调整高度绘制了细的垂直线tikzpicture
。
看使用 tikzmark 库。但对于这个例子,你不需要理解 tikz 代码。
如图所示,上下的空间\hrule
都是10pt,符合预期(绿线)
定理内部baselineskip
为 12pt - 书籍类的默认值,字体大小为 10pt - 而在文档中,baselineskip + parskip 为 24pt,因为添加了 12pt parskip
。(橙色线)
上下文本行基线与hrule
(红线分别为 14pt 和 12pt。想要 >> 均为 17pt)的距离存在差异。
为了获得所需的间距
(1)使用\usepackage[skip=12pt]{parskip}
它将设置段落没有缩进并且 parskip=12pt。
(2)在规则前后添加垂直空格,以匹配段落之间所需的 17pt 空白。
结果是
这是用于调整和测量的代码。如果skip
或\abovebelow
长度发生变化,它将自动调整。
\documentclass[10pt]{book}
\usepackage{amsthm,thmtools,kantlipsum}
\usepackage{tikz}% needed <<<<<<<<<<
\usetikzlibrary{calc,tikzmark} % needed <<<<<<<<<<
\usepackage[autolanguage]{numprint}% needed <<<<<<<<<<
\usepackage[skip=12pt]{parskip} % added <<<<<<<<<<<<
\newlength{\abovebelow} \setlength{\abovebelow}{10pt} % set spaces above & below <<<<<<<<<
\newlength{\htX} \settoheight{\htX}{X} % adjust to font size
\newlength{\dtp} \settodepth{\dtp}{p}
\declaretheoremstyle[
headfont=\normalfont\tikzmark{b}, % added a mark <<<<<<
notefont=\normalfont\bfseries,
headpunct={\tikzmark{c}}, % added a mark <<<<<<
postheadspace=\newline,
bodyfont = \normalfont,
postfoothook= \hrule height 0.1pt \vspace*{\dimexpr \baselineskip -\htX},% changed <<<<<<
preheadhook=\vspace*{\dimexpr \baselineskip + \parskip- \htX- \dtp}\hrule height 0.1pt\vspace*{-\parskip}, % changed <<<<<<
spaceabove=\abovebelow,% changed <<<<<<
spacebelow=\abovebelow,% changed <<<<<<
]{definition}
\declaretheorem[name=Xheorem,numberwithin=chapter,style=definition]{theorem}
\begin{document}
X Some text
\tikzmark{g}Upper text.\tikzmark{a} % added a mark <<<<<<
\begin{theorem}
Pellentesque massa placerat duis ultricies lacus sed turpis tincidunt id. Sagittis nisl rhoncus.\tikzmark{d} % added a mark <<<<<<
\end{theorem}
\tikzmark{f}Lower text.\tikzmark{e} % added a mark <<<<<<
% measure/check vertical spaces <<<<<<<<<<<<
\nprounddigits{1}
\newlength{\bs}\setlength{\bs}{\baselineskip}%
\newlength{\pp} \setlength{\pp}{\dimexpr \baselineskip + \parskip}%
\newlength{\ub} \setlength{\ub}{\dimexpr \baselineskip + \parskip- \htX}%
\newlength{\br} \setlength{\br}{\dimexpr 2\baselineskip -\htX}%
\begin{tikzpicture}[overlay,remember picture, every node/.style={right,midway,font=\tiny}]
\draw [color=red]($ (pic cs:a) +(-1pt,0pt) $ ) -- ($ (pic cs:a) +(-1pt,-\ub) $) node[fill=gray!10]{$\lenprint{\ub}$}; % upper blank
\draw [color=green]($ (pic cs:b) +(2pt,\htX) $ ) -- ($ (pic cs:b) +(2pt,\abovebelow+\htX) $) node{\the\abovebelow}; %upper
\draw [color=green]($ (pic cs:d) +(-1pt,0pt) $ ) -- ($ (pic cs:d) +(-1pt,-\abovebelow) $) node{\the\abovebelow}; %lower
\draw [color=red]($ (pic cs:f) +(2pt,\htX) $ ) -- ($ (pic cs:f) +(2pt,\ub+\htX) $) node[fill=gray!10]{$\lenprint{\ub}$}; %blank to rule
\draw [color=orange]($ (pic cs:d) +(-1pt,0pt) $ ) -- ($ (pic cs:d) +(-1pt,\baselineskip) $) node{\the\bs}; % baselineskip
\draw [color=orange]($ (pic cs:a) +(-1pt,0pt) $ ) -- ($ (pic cs:a) +(-1pt,\pp) $) node{\the\pp}; % baselineskip+parskip
\draw [color=red]($ (pic cs:g) +(2pt,\htX) $ ) -- ($ (pic cs:g) +(2pt,\ub +\htX) $) node[fill=gray!10]{$\lenprint{\ub}$}; %blamk to rule
\end{tikzpicture}
\end{document}
这是使用上述结果的最终工作代码。
\documentclass[10pt]{book}
\usepackage{amsthm,thmtools,kantlipsum}
\usepackage[skip=12pt]{parskip} % added <<<<<<<<<<<<
\newlength{\abovebelow} \setlength{\abovebelow}{10pt} % set spaces above & below <<<<<<<<<
\newlength{\htX} \settoheight{\htX}{X} % adjust to font size
\newlength{\dtp} \settodepth{\dtp}{p}
\declaretheoremstyle[
headfont=\normalfont\bfseries, %
notefont=\normalfont\bfseries,
headpunct={}, %
postheadspace=\newline,
bodyfont = \normalfont,
postfoothook= \hrule \vspace*{\dimexpr \baselineskip -\htX},% changed <<<<<<
preheadhook=\vspace*{\dimexpr \baselineskip + \parskip- \htX- \dtp}\hrule \vspace*{-\parskip}, % changed <<<<<<
spaceabove=\abovebelow,% changed <<<<<<
spacebelow=\abovebelow,% changed <<<<<<
]{definition}
\declaretheorem[name=Theorem,numberwithin=chapter,style=definition]{theorem}
\begin{document}
\kant[1-2]
\begin{theorem}
Pellentesque massa placerat duis ultricies lacus sed turpis tincidunt id. Sagittis nisl rhoncus.
\end{theorem}
\kant[3][1-3]
\end{document}