2

I have these 3 quantum circuits and want to put the three side by side. Is there a way to do it? I'm using the quantikz package. Is there also a way to put titles in the circuits?

\begin{quantikz}
& \ctrl{1} & \qw \\
\lstick{$\ket{0}$} & \targ{} & \qw
\end{quantikz}

\begin{quantikz}
& \ctrl{2} & \qw \\
& \ctrl{1} & \qw \\
\lstick{$\ket{0}$} & \targ{} & \qw
\end{quantikz}

\begin{quantikz}
& \gate{X} & \ctrl{2} & \gate{X} & \qw \\
& \gate{X} & \ctrl{1} & \gate{X} & \qw \\
\lstick{$\ket{0}$} & \qw & \targ{} & \gate{X} & \qw
\end{quantikz}
4
  • Welcome to TeX.SE! Remove empty lines between them.
    – Zarko
    Commented Jun 6, 2019 at 13:32
  • In (La)TeX an empty line starts a new paragraph, therefore (as Zarko said), you should remove those empty lines (if you want to keep the vertical separation in your source code, you can place a % in those lines).
    – Skillmon
    Commented Jun 6, 2019 at 14:01
  • After downloading and reading the manual, it seems only slices have titles. OTOH, you can add anything outside quabtikz. Commented Jun 6, 2019 at 16:24
  • It occurred to me that since quantikz is based on tikz-cd, one should look at how tikz-cd handles labels. It turns out that if you simply insert text into the code, it will show up (somewhere). Commented Jun 7, 2019 at 2:10

2 Answers 2

3

This solution adds titles using tabular. Unfortunately, tabular objects to the use of & in quantikz, so I had to store them in saveboxes.

It should be noted that one can also put saveboxes inside tikz nodes, in case you want to add titles overlapping the quantikz images. Not sure what good [remember picture] would do if you can't name components.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{quantikz}

\begin{document}

\begin{figure}
\centering
\sbox0{\begin{quantikz}
& \ctrl{1} & \qw \\
\lstick{$\ket{0}$} & \targ{} & \qw
\end{quantikz}}%
\sbox1{\begin{quantikz}
& \ctrl{2} & \qw \\
& \ctrl{1} & \qw \\
\lstick{$\ket{0}$} & \targ{} & \qw
\end{quantikz}}%
\sbox2{\begin{quantikz}
& \gate{X} & \ctrl{2} & \gate{X} & \qw \\
& \gate{X} & \ctrl{1} & \gate{X} & \qw \\
\lstick{$\ket{0}$} & \qw & \targ{} & \gate{X} & \qw
\end{quantikz}}%
\begin{tabular}{ccc}
Title A & Title B & Title C \\
\usebox0 & \usebox1 & \usebox2
\end{tabular}
\end{figure}

\end{document}

demo

1

As has already been said, the tabular environment works great for organising the circuits + titles. However, you don't need to go to the lengths of using a savebox. So long as you're not using the external library, just replace \begin{quantikz} with \begin{tikzcd}:

\begin{tabular}{ccc}
Controlled-not & Toffoli & something else \\
\begin{tikzcd}
& \ctrl{1} & \qw \\
\lstick{$\ket{0}$} & \targ{} & \qw
\end{tikzcd}
&
\begin{tikzcd}
& \ctrl{2} & \qw \\
& \ctrl{1} & \qw \\
\lstick{$\ket{0}$} & \targ{} & \qw
\end{tikzcd}
&
\begin{tikzcd}
& \gate{X} & \ctrl{2} & \gate{X} & \qw \\
& \gate{X} & \ctrl{1} & \gate{X} & \qw \\
\lstick{$\ket{0}$} & \qw & \targ{} & \gate{X} & \qw
\end{tikzcd}
\end{tabular}

Another option that gives you a lot more control over placement (particularly if you don't like the centering of the titles!) is to embed everything as nodes inside a tikzpicture:

\begin{tikzpicture}
\node at (0,0) {controlled-not};
\node at (0,-0.1) [anchor=north]{\begin{tikzcd}
& \ctrl{1} & \qw \\
\lstick{$\ket{0}$} & \targ{} & \qw
\end{tikzcd}};
\node at (3,0) {Toffoli};
\node at (3,-0.1) [anchor=north]{
\begin{tikzcd}
& \ctrl{2} & \qw \\
& \ctrl{1} & \qw \\
\lstick{$\ket{0}$} & \targ{} & \qw
\end{tikzcd}};
\node at (6,0) {something else};
\node at (6,-0.1) [anchor=north]{
\begin{tikzcd}
& \gate{X} & \ctrl{2} & \gate{X} & \qw \\
& \gate{X} & \ctrl{1} & \gate{X} & \qw \\
\lstick{$\ket{0}$} & \qw & \targ{} & \gate{X} & \qw
\end{tikzcd}};
\end{tikzpicture}

You must log in to answer this question.

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