# Controlling spacing and alignment using Qcircuit

I'm trying to typeset a circuit using Qcircuit and running into some spacing and alignment issues. Here is the portion that is giving me trouble (this will be embedded in a larger diagram):

\documentclass{article}
\usepackage[braket]{Qcircuit}% using  qcircuit version 2.5
\begin{document}
\Qcircuit @C=1em @R=1em @!R {
&                             &&         &\mbox{Black box $\times 3$} \\
&                             &&\gate{H} &\qw &\qw &\qw&\measuretab{A} \\
&\push{\Psi_{GHZ}\Rightarrow} &&\qw      &\gate{H}  &\qw      &\qw &\measuretab{B} \\
&                             &&\qw      &\qw       &\gate{H} &\qw &\measuretab{C}\\
&                             &&\dstick{S_A}\cwx[-3]&\dstick{S_B}\cwx[-2] &\dstick{S_C}\cwx
\gategroup{2}{3}{4}{6}{1em}{\{}
\gategroup{2}{4}{2}{6}{.8em}{--}
\gategroup{3}{4}{3}{6}{.8em}{--}
\gategroup{4}{4}{4}{6}{.8em}{--}
}
\end{document}


The result is:

The dashed boxes are all in the right place but I would like for them to be equally sized and nicely aligned & spaced, as well as the \psi_{GHZ} aligned with the big brace. I've tried various things to do with varying row & group spacings, \vphantom, \vspace, and \push (as described in the Qcircuit documentation) but nothing seems to help much. How do I achieve the desired effect?

Like it says in the Qcircuit tutorial, \gategroup only uses the four corner objects for sizing the enclosing box. The problem you're having is that the entries at the corners are different sizes. You can get around this by extending the boxes out to empty entries and then placing invisible struts of the appropriate size in those entries using \push and \rule. Here's my rendition of the circuit you were trying to make:

Here's the code used to typeset it:

\documentclass{standalone}
\input{Qcircuit}% using  qcircuit version 2.5
\begin{document}
\begin{tabular}{c}
\vspace{-.6em}\\
\Qcircuit @C=.5em @R=1em @!R {
& & & & & & & \mbox{Black box $\times 3$} \\
& & & \qw & \push{\rule{0em}{1.2em}} \qw & \gate{H} & \qw & \qw & \qw & \qw & \qw & \qw & \measuretab{A} \\
& \push{\Psi_{GHZ}\Rightarrow\ \ } & & \qw &\push{\rule{0em}{1.2em}} \qw & \qw &\qw&\gate{H} & \qw & \qw & \qw & \qw & \measuretab{B} \\
& & & \qw & \push{\rule{0em}{1.2em}} \qw & \qw & \qw & \qw & \qw & \gate{H} & \qw & \qw & \measuretab{C} \\
& & & & & \dstick{S_A}\cwx[-3] & &\dstick{S_B}\cwx[-2] & & \dstick{S_C} \cwx
\gategroup{2}{3}{4}{3}{1em}{\{}
\gategroup{2}{5}{2}{11}{.8em}{--}
\gategroup{3}{5}{3}{11}{.8em}{--}
\gategroup{4}{5}{4}{11}{.8em}{--}
}
\vspace{2em}\hspace{1em}
\\
\end{tabular}
\end{document}


Note that, to get things to look right, I had to reduce the base column spacing and add more wire commands. The issue with the location of your label on the left was fixed by setting the region sized by the bracket to only the leftmost column.