2

I'm trying to annotate certain parts of my quantikz circuit and drawing boxes around some gates:

\documentclass{article}
\usepackage{graphicx}
\usepackage{amssymb,amsfonts,dsfont}
\usepackage{tikz}
\usetikzlibrary{quantikz}

\begin{document}

\begin{quantikz}[row sep={20pt,between origins},column sep=.2cm,font=\small]
\lstick{\ket{0}} & \qw & \qw & \qw & \qw & \qw &[1cm] \qw & \qw \\
\lstick{\ket{0}} & \qw & \qw\qwbundle{} & \qw & \qw & \qw &[1cm] \qw & \gate[3]{U_2} \\
\lstick{\ket{0}} & \qw & \qw\qwbundle{} & \qw & \qw & \qw &[1cm] \qw & \qw \\
\lstick{\ket{0}} & \qw & \qwbundle{} & \gate{H}\gategroup[wires=2,steps=3,style={dashed,rounded corners,fill=white,inner xsep=2pt},background]{mylabel}  & \ctrl{1} & \gate{U_1} &[1cm] \qw & \qw \\
\lstick{\ket{b}} & \qw & \qw\qwbundle{} & \qw & \gate{Z} & \qw &[1cm] \qw & \qw \\
\end{quantikz} 

\end{document}

and I want it to look like:

enter image description here

I read the quantikz docs and adapted the gategroup examples on p. 13, but I get an error that I don't understand: l.76 I think the culprit is a tikzcd arrow in cell 5-8. \errmessage ...currentrow -\tikzcd@currentcolumn }

2 Answers 2

0

enter image description here

I think it is better to try to do the drawing directly, without specialized libraries. I suggest the solution below which is based on the fit command to group nodes in a rectangle.

The code

\documentclass[border=5mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{fit, math}

\begin{document}

\newcommand{\ket}[1]{$|#1\rangle$}
\tikzset{%
  box/.style={draw, fill=white,
    minimum width=2em, minimum height=4ex,
    inner sep=1ex, outer sep=.2ex%
  },
    hbox/.style={draw, fill=white,
    minimum width=2em, minimum height=#1 ex,
    inner sep=1ex, outer sep=.2ex%
  },
  dot/.style={circle, fill=black, minimum size=1ex,
    inner sep=0pt, outer sep=2pt}
}
\begin{tikzpicture}[evaluate={real \a, \posl; \a=6; \posl=.75;}]
  \draw (0, 1) node {\ket{0}} ++(.5, 0) -- ++(.5, 0) -- ++(\a, 0);
  \draw (0, 0) node {\ket{0}} ++(.5, 0) -- ++(.5, 0) node {$/$} -- ++(\a, 0);
  \draw (0, -1) node {\ket{0}} ++(.5, 0) -- ++(.5, 0) node {$/$} -- ++(\a, 0)
  coordinate (U1);
  \draw (0, -2) node {\ket{0}} ++(.5, 0) -- ++(.5, 0) node {$/$} -- ++(\a, 0)
  node[pos=.15, box] (H) {$H$} node[pos=.3, dot] {} node[pos=.45, box] (U) {$U_1$}
  node[pos=\posl, red, above] (a) {\ket{a}};
  \draw (0, -3) node {\ket{b}} ++(.5, 0) -- ++(.5, 0) node {$/$} -- ++(\a, 0)
  node[pos=.3, box] (Z) {$Z$}
  node[pos=\posl, blue, above] (b) {$\beta$\/\ket{b}}
  node[pos=\posl, blue, below=1ex] (ab) {$\beta\,${\color{red}\ket{a}}\ket{b}};
  
  \path node[draw, dashed, fit={(H) (U) (Z)}, inner sep=1.5ex,
  label={270: my label}] {}
  node[fill=gray, opacity=.15, fit={(a) (b)}, inner sep=.5ex] {};
  \path (U1) node[hbox=15] {$U_1$};
\end{tikzpicture}
\end{document}
0

The problem is that you put \\ at the end of the last line of the circuit.

Furthermore some small changes to the gategroup regarding positioning of the label and size of the box.

\documentclass{article}
\usepackage{graphicx}
\usepackage{amssymb,amsfonts,dsfont}
\usepackage{tikz}
\usetikzlibrary{quantikz}

\begin{document}

\begin{quantikz}[row sep={20pt,between origins},column sep=.2cm,font=\small]
\lstick{\ket{0}} & \qw & \qw & \qw & \qw & \qw &[1cm] \qw & \qw \\
\lstick{\ket{0}} & \qw & \qw\qwbundle{} & \qw & \qw & \qw &[1cm] \qw & \gate[3]{U_2} \\
\lstick{\ket{0}} & \qw & \qw\qwbundle{} & \qw & \qw & \qw &[1cm] \qw & \qw \\
\lstick{\ket{0}} & \qw & \qwbundle{} & \gate{H}\gategroup[wires=2,steps=3,style={dashed,rounded corners,fill=white,inner xsep=0pt},background,label style={label position=below,anchor=
north,yshift=-0.2cm}]{mylabel}  & \ctrl{1} & \gate{U_1} &[1cm] \qw & \qw \\
\lstick{\ket{b}} & \qw & \qw\qwbundle{} & \qw & \gate{Z} & \qw &[1cm] \qw & \qw
\end{quantikz} 

\end{document}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .