4

I am trying to type

$$\left|\uparrow\right\rangle_A{}_A\left\langle\uparrow\right|$$

But the As in the subscript are not symmetrical. One is upper and another is lower. Is there a way to type this more elegantly?

2 Answers2

6

One way is to use \DeclarePairedDelimiter from mathtools package (an extension of amsmath):

\documentclass{article}
\usepackage{mathtools}

\DeclarePairedDelimiter{\ket}{\lvert}{\rangle} \DeclarePairedDelimiter{\bra}{\langle}{\rvert}

\begin{document} [ \left|\uparrow\right\rangle_A{}_A\left\langle\uparrow\right| ]

[ \ket{\uparrow}{A} {}{A}\bra{\uparrow} ] \end{document}

enter image description here

Edit

For fractions or tall expressions as leftaroundabout said in the comments, mathtools provides two options: An optional parameter \ket[size command]{something} and a starred version \ket*{something} that is preceded by \left and \right so they "grow" to match the content inside.

There are more additions to de delimiters, for example \DeclarePairedDelimiterX to be able to use arguments in the definition, as a \newcommand. Some examples from the manual:

\documentclass{article}
\usepackage{mathtools}

\DeclarePairedDelimiter{\ket}{\lvert}{\rangle} \DeclarePairedDelimiter{\bra}{\langle}{\rvert} \DeclarePairedDelimiterX\braket[3]{\langle}{\rangle}% {#1,\delimsize\vert,\mathopen{}#2,\delimsize\vert,\mathopen{}#3}

\begin{document} [ \bra[\Big]{\frac{a}{b}}, \quad \ket{\frac{a}{b}}, \quad \braket{B}{\sum_{k} f_k}{C} ] \end{document}

enter image description here

For the subindex in this taller delimiters it is still needed \prescript as in leftaroundabout answer.

Luis Turcio
  • 2,757
  • Perfect! Thanks! – user824530 May 25 '21 at 00:36
  • Nice, except that the names are exactly backward from the same constructions provided by the braket package. – barbara beeton May 25 '21 at 00:48
  • @barbarabeeton Whoops! My bad, I didn’t remember how is Dirac notation. In a minute I will do the correction. Thanks for pointing that mistake – Luis Turcio May 25 '21 at 02:01
  • Can this be made to work also with tall expressions in the bra/kets? E.g. \ket{\frac{\uparrow}{\downarrow}}_{A} doesn't scale the delimiters like \left| ... \right\rangle would. – leftaroundabout May 25 '21 at 10:57
  • @leftaroundabout Thanks for pointing that out. I have edited the answer to cover your comments – Luis Turcio May 25 '21 at 12:47
  • Ok. But, as I see it \DeclarePairedDelimiter, albeit useful for other reasons, doesn't really do anything about the subscript alignment at all, right? Your original solution doesn't really do more than \left|\uparrow\right\rangle{}_A{}_A\left\langle\uparrow\right| in that regard. – leftaroundabout May 25 '21 at 13:04
1
\documentclass{article}
\usepackage{mathtools}

\begin{document}

% I would use \prescript:

\[
  \left|\uparrow\right\rangle_A\prescript{}{A}{\left\langle\uparrow\right|}
\]

low kets

% Note that this also works when the kets get taller:

\[
  \left|\frac{\uparrow}{\downarrow}\right\rangle_A
   \prescript{}{A}{\left\langle\frac{\uparrow}{\downarrow}\right|}
\]

tall kets

% Shame about the (lack of) kerning. We might hack it to be a bit more snug with some manual spacing adjustments:

\[
  \left|\frac{\uparrow}{\downarrow}\right\rangle_{\!\!A}
   \: \prescript{}{A}{\!\left\langle\frac{\uparrow}{\downarrow}\right|}
\]

with hacked kerning

\end{document}