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?

3
  • 2
    Unrelated, but \[...\] is preferred over $$: tex.stackexchange.com/q/503/107497
    – Teepeemm
    May 25, 2021 at 11:38
  • 1
    Why not just use \rangle_{AA}?
    – md2perpe
    May 25, 2021 at 17:50
  • @md2perpe sometimes I would need them separately with some other stuff between. In such case the asymmetrical typesetting looks weird
    – user824530
    May 26, 2021 at 2:27

2 Answers 2

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.

6
  • Perfect! Thanks!
    – user824530
    May 25, 2021 at 0:36
  • Nice, except that the names are exactly backward from the same constructions provided by the braket package. May 25, 2021 at 0: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 May 25, 2021 at 2: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. May 25, 2021 at 10:57
  • @leftaroundabout Thanks for pointing that out. I have edited the answer to cover your comments May 25, 2021 at 12:47
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}

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.