I can offer a modified \underbrace
command that takes optional arguments to specify the amount of space to cut from the left and from the right, using the widest entry (with some space added).
\documentclass[12pt]{article}
\usepackage{tikz}
\usetikzlibrary{quantikz2}
\newlength{\Ubraceignoreleft}
\newlength{\Ubraceignoreright}
\NewDocumentCommand{\Ubrace}{ommo}{%
% #1 = optional part to ignore (on the left)
% #2 = object to be underbraced
% #3 = subscript
% #4 = optional part to ignore (on the right)
{% start a group to fix the spacing
% and to limit the setting to the lengths
\IfValueT{#1}{\settowidth{\Ubraceignoreleft}{$#1$}}%
\IfValueT{#4}{\settowidth{\Ubraceignoreright}{$#4$}}%
\hspace*{\Ubraceignoreleft}
\underbrace{%
\hspace*{-\Ubraceignoreleft}%
#2%
\hspace*{-\Ubraceignoreright}%
}_{#3}%
\hspace*{\Ubraceignoreright}%
}%
}
\begin{document}
\[
\Ubrace[\ket{\psi_1}\enspace]{
\begin{quantikz}
\lstick{\ket{\psi_1}} & \ctrl{1} & \\
\lstick{\ket{\psi_2}} & \targ{} &
\end{quantikz}
}{\text{text}}
\]
\end{document}
The \enspace
was computed “by eye”.
Basically, the space is added in front of the \underbrace
command, and removed inside it. Similarly if you want to cut from the right. I don't know whether you need to remove from the right, but, you know, mathematicians love symmetry.