我正在使用该包changebar
在我的文档中设置几个环境。
当我结束显示方程式的环境时,更改栏会延伸到方程式的太远。我希望更改栏停止在显示方程式的基线处。
我的 MWE......
\documentclass{article}
\usepackage{amsmath}
\usepackage[leftbars]{changebar}
\setlength{\changebarsep}{-20pt}
\setlength{\changebarwidth}{2pt}
\newcounter{example}
\newenvironment{exampl}
{
\par\vspace{10pt}
\begin{enumerate}
\item[]
\refstepcounter{example}
\noindent
\cbstart
\textbf{Example \theexample} %
}
{
\cbend
\end{enumerate}
}
\begin{document}
In Example 1 below, the bar extends to the baseline of the ending text.
\begin{exampl}
The quadratic formula
\[c^2=a^2+b^2\]
generalizes to the Law of Cosines
\[c^2=a^2+b^2-2ab\cos C\ .\]
This generalization shows how to use the Pythagorean Theorem with oblique triangles; that is, with non-right triangles.
\end{exampl}
However, Example 2 ends with a display equation and the bar extends past the baseline of the equation.
\begin{exampl}
The quadratic formula
\[c^2=a^2+b^2\]
generalizes to the Law of Cosines
\[c^2=a^2+b^2-2ab\cos C\ .\]
\end{exampl}
How can I get the bar to stop at the baseline of the display equation in Example 2?
\end{document}
我已尝试调整\belowdisplayskip
,但我不知道如何仅影响我的环境末尾的显示方程。
我感谢任何帮助和评论。
答案1
这个答案专门针对此评论。首先,让我展示一些代码和一张图片。
代码和图片
\documentclass{article}
\usepackage{amsmath}
\usepackage[margin=2.5in]{geometry}
\usepackage[leftbars]{changebar}
\setlength{\changebarwidth}{2pt}
\setlength{\changebarsep}{0pt}
\setlength{\parindent}{0pt}
\begin{document}
\cbstart
First we wrap the entire paragraph, including the math in the changebar.
\[ E = mc^2\]
Some text.
\cbend
Next, we show what happens if we wrap an equation by itself in change bar.
\cbstart
\[ E = mc^2\]
\cbend
In the next example the changebar commands are issued from \emph{within} the display math mode.
\[ \cbstart E = mc^2 \cbend \]
In this example, we wrap the equations in some text (as it would appear within a paragraph), but only issue the changebar commands immediately before and immediately after the equation.
\cbstart
\[ E = mc^2 \]
\cbend
some more text.
In this final example, we see what happens if we enter vertical mode before passing control to the changebar end command.
\cbstart
\[ E =mc^2 \]\par
\cbend
Some more text so the spacing can be more clearly seen. Just extend this a little bit more.
\end{document}
讨论
关键在于\cbstart
和\cbend
命令在垂直和水平模式下的行为不同。在垂直模式下\cbend
标记垂直位置,仅此而已。但在水平模式下,它会换行\vadjust
,这样当前行就会先得到处理,然后再放下标记。这样做的问题是,在一个空行上,\cbend
和\leavevmode\cbend
的行为不同:后者将首先键入一个空白行,然后结束更改栏,从而产生一行额外的空间。
回答你的问题
如果您希望它与baseline
显示的方程式齐平,您无法做到这一点,至少不能像在环境中包装事物那样做到这一点。要访问显示的方程式基线的垂直位置,您实际上必须将其放置\cbend
在最终显示的方程式内。我想可能有办法做到这一点(类似于\qedhere
证明环境,我期望),但这对我来说太难了。
但是,如果您对仅删除上述讨论中产生的额外空间(实际上是由于\cbend
设置了额外的空白行)的解决方案感到满意,那么您可以做的是确保\cbend
在垂直模式(而不是水平模式)下调用。执行此操作的命令是\par
。
因此,您可以做的是在环境定义中替换对的调用,\cbend
这样\par\cbend
可以删除一些(但不是全部)额外的空间。
答案2
为什么要使用changebar
?如果你要生成示例列表,使用mdframed
+似乎更容易ntheorem
。请参阅mdframed
了解使用信息。例如:
\documentclass{article}
\usepackage{amsmath}
\usepackage{ntheorem}
\usepackage[xcolor,tikz]{mdframed}
\theoremstyle{plain}
\theorembodyfont{\upshape}
\newmdtheoremenv[%
innertopmargin=0pt,% make the frame "tight"
innerbottommargin=0pt,%
rightline=false,% Kill all the lines except the left one
topline=false,%
bottomline=false,%
linecolor=gray,%
linewidth=4pt,%
leftmargin=10pt%
ntheorem = true% since we are using ntheorem to configure the style
]{exampl}{Example}
\begin{document}
In Example 1 below, the bar extends to the baseline of the ending text.
\begin{exampl}
The quadratic formula
\[c^2=a^2+b^2\]
generalizes to the Law of Cosines
\[c^2=a^2+b^2-2ab\cos C\ .\]
This generalization shows how to use the Pythagorean Theorem with oblique triangles; that is, with non-right triangles.
\end{exampl}
However, Example 2 ends with a display equation and the bar extends past the baseline of the equation.
\begin{exampl}
The quadratic formula
\[c^2=a^2+b^2\]
generalizes to the Law of Cosines
\[c^2=a^2+b^2-2ab\cos C\ .\]%
\end{exampl}
How can I get the bar to stop at the baseline of the display equation in Example 2?
\end{document}