我用它thmtools
来制作非常奇特的定理。我希望定理名称和编号(例如,“定理 1”)突出到文本的左边距,而注释(例如,“微积分基本定理”)位于常规文本中。但我无法完全正确地对齐。这是一个最小示例:
\documentclass{article}
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{amssymb}
\usepackage{thmtools}
\pagestyle{empty}
\declaretheoremstyle[
headfont=\bfseries,
notefont=\normalfont,
bodyfont=\itshape,
headpunct=\newline,
headformat={%
\makebox[0pt][r]{\NAME\ \NUMBER\ }{\NOTE}%
},
]{theorem}
\declaretheorem[style=theorem]{theorem}
% I need to undeclare the proof environment that amsthm provides but I can't use \renewenvironment
\let\proof\relax
\let\endproof\relax
\declaretheoremstyle[
headfont=\scshape,
notefont=\itshape
bodyfont=\normalfont,
headpunct=\relax,
headformat={%
\makebox[0pt][r]{\NAME\ }\NOTE},
]{proof}
\declaretheorem[
style=proof,
qed=\qedsymbol]{proof}
\begin{document}
\begin{theorem}[The Fundamental Theorem of Calculus]
Let $f$ be an integrable function on $[a,b]$ and define
\[
g(x) = \int_a^x f(t) \,dt.
\]
If $f$ is continuous at $x$ in $(a,b)$, then $g$ is differentiable at $x$ and
\[
g'(x) = f(x).
\]
\end{theorem}
\begin{proof}
Let $h>0$ be given so that $x+h < b$ (The case $h<0$ is treated similarly). We have
\[
\frac{g(x+h) - g(x)}{h} = \frac{1}{h} \int_x^{x+h} f(t)\,dt.
\]
Let $M_h$ be the maximum value of $f$ on $[x,x+h]$, and let $m_h$ the minimum value of $f$ on $[x,x+h]$. We have
\[
m_h \cdot h \leq \int_x^{x+h}f(t)\,dt \leq M_h \cdot h
\]
So
\[
m_h \leq \frac{g(x+h) - g(x)}{h} \leq M_h.
\]
Since $f$ is continuous at $x$, as $h\to 0$, both $m_h$ and $M_h$ tend to $f(x)$.
\end{proof}
\end{document}
如您所见,注释太靠右了。在环境中proof
,没有注释,但文本的开头也太靠右了。
为什么要在那里留出多余的空间?我怎样才能消除它?
编辑向下滚动到我的答案,看看我是如何解决这个问题的。我接受了 Phil 的答案,因为它比 Gonzalo 的答案更少黑客(不涉及@
),并且让我最接近我想要的结果。
答案1
快速浏览代码(在后面的部分thmtools.pdf
)显示,宏\NODE
本身在左括号前插入了一个空格。如果您不介意粗鲁一点,您可以执行以下操作:
\newlength{\spacelength}
\settowidth{\spacelength}{\normalfont\ }
\declaretheoremstyle[
headfont=\bfseries,
notefont=\normalfont,
bodyfont=\itshape,
headpunct=\newline,
headformat={%
\makebox[0pt][r]{\NAME\ \NUMBER\ }\hskip-\spacelength{\NOTE}%
},
]{theorem}
答案2
快速查看包实现,我发现注释前有一个硬编码的空格;一个可能的解决方案是删除该空格(这当然会影响所有定理)。您可以将以下内容添加到文档的序言中(该空格已被隐藏):
\makeatletter
\newtoks\thmt@style@headstyle
\define@key{thmstyle}{headformat}[]{%
\thmt@style@headstyle{%
\def\NAME{\the\thm@headfont ##1}%
\def\NUMBER{\bgroup\@upn{##2}\egroup}%
\def\NOTE{\if=##3=\else\bgroup\the\thm@notefont(##3)\egroup\fi}%
}
\def\thmt@tmp{#1}%
\@onelevel@sanitize\thmt@tmp
%\tracingall
\ifcsname thmt@headstyle@\thmt@tmp\endcsname
\thmt@style@headstyle\@xa{%
\the\thmt@style@headstyle
\csname thmt@headstyle@#1\endcsname
}%
\else
\thmt@style@headstyle\@xa{%
\the\thmt@style@headstyle
#1
}%
\fi
%\showthe\thmt@style@headstyle
}
\makeatother
原文几乎相同;仅在以 开头的行有差异\def\NOTE
:
\def\NOTE{\if=##3=\else\bgroup\ \the\thm@notefont(##3)\egroup\fi}%
您可以看到 之前的额外空间\the\thm@notefont(##3)
。
我发现针对证明环境情况的唯一解决方案是手动抑制额外的空间,添加类似这样的内容
postheadspace=-4pt,
到相应的\declaretheoremstyle
命令
答案3
感谢 Phil 和 Gonzalo 的回答。我从两者中吸取了一些经验,因此不要投票支持我的答案,除非你也投票支持他们的答案。
我采用了 Gonzalo 的建议,在环境中调整postheadspace
为,并采用了 Phil 的建议“退格”。我没有像 Phil 那样使用全局变量,而是使用了一个临时框,这样负单词间距的宽度将与定理头部字体中的单词间距相同。如果有其他方法或现有宏可以做同样的事情,请告诉我。0pt
proof
\documentclass{article}
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{amssymb}
\usepackage{thmtools}
\pagestyle{empty}
\declaretheoremstyle[
headfont=\bfseries,
notefont=\normalfont,
bodyfont=\itshape,
headpunct=\newline,
headformat={%
\makebox[0pt][r]{\NAME\ \NUMBER\ }\setbox0\hbox{\ }\hspace{-\the\wd0}\NOTE%
},
]{theorem}
\declaretheorem[style=theorem]{theorem}
% I need to undeclare the proof environment that amsthm provides but I can't use \renewenvironment
\let\proof\relax
\let\endproof\relax
\declaretheoremstyle[
headfont=\scshape,
notefont=\itshape,
bodyfont=\normalfont,
headpunct={},
postheadspace={0pt},
headformat={%
\makebox[0pt][r]{\NAME\ }\setbox0\hbox{\ }\hspace{-\the\wd0}\NOTE},
]{proof}
\declaretheorem[
style=proof,
qed=\qedsymbol
]{proof}
\begin{document}
\begin{theorem}[The Fundamental Theorem of Calculus]
Let $f$ be an integrable function on $[a,b]$ and define
\[
g(x) = \int_a^x f(t) \,dt.
\]
If $f$ is continuous at $x$ in $(a,b)$, then $g$ is differentiable at $x$ and
\[
g'(x) = f(x).
\]
\end{theorem}
\begin{proof}
Let $h>0$ be given so that $x+h < b$ (The case $h<0$ is treated similarly). We have
\[
\frac{g(x+h) - g(x)}{h} = \frac{1}{h} \int_x^{x+h} f(t)\,dt.
\]
Let $M_h$ be the maximum value of $f$ on $[x,x+h]$, and let $m_h$ the minimum value of $f$ on $[x,x+h]$. We have
\[
m_h \cdot h \leq \int_x^{x+h}f(t)\,dt \leq M_h \cdot h
\]
So
\[
m_h \leq \frac{g(x+h) - g(x)}{h} \leq M_h.
\]
Since $f$ is continuous at $x$, as $h\to 0$, both $m_h$ and $M_h$ tend to $f(x)$.
\end{proof}
\end{document}
环境中的注释看起来仍然不太好proof
。我认为还有另一个硬编码空间。
我期待 Ulrich 的更新。:-)