为了符合我的数学书中使用的惯例,我希望定理、引理、定义等从左/右边距缩进。用“\begin{adjustwidth}{.6cm}{.6cm}”包裹定理会导致文本之间的顶部/底部间距不同。我可以通过调用 /vspace 来纠正这个问题,但这似乎有点笨拙。有没有更好的格式化方法,还是我只能调用 \vspace?
\documentclass{book}
\usepackage{lipsum}% just to generate text for the example
\usepackage{amsmath, mathtools,amssymb,amscd,amsthm,amstext}
\usepackage{changepage}
% Redefine theorem style
\newtheoremstyle{mytheoremstyle} % name
{\topsep} % Space above
{\topsep} % Space below
{\itshape} % Body font
{\parindent} % Indent amount
{\bfseries} % Theorem head font
{.} % Punctuation after theorem head
{0.5em} % Space after theorem head
{} % Theorem head spec (can be left empty, meaning ‘normal’)
\theoremstyle{mytheoremstyle}
\newtheorem{theorem}{Theorem}[chapter]
\begin{document}
\lipsum[1-1]
\begin{theorem}
This theorem looks correct, but I haven't applied any indentation.
It follows the indentation of the document.
\end{theorem}
\lipsum[1-1]
\begin{adjustwidth}{.6cm}{.6cm}
\begin{theorem}
This theorem has had indentation applied and the result is different
spacing above and below it.
\end{theorem}
\end{adjustwidth}
\lipsum[1-1]
\end{document}
答案1
我可以建议不要使用adjustwidth
,但要进行小修改https://tex.stackexchange.com/a/67251/4427
\normalparindent
为了避免时间问题(将参数设置为零),这个技巧是\list
必要\parindent
的。
\documentclass{book}
\usepackage{lipsum}% just to generate text for the example
\usepackage{amsmath, mathtools,amssymb,amscd,amsthm,amstext}
\usepackage{etoolbox}
\makeatletter
\patchcmd{\@thm}
{\trivlist}
{\list{}{\leftmargin=\thm@leftmargin\rightmargin=\thm@rightmargin}}
{}{}
\patchcmd{\@endtheorem}
{\endtrivlist}
{\endlist}
{}{}
\newlength{\thm@leftmargin}
\newlength{\thm@rightmargin}
\newcommand{\xnewtheorem}[3]{%
\newenvironment{#3}
{\thm@leftmargin=#1\relax\thm@rightmargin=#2\relax\begin{#3INNER}}
{\end{#3INNER}}%
\newtheorem{#3INNER}%
}
\newlength{\normalparindent}
\setlength{\normalparindent}{1sp}
\AtBeginDocument{\setlength{\normalparindent}{\parindent}}
\makeatother
% Redefine theorem style
\newtheoremstyle{mytheoremstyle} % name
{\topsep} % Space above
{\topsep} % Space below
{\itshape} % Body font
{\normalparindent} % Indent amount
{\bfseries} % Theorem head font
{.} % Punctuation after theorem head
{0.5em} % Space after theorem head
{} % Theorem head spec (can be left empty, meaning ‘normal’)
\theoremstyle{mytheoremstyle}
\xnewtheorem{.6cm}{.6cm}{theorem}{Theorem}[chapter]
\begin{document}
\lipsum[1-1]
\begin{theorem}
This theorem looks correct, but I haven't applied any indentation.
It follows the indentation of the document.
\end{theorem}
\lipsum[1-1]
\begin{theorem}
This theorem has had indentation applied and the result is different
spacing above and below it.
\end{theorem}
\lipsum[1-1]
\end{document}
答案2
这是环境的一个普遍问题theorem
(重新定义为amsthm
) 被用作 . 后面的第一个元素(环境中\item
有一个隐藏元素)。这深入探讨了 LaTeX 对列表的管理。\item
adjustwidth
与其修补theorem
,我建议在此对 进行破解adjustwidth
,这可能足以满足您的文档,但可能会产生我尚未尝试发现的后遗症。 已完成etoolbox
,\apptocmd
作为商品。
\documentclass{book}
\usepackage{lipsum}% just to generate text for the example
\usepackage{amsmath, mathtools,amssymb,amscd,amsthm,amstext}
\usepackage{changepage}
% Redefine theorem style
\newtheoremstyle{mytheoremstyle} % name
{\topsep} % Space above
{\topsep} % Space below
{\itshape} % Body font
{\parindent} % Indent amount
{\bfseries} % Theorem head font
{.} % Punctuation after theorem head
{0.5em} % Space after theorem head
{} % Theorem head spec (can be left empty, meaning ‘normal’)
\theoremstyle{mytheoremstyle}
\newtheorem{theorem}{Theorem}[chapter]
% HACKING \adjustwidth
\usepackage{etoolbox}
\makeatletter
\apptocmd\adjustwidth{\@inlabelfalse\@newlistfalse}
\makeatother
\begin{document}
\lipsum[1-1]
\begin{theorem}
This theorem looks correct, but I haven't applied any indentation.
It follows the indentation of the document.
\end{theorem}
\lipsum[1-1]
\begin{adjustwidth}{.6cm}{.6cm}
\begin{theorem}
This theorem has had indentation applied and the result is with similar
spacing above and below it as in previous theorem.
\end{theorem}
\end{adjustwidth}
\lipsum[1-1]
\end{document}
更新
我对这个问题进行了更深入的研究,似乎theorem
包中的环境的这个“特性”(错误行为?)可以通过使用但不使用标准(或者更确切地说)amsthm
来解释 。宏取代了它,并且缺少常规的某些条件测试:没有部分。amsthm
\trivlist
\item
\@item
\deferred@thm@head
\@item
\if@noparitem \@donoparitem \else ...
原文如下:
\def\deferred@thm@head#1{%
\if@inlabel \indent \par \fi % eject a section head if one is pending
\if@nobreak
\adjust@parskip@nobreak
\else
\addpenalty\@beginparpenalty
\addvspace\@topsep
\addvspace{-\parskip}%
\fi
\global\@inlabeltrue
\everypar\dth@everypar
\sbox\@labels{\normalfont#1}%
\ignorespaces
}
基于 LaTeX 内核模型,重新定义为\@item
:
\def\deferred@thm@head#1{%
\if@noparitem
\@noparitemfalse
\else
\if@inlabel \indent \par \fi % eject a section head if one is pending
\if@nobreak
\adjust@parskip@nobreak
\else
\addpenalty\@beginparpenalty
\addvspace\@topsep
\addvspace{-\parskip}%
\fi
\global\@inlabeltrue
\fi
\everypar\dth@everypar
\sbox\@labels{\normalfont#1}%
\ignorespaces
}
theorem
我观察到,如果环境被用作 中的第一个元素,那么使用修补后的宏将不会有额外的空白行\item
。修补效果实际上甚至抑制了 由 添加的默认垂直空间theorem
,所有垂直空间责任都落在周围列表的肩上(如果有的话)(在 的情况下adjustwidth
,这意味着基本上没有额外的垂直空间)。因此,这只是一个提议,但它允许将垂直间距的设置完全委托给周围的列表环境。然后我们可以通过列表环境控制左右边距等……
由于列表中的标准theorem
环境中没有出现多余的空行,因此的这一特征似乎是一种错误行为。\item
amsthm