Correct spacing in the alignat*-environment

Using {}= solves the spacing issue:

\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}

Output of the MWE using <code>\tfrac</code> instead of <code>nicefrac</code>.

(I do not have the package nicefrac installed. I would recommend to use \tfrac instead of \nicefrac. Most mathematicians prefer a horizontal fraction bar.)

Edit

Here is another version that might make more sense with respect to the structure of the content:

\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}

David Carlisle shows yet another version for placing the delimiters in his answer to this question. All versions have pros and cons, and it depends, e.g., on the format of the numbers and the other content, which one is best.


Two ways depending how you think of it {}- forces a binary - but you could view the form as only having right hand sides of the second and third groups so if you mark the empty lhs with && then the - at the start of the right hand sides get the usual space.

enter image description here

\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}

A tabstackengine approach. Here, the \TABbinary forces the leading negatives to be considered binary, the \setstackalingap{} allows the horizontal gap between align groups to be eliminated and the \setsatckgap{L}{} allows for the baselineskip to be set.

\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}

enter image description here