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

  • Have you tried ^{} ? – daleif Feb 21 '17 at 7:58
  • @daleif Sorry, at first I didn't understand that you intended ^{} instead of ^{\vphantom{-1}}. However, it doesn't work... – CarLaTeX Feb 21 '17 at 8:10
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

  • 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 9:51
  • @egreg I've added your version, please let me know if I acted correctly! – CarLaTeX Feb 21 '17 at 10:13
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

  • In the screenshot, the two "\theta" subscripts aren't at the same depth. Is this intentional? – Mico Feb 21 '17 at 10:30
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

  • 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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.