# Qcircuit: How to insert a vertical dashed line in a circuit?

I want to insert vertical dashed lines between parts of the following circuit to make some comments:

\documentclass{amsart}
\usepackage[matrix,frame,arrow]{xy}
\input{Qcircuit}
\vfuzz2pt % Don't report over-full v-boxes if over-edge is small
\begin{document}
$\Qcircuit @C=1em @R=1em { \lstick{\ket{x}} & \qw & \ctrl{1} & \qw & \rstick{\ket{x}} \qw \\ \lstick{\ket{y}} & \gate{H} & \gate{\pi} & \gate{H} & \rstick{\ket{y \oplus x}} \qw }$
\end{document}


Output:

I have found a similar question (xypic: How to typeset the dashed line in this diagram? ) concerning xy-pic, it is the same idea, it should be the same solution. But it's not working, I don't know why.

Note: Q-circuit is a Qcircuit.tex macro package for drawing quantum circuit diagrams in LaTeX

• Welcome to TeX.SX! Please make your code compilable, starting with \documentclass{...} and ending with \end{document}. That may seem tedious to you, but think of the extra work it represents for TeX.SX users willing to help you. Help them help you: remove that one hurdle between you and a solution to your problem. – jub0bs Aug 7 '13 at 7:10
• Can you give an idea/sketch inside Q where the dotted line should be or do you need a box encompassing the [H] ?. The answers to your linked Q will work if you remove the \input{Qcircuit} macro which is specifically defined for \Qcircuit. Those answers need only pure xy-pic \usepackage[all]{xy} – texenthusiast Aug 7 '13 at 7:33

Here is an example placement. I have used a dotted rather than dashed line for clarity. To get dashes use \ar@{--} instead of \ar@{.}.

\documentclass{article}

\input{Qcircuit}

\begin{document}

\Qcircuit @C=1em @R=1em {
\lstick{\ket{x}} & \qw \ar@{.}[]+<3.5em,1em>;[d]+<3.5em,-1em>
& \ctrl{1} & \qw & \rstick{\ket{x}} \qw \\
\lstick{\ket{y}} & \gate{H} & \gate{\pi} & \gate{H} & \rstick{\ket{y \oplus x}} \qw
}
\end{document}


The command used was:

\ar@{.}[]+<3.5em,1em>;[d]+<3.5em,-1em>


placed at the node where you want the line to start. The [d] points to the node one line down, [dd] would send you two lines down instead, [r] would make the line go to the right. The <3.5em,1em> means the line starts 3.5em to the right and 1em above the starting node. Similarly <3.5em,-1em> puts the end 3.5em to the right and 1em below the end node.

• It works but a problem happens when include \usepackage[francais]{babel}and \usepackage[utf8]{inputenc}, the line is not vertical and a part of the command is displayed in the output file! – thriller91 Aug 7 '13 at 10:30
• That is because ; is a shorthand in that set-up. Use a \shorthandoff{;} as e.g. \Qcircuit @C=1em @R=1em { \shorthandoff{;}..., cf. tex.stackexchange.com/a/86025/15925 – Andrew Swann Aug 7 '13 at 11:04