# How to hide a part of my Qcircuit?

With the help of qcircuit.tex (official main page) I created the representation of a quantum circuit. I now want to hide some parts of the circuit, just like \phantom{} would do (but it seems like I can't use \phantom{} inside the qcircuit environment).

Below is the graphical representation of my circuit (MWE at the end):

I tried to draw a white rectangle above the part I wanted to hide with TikZ, but after a long fight against box sizes, I could not find a way to superpose nicely a white TikZ rectangle over my circuit.

Example of result I would like to have:

Minimal Working Example (needs qcircuit.tex and graphicx):

\documentclass{beamer}
\usepackage{graphicx}                 % Many thing (scalebox)
\usepackage{qcircuit}                 % Draw quantum circuits

\newcommand{\ket}[1]{\ensuremath{\left\vert #1 \right\rangle}}

\begin{document}

\begin{frame}
\begin{figure}[h]
\centering
\leavevmode
\resizebox{.95\linewidth}{!}{
\Qcircuit @C=1em @R=2em {
\lstick{\ket{0}}    & \qw  & \qw      & \qw & \qw      & \qw               & \qw                                                & \gate{R_y(\lambda^{-1})} & \qw                                        & \qw              & \qw      & \meter & \rstick{\ket{1}} \cw \\
\lstick{\ket{0}^m}  & \qw  & {/^m}\qw & \qw & \gate{H} & \ctrl{1}          & \gate{\mathcal{Q}\mathcal{F}\mathcal{T}_m^\dagger} & \ctrl{-1}                & \gate{\mathcal{Q}\mathcal{F}\mathcal{T}_m} & \ctrl{1}         & \gate{H} & \qw    & \rstick{\ket{0}^m} \qw \\
\lstick{\ket{b}}    & \qw  & {/^n}\qw & \qw & \qw      & \gate{e^{-iAt_0}} & \qw                                                & \qw                      & \qw                                        & \gate{e^{iAt_0}} & \qw      & \qw    & \rstick{\ket{x}} \qw \\
}
}
\caption{Starting point for HHL algorithm}
\label{fig:hhl1}
\end{figure}
\end{frame}

\end{document}


You can use a \clipbox from the trimclip package, which is part of the adjustbox package bundle.

In the example below there are two variants: one without the floating figure environment (using \captionof from the caption package for the caption), which is aligned left, and one with the floating environment, which is centered. Note that I removed the leavevmode line.

The \clipbox command can be used in different ways. In this example the version with four arguments is used, indicating the amount of clipping left, bottom, right, top. Note that there is a bit of negative clip on the left, for some reason a bit of the figure was clipped when providing 0pt.

MWE:

\documentclass{beamer}
\usepackage{graphicx}                 % Many thing (scalebox)
\usepackage{qcircuit}                 % Draw quantum circuits
\usepackage{trimclip}
\usepackage{caption}

\newcommand{\ket}[1]{\ensuremath{\left\vert #1 \right\rangle}}
\newcommand{\hhlcircuit}{\Qcircuit @C=1em @R=2em {
\lstick{\ket{0}}    & \qw  & \qw      & \qw & \qw      & \qw               & \qw                                                & \gate{R_y(\lambda^{-1})} & \qw                                        & \qw              & \qw      & \meter & \rstick{\ket{1}} \cw \\
\lstick{\ket{0}^m}  & \qw  & {/^m}\qw & \qw & \gate{H} & \ctrl{1}          & \gate{\mathcal{Q}\mathcal{F}\mathcal{T}_m^\dagger} & \ctrl{-1}                & \gate{\mathcal{Q}\mathcal{F}\mathcal{T}_m} & \ctrl{1}         & \gate{H} & \qw    & \rstick{\ket{0}^m} \qw \\
\lstick{\ket{b}}    & \qw  & {/^n}\qw & \qw & \qw      & \gate{e^{-iAt_0}} & \qw                                                & \qw                      & \qw                                        & \gate{e^{iAt_0}} & \qw      & \qw    & \rstick{\ket{x}} \qw \\
}}

\begin{document}

\begin{frame}
\clipbox{-20pt 0pt 238pt 0pt}{%
\resizebox{.95\linewidth}{!}{\hhlcircuit}%
}
\captionof{figure}{Starting point for HHL algorithm}

\begin{figure}[h]
\clipbox{-20pt 0pt 238pt 0pt}{%
\resizebox{.95\linewidth}{!}{\hhlcircuit}%
}
\caption{Starting point for HHL algorithm}
\label{fig:hhl2}
\end{figure}

\end{frame}

\end{document}


Result:

• I will try that tomorrow! Thanks for the quick (and nice!) answer ;) – Nelimee Jul 3 '18 at 15:50