2

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 !

2

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}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.