
我想將一個段落塗成藍色。由於我的文本包含一些方程式,因此我遵循了中給出的建議這個答案。但是,當段落以對齊環境結尾時,我會獲得額外的垂直空間,如下所示。
\documentclass{article}
\usepackage{amsmath}
\usepackage{xcolor}
\begin{document}
{ \color{blue}This is is a paragraph in blue. It contains the equation
\begin{align*}
a & = b + c - 2c\\
&= b - c.
\end{align*}
}
This is a new paragraph in black.
\end{document}
在不創建任何額外空間的情況下為段落著色的最佳方法是什麼?
答案1
(至少對於 PDFLaTeX)\color{…}
結果是那是什麼因此是水平材料。不幸的是,在一組結束時切換回之前的顏色也需要一個東西。因此,在您的情況下,\end{align*}
由於顏色切換而導致後面有一個額外的段落。我的建議是避開該組並明確切換到\normalcolor
下一段的開頭:
\documentclass{article}
\usepackage{amsmath}
\usepackage{xcolor}
\begin{document}
\color{blue}%
This is is a paragraph in blue. It contains the equation
\begin{align*}
a & = b + c - 2c\\
&= b - c.
\end{align*}
\normalcolor
This is a new paragraph in black.
\end{document}
另一個選擇是使用 LuaLaTeX 和包裹luacolor
:
\documentclass{article}
\usepackage{amsmath}
\usepackage{xcolor}
\usepackage{luacolor}
\begin{document}
{\color{blue}%
This is is a paragraph in blue. It contains the equation
\begin{align*}
a & = b + c - 2c\\
&= b - c.
\end{align*}}
This is a new paragraph in black.
\end{document}
顏色luacolor
不再是什麼(因此是水平材質),而是節點屬性。使用 LuaLaTeX 的另一個優勢。
\par
另一種選擇是在組結束之後align*
但在組結束之前添加 a ,因為顏色代碼試圖在垂直模式下避免此類問題:
\documentclass{article}
\usepackage{amsmath}
\usepackage{xcolor}
\begin{document}
{\color{blue}%
This is is a paragraph in blue. It contains the equation
\begin{align*}
a & = b + c - 2c\\
&= b - c.
\end{align*}\par}
This is a new paragraph in black.
\end{document}