2

I am trying to create to create a set of equations as follows

enter image description here

The fractions 1/2 and 40/89 should be dead centered above each other, similarly for 1/2 and 49/89. And 0.040 and 0.036 should be right above each other. Ideally the operators \cdot, 0 and = should also be right above each other. Is this possible without some dirty hacks as depicted below?

\documentclass[10pt]{article}
\usepackage{amsmath}
\begin{document}
\def\spc{\hspace*{0.087cm}}
\def\spct{\hspace*{0.075cm}}
\begin{align*}
       \widehat{p}_a 
    &= \spc \frac{1}{2} \spc \cdot \frac{X}{10} + \spc \frac{1}{2} \spc \cdot \frac{\,Y}{10}
     = \spct \frac{1}{25} \spct 
     = 0.040 \\ 
       \widehat{p}_g 
    &= \frac{40}{89} \cdot \frac{X}{10} + \frac{49}{89} \cdot \frac{\,Y}{10} 
     = \frac{16}{445} 
       \approx 0.036
\end{align*}
\end{document}
N3buchadnezzar
  • 11,348
  • 7
  • 55
  • 114

2 Answers2

1

This is obviously a job for an array.

\documentclass[10pt]{article}
\usepackage{amsmath,array}

\begin{document}

\[
\setlength{\arraycolsep}{0pt}
\begin{array}{c *{6}{ >{{}}c<{{}} >{\displaystyle}c } }
\widehat{p}_a 
    &=& \frac{1}{2}  &\cdot& \frac{X}{10} &+& \frac{1}{2} &\cdot& \frac{\,Y}{10}
    &=& \frac{1}{25}
    &=& 0.040 \\[2ex]
\widehat{p}_g 
    &=& \frac{40}{89} &\cdot& \frac{X}{10} &+& \frac{49}{89} &\cdot& \frac{\,Y}{10} 
    &=& \frac{16}{445} 
    &\approx& 0.036
\end{array}
\]

\end{document}

enter image description here

egreg
  • 1,121,712
  • Great! Is there any typographical reason one should avoid doing this in practice? – N3buchadnezzar Mar 25 '20 at 01:21
  • 1
    @N3buchadnezzar I see no reason to reject it; on the other hand, using the natural width might better show the differences. Try and pick the one that seems clearer. – egreg Mar 25 '20 at 08:55
1

This can alternately be done as a TABstack.

\documentclass{article}
\usepackage{amsmath,tabstackengine}
\TABstackMathstyle{\displaystyle}
\begin{document}
\[
\TABbinary
\setstackgap{L}{32pt}% BASELINE SKIP OF ROWS
\Matrixstack{
\widehat{p}_a 
    &=& \frac{1}{2}  &\cdot& \frac{X}{10} &+& \frac{1}{2} &\cdot& \frac{\,Y}{10}
    &=& \frac{1}{25}
    &=& 0.040 \\
\widehat{p}_g 
    &=& \frac{40}{89} &\cdot& \frac{X}{10} &+& \frac{49}{89} &\cdot& \frac{\,Y}{10} 
    &=& \frac{16}{445} 
    &\approx& 0.036
}
\]
\end{document}

enter image description here