给出以下代码:
\begin{alignat*}{3}
h(0) & = g_s(0) - g_s(0 - 1) = 0.25 & - 0.00 & = \nicefrac{1}{4}\\
h(1) & = g_s(1) - g_s(1 - 1) = 0.50 & - 0.25 & = \nicefrac{1}{4}\\
h(2) & = g_s(2) - g_s(2 - 1) = 0.75 & - 0.50 & = \nicefrac{1}{4}\\
h(3) & = g_s(3) - g_s(3 - 1) = 1.00 & - 0.75 & = \nicefrac{1}{4}\\
h(4) & = g_s(4) - g_s(4 - 1) = 1.00 & - 1.00 & = 0
\end{alignat*}
输出
但是输出结果中每个数字之间的间距应该与第一个方程相同h(x) = g_s(x) - g_s(x - 1)
。(换句话说,减号之间的间距太小。)我该如何获得这个结果?
答案1
两种方式取决于你如何看待它{}-
强制二进制 - 但你可以将形式视为只有第二组和第三组的右侧,所以如果你用标记空的 lhs,&&
那么-
在右侧的开头就会得到通常的空间。
\documentclass{article}
\usepackage{amsmath,nicefrac}
\begin{document}
aaa
\begin{alignat*}{3}
h(0) & = g_s(0) - g_s(0 - 1) = 0.25 & - 0.00 & = \nicefrac{1}{4}\\
h(1) & = g_s(1) - g_s(1 - 1) = 0.50 & - 0.25 & = \nicefrac{1}{4}\\
h(2) & = g_s(2) - g_s(2 - 1) = 0.75 & - 0.50 & = \nicefrac{1}{4}\\
h(3) & = g_s(3) - g_s(3 - 1) = 1.00 & - 0.75 & = \nicefrac{1}{4}\\
h(4) & = g_s(4) - g_s(4 - 1) = 1.00 & - 1.00 & = 0
\end{alignat*}
bbb
\begin{alignat*}{3}
h(0) & = g_s(0) - g_s(0 - 1) = 0.25 & {}- 0.00 & = \nicefrac{1}{4}\\
h(1) & = g_s(1) - g_s(1 - 1) = 0.50 & {}- 0.25 & = \nicefrac{1}{4}\\
h(2) & = g_s(2) - g_s(2 - 1) = 0.75 & {}- 0.50 & = \nicefrac{1}{4}\\
h(3) & = g_s(3) - g_s(3 - 1) = 1.00 & {}- 0.75 & = \nicefrac{1}{4}\\
h(4) & = g_s(4) - g_s(4 - 1) = 1.00 & {}- 1.00 & = 0
\end{alignat*}
ccc
\begin{alignat*}{3}
h(0) & = g_s(0) - g_s(0 - 1) = 0.25 && - 0.00 && = \nicefrac{1}{4}\\
h(1) & = g_s(1) - g_s(1 - 1) = 0.50 && - 0.25 && = \nicefrac{1}{4}\\
h(2) & = g_s(2) - g_s(2 - 1) = 0.75 && - 0.50 && = \nicefrac{1}{4}\\
h(3) & = g_s(3) - g_s(3 - 1) = 1.00 && - 0.75 && = \nicefrac{1}{4}\\
h(4) & = g_s(4) - g_s(4 - 1) = 1.00 && - 1.00 && = 0
\end{alignat*}
\end{document}
答案2
使用{}=
解决间距问题:
\documentclass{article}
\usepackage{amsmath}
\usepackage{nicefrac}
\begin{document}
\begin{alignat*}{3}
h(0) & = g_s(0) - g_s(0 - 1) = 0.25 & {}- 0.00 & = \nicefrac{1}{4} \\
h(1) & = g_s(1) - g_s(1 - 1) = 0.50 & {}- 0.25 & = \nicefrac{1}{4} \\
h(2) & = g_s(2) - g_s(2 - 1) = 0.75 & {}- 0.50 & = \nicefrac{1}{4} \\
h(3) & = g_s(3) - g_s(3 - 1) = 1.00 & {}- 0.75 & = \nicefrac{1}{4} \\
h(4) & = g_s(4) - g_s(4 - 1) = 1.00 & {}- 1.00 & = 0
\end{alignat*}
\end{document}
(我没有nicefrac
安装该软件包。我建议使用\tfrac
而不是\nicefrac
。大多数数学家更喜欢水平分数线。)
编辑
以下是另一个从内容结构上来说可能更有意义的版本:
\documentclass{article}
\usepackage{amsmath}
\usepackage{nicefrac}
\begin{document}
\begin{alignat*}{3}
h(0) & = g_s(0) - g_s(0 - 1) && = 0.25 - 0.00 && = \nicefrac{1}{4} \\
h(1) & = g_s(1) - g_s(1 - 1) && = 0.50 - 0.25 && = \nicefrac{1}{4} \\
h(2) & = g_s(2) - g_s(2 - 1) && = 0.75 - 0.50 && = \nicefrac{1}{4} \\
h(3) & = g_s(3) - g_s(3 - 1) && = 1.00 - 0.75 && = \nicefrac{1}{4} \\
h(4) & = g_s(4) - g_s(4 - 1) && = 1.00 - 1.00 && = 0
\end{alignat*}
\end{document}
大卫·卡莱尔显示了另一个将分隔符放置在他的回答回答这个问题。所有版本都有优点和缺点,这取决于数字的格式和其他内容,哪一个最好。
答案3
一种tabstackengine
方法。在这里,\TABbinary
强制将前导负片视为二进制,允许\setstackalingap{}
消除对齐组之间的水平间隙,并\setsatckgap{L}{}
允许设置基线跳跃。
\documentclass{article}
\usepackage{amsmath,nicefrac,tabstackengine}
\TABstackMath
\begin{document}
\[
\TABbinary
\setstackaligngap{0pt}
\setstackgap{L}{1.2\baselineskip}
\alignCenterstack{
h(0) & = g_s(0) - g_s(0 - 1) = 0.25 & - 0.00 & = \nicefrac{1}{4} \\
h(1) & = g_s(1) - g_s(1 - 1) = 0.50 & - 0.25 & = \nicefrac{1}{4} \\
h(2) & = g_s(2) - g_s(2 - 1) = 0.75 & - 0.50 & = \nicefrac{1}{4} \\
h(3) & = g_s(3) - g_s(3 - 1) = 1.00 & - 0.75 & = \nicefrac{1}{4} \\
h(4) & = g_s(4) - g_s(4 - 1) = 1.00 & - 1.00 & = 0
}
\]
\end{document}