5

I'm looking for a way to use color in qcircuit (based on xy-pic). I'd like to be able to add a background color for a gate, and for a gategroup. For exemple, how can I change this code:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}     
\usepackage{graphicx}
\usepackage[]{qcircuit}

\begin{document}
\Qcircuit @C=1em @R=1em {
& \ctrl{2} & \qw & \gate{H} & \ctrl{1} &
\gate{H} & \qw \\
& \qw & \ctrl{1} & \gate{H} & \targ &
\gate{H} & \qw \\
& \targ & \targ & \gate{Z} & \qw & \ctrl{-1} &
\qw \gategroup{1}{4}{2}{6}{.7em}{-}
}
\end{document}

so that it produces something like that:

enter image description here

Thank you !

tobiasBora
  • 8,684
  • See also https://tex.stackexchange.com/questions/199683/how-to-plot-quantum-logical-gates-with-tikz – John Kormylo Sep 03 '17 at 13:56
  • @JohnKormylo: I would like to avoid to draw circuits in tikz, because for now it takes to much time, and it's not easy to draw nodes that span several wires in a clear way... – tobiasBora Sep 03 '17 at 14:45

1 Answers1

3

There is no convenient way to do this using Qcircuit and Xy-pic. I generally use the pgf package to draw colored boxes behind the regions of the circuit of interest. Aligning the colors precisely with the circuit elements is a pain, but it can be done as shown below:

enter image description here

This was typeset using the following code:

\documentclass{standalone}
\usepackage{color}
\usepackage{pgf}
\input{Qcircuit}% using  Qcircuit version 2.5
\begin{document}
\hspace{1em}
\begin{tabular}{c}
\vspace{-.6em}\\
\begin{pgfpicture}{0em}{0em}{0em}{0em}
\color{cyan}
\pgfrect[fill]{\pgfpoint{5.05em}{-5.2em}}{\pgfpoint{1.35em}{1.25em}}
\color{green}
\pgfrect[fill]{\pgfpoint{4.6em}{-3.28em}}{\pgfpoint{6.55em}{4.3em}}
\end{pgfpicture}
    \Qcircuit @C=1em @R=1em {
        & \ctrl{2} & \qw & \gate{H} & \ctrl{1} & \gate{H} & \qw \\
        & \qw & \ctrl{1} & \gate{H} & \targ & \gate{H} & \qw \\
        & \targ & \targ & \gate{Z} & \qw & \ctrl{-1} & \qw
        \gategroup{1}{4}{2}{6}{.7em}{-}
    }
\vspace{1.2em}\hspace{1.2em}
\\
\end{tabular}
\end{document}
beastin
  • 356