3

I am coming from this thread Have characters (subscripts) in equation mode occupy the same width to make my equation occupy the same width. The solution is to use alignat. Now I add in 2 more equations above and the spacing goes wild. How do I fix this ? Ive tried a bunch of random things but they all end up looking like garbage.

\documentclass{article}
\usepackage{tabularx}
\usepackage{booktabs}
\usepackage{graphicx}
\usepackage{amsmath}

\begin{document}

\begin{alignat}{4} \hat{y}{\Psi}^t &= \Psi(h^t\text{h}) \ \hat{y}^t_{\Phi,s,i} &= \Phi([\hat{y}{\Psi}^t \odot m_s,x_i^t];\text{BPS}_i) \label{eq:doublenets} \ \hat{y}^t &= \alpha^t{l,\text{h}}\hat{y}^t &&\odot m_l &&+ \mathop{\textstyle\sum_{i}} \alpha^t_{l,i}\hat{y}^t_{l,i} &&\odot (1 - m_l) \label{eq:update1} \ \hat{y}^t &= \alpha^t_{r,\text{h}}\hat{y}^t &&\odot m_r &&+ \mathop{\textstyle\sum_{i}} \alpha^t_{r,i}\hat{y}^t_{r,i} &&\odot (1 - m_r) \label{eq:update2} \end{alignat}

\end{document}

enter image description here

Kong
  • 2,313

2 Answers2

4

Just hide the width of the entries in the first rows, eg

enter image description here

\documentclass{article}
\usepackage{tabularx}
\usepackage{booktabs}
\usepackage{graphicx}
\usepackage{amsmath}

\begin{document}

\begin{alignat}{4} \hat{y}{\Psi}^t &= \Psi(h^t{\mathrm{h}})\hspace{-\textwidth} \ \hat{y}^t_{\Phi,s,i} &= \Phi([\hat{y}{\Psi}^t \odot m_s,x_i^t];\mathrm{BPS}_i)\hspace{-\textwidth} \label{eq:doublenets} \ \hat{y}^t &= \alpha^t{l,\mathrm{h}}\hat{y}^t &&\odot m_l &&+ \mathop{\textstyle\sum_{i}} \alpha^t_{l,i}\hat{y}^t_{l,i} &&\odot (1 - m_l) \label{eq:update1} \ \hat{y}^t &= \alpha^t_{r,\mathrm{h}}\hat{y}^t &&\odot m_r &&+ \mathop{\textstyle\sum_{i}} \alpha^t_{r,i}\hat{y}^t_{r,i} &&\odot (1 - m_r) \label{eq:update2} \end{alignat}

\end{document}

I also fixed \text which should not be used here, to \mathrm, I missed that last time.

David Carlisle
  • 757,742
  • Jeez, i would have never thought of that solution. Many thanks you are very kind. Latex is so unintuitive and is something I will never get better at especially since I only visit it once a year when writing up my work.... – Kong Apr 25 '23 at 17:45
  • @Kong I wouldn't say this was that latex-specific, alignat is just a table, you would see same in html or other tables if you put a large entry in column 2 that column gets wider in all rows, as your image showed. – David Carlisle Apr 25 '23 at 17:49
  • Why not use \rlap on the post-= segment of the second line? – barbara beeton Apr 25 '23 at 18:53
  • @barbarabeeton \rlap{$\displaystyle{} ...$} or \mathrlap{\displaystyle...} from mathtools would work but I thought hspace was simpler here – David Carlisle Apr 25 '23 at 19:25
2

You can use IEEEeqnarray provided by the IEEEtrantools package.

\documentclass{article}
\usepackage{amsmath}
\usepackage{IEEEtrantools}

\newcommand{\hup}{\mathrm{h}} \newcommand{\tsum}{\mathop{\textstyle\sum}\nolimits}

\begin{document}

\begin{IEEEeqnarray}{rLLLL} \hat{y}^t &= \alpha^t_{l,\hup}\hat{y}^t &\odot m_l &+ \tsum_{i} \alpha^t_{l,i}\hat{y}^t_{l,i} &\odot (1 - m_l) \ \hat{y}^t &= \alpha^t_{r,\hup}\hat{y}^t &\odot m_r &+ \tsum_{i} \alpha^t_{r,i}\hat{y}^t_{r,i} &\odot (1 - m_r) \end{IEEEeqnarray} And another one \begin{IEEEeqnarray}{rLLLL} \hat{y}{\Psi}^t &= \Psi(h^t{\hup}) \ \hat{y}^t_{\Phi,s,i} & \IEEEeqnarraymulticol{4}{L}{=\Phi\bigl([\hat{y}{\Psi}^t \odot m_s,x_i^t];\mathrm{BPS}_i\bigr)} \label{eq:doublenets} \ \hat{y}^t &= \alpha^t{l,\hup}\hat{y}^t &\odot m_l &+ \tsum_{i} \alpha^t_{l,i}\hat{y}^t_{l,i} &\odot (1 - m_l) \label{eq:update1} \ \hat{y}^t &= \alpha^t_{r,\hup}\hat{y}^t &\odot m_r &+ \tsum_{i} \alpha^t_{r,i}\hat{y}^t_{r,i} &\odot (1 - m_r) \label{eq:update2} \end{IEEEeqnarray}

\end{document}

Note that \text{h} and \text{BPS} are wrong and \text should be \mathrm. I also provided a shorthand for the text style \sum.

The column type L means left alignment with an empty atom at the beginning, so the spacing around the initial binary or relation symbol is correct.

enter image description here

egreg
  • 1,121,712