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?
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?
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}
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}
For the subindex in this taller delimiters it is still needed \prescript as in leftaroundabout answer.
braket package.
– barbara beeton
May 25 '21 at 00:48
\ket{\frac{\uparrow}{\downarrow}}_{A} doesn't scale the delimiters like \left| ... \right\rangle would.
– leftaroundabout
May 25 '21 at 10:57
\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
\documentclass{article}
\usepackage{mathtools}
\begin{document}
% I would use \prescript:
\[
\left|\uparrow\right\rangle_A\prescript{}{A}{\left\langle\uparrow\right|}
\]
% 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|}
\]
% 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|}
\]
\end{document}
\[...\]is preferred over$$: https://tex.stackexchange.com/q/503/107497 – Teepeemm May 25 '21 at 11:38\rangle_{AA}? – md2perpe May 25 '21 at 17:50