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?
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It only takes a minute to sign up.
Sign up to join this communityI 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.
May 25, 2021 at 0:48
\ket{\frac{\uparrow}{\downarrow}}_{A}
doesn't scale the delimiters like \left| ... \right\rangle
would.
May 25, 2021 at 10:57
\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$$
: tex.stackexchange.com/q/503/107497\rangle_{AA}
?