5

Is there an easy way (maybe provided by mathtools that aligns normal subscripts)?

I know that I can do this manually with \vphantom, but I was looking for a better way.

\documentclass{article}

\usepackage{mathtools}

\begin{document}
\noindent Looks pretty bad:
\[
    T_\theta T_\theta^{-1} = \begin{pmatrix*}[r]
        \cos\theta & -\sin\theta\\
        \sin\theta & \cos\theta
    \end{pmatrix*}\begin{pmatrix*}[r]
        \cos\theta & \sin\theta\\
        -\sin\theta & \cos\theta
    \end{pmatrix*}
    = \begin{pmatrix}1&0\\0&1\end{pmatrix} = I
\]
adjustlimits doesn't work:
\[
    \adjustlimits T_\theta T_\theta^{-1} = \begin{pmatrix*}[r]
        \cos\theta & -\sin\theta\\
        \sin\theta & \cos\theta
    \end{pmatrix*}\begin{pmatrix*}[r]
        \cos\theta & \sin\theta\\
        -\sin\theta & \cos\theta
    \end{pmatrix*}
    = \begin{pmatrix}1&0\\0&1\end{pmatrix} = I
\]
vphantom does work
\[
    T_\theta^{\vphantom{-1}} T_\theta^{-1} = \begin{pmatrix*}[r]
        \cos\theta & -\sin\theta\\
        \sin\theta & \cos\theta
    \end{pmatrix*}\begin{pmatrix*}[r]
        \cos\theta & \sin\theta\\
        -\sin\theta & \cos\theta
    \end{pmatrix*}
    = \begin{pmatrix}1&0\\0&1\end{pmatrix} = I
\]
\end{document}

enter image description here

CarLaTeX
  • 62,716

3 Answers3

4

Try \mathstrut, which is exactly a \vphantom(, and always put subscripts within {}.

Edit: The Master says that \vphantom{-} is conceptually better, I've created a new command for convenience:

\documentclass{article}
\usepackage{mathtools}
\newcommand{\egreg}{\vphantom{-}}% new command for alignment adjustment (you can choose another name, of course!) 
\begin{document}
    \noindent egreg's version: 
    \[
    T_{\theta}^{\egreg}\, T_{\theta}^{-1} = \begin{pmatrix*}[r] % I've added also a little space \,
    \cos\theta & -\sin\theta\\
    \sin\theta & \cos\theta
    \end{pmatrix*}\begin{pmatrix*}[r]
    \cos\theta & \sin\theta\\
    -\sin\theta & \cos\theta
    \end{pmatrix*}
    = \begin{pmatrix}1&0\\0&1\end{pmatrix} = I
    \]
    \noindent My previous version: 
    \[
    T_{\theta}^{\mathstrut}\, T_{\theta}^{-1} = \begin{pmatrix*}[r] % I've added also a little space \,
    \cos\theta & -\sin\theta\\
    \sin\theta & \cos\theta
    \end{pmatrix*}\begin{pmatrix*}[r]
    \cos\theta & \sin\theta\\
    -\sin\theta & \cos\theta
    \end{pmatrix*}
    = \begin{pmatrix}1&0\\0&1\end{pmatrix} = I
    \]
\end{document}

enter image description here

CarLaTeX
  • 62,716
  • 1
    \vphantom{-} would be conceptually better; the minus sign has a depth (equal to +) and is responsible for the fact that ^{} is not enough, which it would be for T_{\theta}^{}T_{\theta}^{2} – egreg Feb 21 '17 at 09:51
  • @egreg I've added your version, please let me know if I acted correctly! – CarLaTeX Feb 21 '17 at 10:13
1

Another manual workaround is to separate subscripts from superscripts by using braces:

\documentclass{article}
\usepackage{mathtools}

\begin{document}
    \noindent 
    \[
        T_{\theta}\, {T_{\theta}}^{-1} = \begin{pmatrix*}[r] % I've also added also a little space \,
        \cos\theta & -\sin\theta\\
        \sin\theta & \cos\theta
        \end{pmatrix*}\begin{pmatrix*}[r]
        \cos\theta & \sin\theta\\
        -\sin\theta & \cos\theta
        \end{pmatrix*}
        = \begin{pmatrix}1&0\\0&1\end{pmatrix} = I
    \]
\end{document}

In the final output, the subscripts are aligned. The result is slightly different from the first solution:

Example Result

EditPiAf
  • 983
  • If you go this route, it would probably be a good idea to also (a) snug up the \theta subscript to the letter T, say, T_{\!\theta}, and (b) to snug up the superscript -1 to the material that precedes it, say, {...}{!-1}`. – Mico Feb 21 '17 at 10:25
1

You could adjust the fontdimens accordingly.

\documentclass{article}

\usepackage{mathtools}

\begin{document}
\[
    % Regular subscript positon
    \fontdimen16\textfont2=\dimexpr
        \fontdimen17\textfont2 % subscript position in presence of superscript
      + \fontdimen19\textfont2 % subscript drop in presence of superscript
    \relax
    T_\theta T_\theta^{-1} = \begin{pmatrix*}[r]
        \cos\theta & -\sin\theta\\
        \sin\theta & \cos\theta
    \end{pmatrix*}\begin{pmatrix*}[r]
        \cos\theta & \sin\theta\\
        -\sin\theta & \cos\theta
    \end{pmatrix*}
    = \begin{pmatrix}1&0\\0&1\end{pmatrix} = I
\]
\end{document}

enter image description here

Henri Menke
  • 109,596
  • In the screenshot, the two "\theta" subscripts aren't at the same depth. Is this intentional? – Mico Feb 21 '17 at 10:30