1

Is there a way to make specific letters in equation mode have the same width? I could use the command \texttt{} outside the align environment but not in math mode. For instance, the script below generates the following

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

\begin{document}

\begin{align} \hat{y}^t &= \alpha^t_{l,\text{h}}\hat{y}^t \odot m_l + \textstyle\sum_{i} \alpha^t_{l,i}\hat{y}^t_{l,i} \odot (1 - m_l) \ \hat{y}^t &= \alpha^t_{r,\text{h}}\hat{y}^t \odot m_r + \textstyle\sum_{i} \alpha^t_{r,i}\hat{y}^t_{r,i} \odot (1 - m_r) \end{align}

\noindent \texttt{your text - IN CAPITALS}\ \texttt{lrlr text - IN CAPITALS}

\end{document}

enter image description here

I have a lot of such equations that need to be computed and read sequentially and i think it would be nicer if I could have at least specific letters occupy the same width. In the example above I would like the subscripts l and r have the same width or have the letter l have extra padding to match total width the letter r takes. I cannot use their capital letters.

Kong
  • 2,313

2 Answers2

4

I think it is better to align the operators rather than get "accidental" alignment by forcing same width characters.

I also restricted textstyle to just the summation not the rest of the expression.

enter image description here

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

\begin{document}

\begin{alignat}{4} \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) \ \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) \end{alignat}

\noindent \texttt{your text - IN CAPITALS}\ \texttt{lrlr text - IN CAPITALS}

\end{document}

David Carlisle
  • 757,742
3

I agree with David Carlisle that you have an XY problem.

But, here are some answers to the X problem. The \texttt command also works in math mode if you use amsmath, which nearly all math papers do. The unicode-math package additionally provides \symtt for the Unicode mathematical typewriter alphabet. (Note that neither is supposed to be synonymous with ordinary variables.) Finally, you could calculate the maximum width of the subscripts and put a \scriptstyle i inside a \mbox whose width is the same as the widest subscript.

Davislor
  • 44,045