4

I want to tabulate a list of circuits. Unfortunately, quantikz uses object '&' like table environment. I saw a solution that uses savebox here:

Quantikz side by side and titles

but this solution is impractical for a big table. Is there a better way?

Here is a code example

\begin{tabular}{c | c}
     Name  & Circuit \\
     \hline
     Pauli-$Z$    &\begin{quantikz} & \gate{Z} & \qw \end{quantikz} \\
     $z$-rotation &\begin{quantikz} & \gate{R_z(\theta)}&\qw\end{quantikz} \\
     \hline
\end{tabular}

which gives the correct output, but also giving the following error for every declared quantikz.

 ! Missing { inserted.
<inserted text> 
                {
2
  • The problem is that tabular pre-scans for & symbols, so at best you are going to confuse the heck out of it when the &s are eaten by quantikz. Interestngly, \edef\testA{\begin{quantikz} & \gate{Z} & \qw \end{quantikz}}% gives the same error message. So just how big is this tabular? Mar 3, 2020 at 14:48
  • around 20 entries :-/ May 3, 2020 at 22:16

4 Answers 4

2

If you only want a very simple table with two columns, you could so this:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{quantikz}
\newcommand\qthead[2]{\makebox[42pt][c]{\textbf{#1}}\makebox[260pt][c]{\textbf{#2}}\smallskip\hrule\medskip}
\newcommand\qtline[2]{\makebox[42pt][c]{#1}\makebox[260pt][c]{\begin{quantikz}& #2 & \qw \end{quantikz}}}
\newenvironment{qtab}{\par\bigskip\bgroup\parindent32pt\obeylines}{\egroup\bigskip}
\begin{document}

In theory, the interrelation of system and/or subsystem technologies must utilize
and be functionally interwoven with the evolution of specifications over a given
time period.  In particular, any associated supporting element necessitates that
urgent consideration be applied to possible bidirectional logical relationship
approaches.  

\begin{qtab}
\qthead {Name}         {Circuit}
\qtline {Pauli-$Z$}    {\gate{Z}}
\qtline {$z$-rotation} {\gate{R_z(\theta)}}
\end{qtab}

It is assumed that the product configuration baseline recognizes other
systems' importance and the necessity for the total system rationale.
Of course, the product assurance architecture necessitates that urgent
consideration be applied to the greater fight-worthiness concept.  

\end{document}

You can, of course, adjust the sizes of the boxes to suit.

enter image description here

1
  • that is perfect! thank you! :) May 3, 2020 at 22:21
4

There are 256 box registers, although less than 200 are available for use. If you put the tabular into a standalone, all of the free registers can be used.

Note: the third column is for demonstration purposes only.

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

\newsavebox{\boxA}
\newsavebox{\boxB}
\newinsert{\last}% MWE only

\begin{document}
\savebox{\boxA}{\begin{quantikz} & \gate{Z} & \qw \end{quantikz}}%
\savebox{\boxB}{\begin{quantikz} & \gate{R_z(\theta)}&\qw \end{quantikz}}%
\begin{tabular}{c | c | c}
     Name  & Circuit & register \\
     \hline
     Pauli-$Z$    & \usebox\boxA & \the\boxA \\
     $z$-rotation & \usebox\boxB & \the\boxB \\
     && up to \the\last \\
     \hline
\end{tabular}
\end{document}

demo

1
  • Thanks for the code!. I accept the first answer since it is the best one for the question. However, your code is useful for an arbitrary quantikz circuit, which I'm also using it now. :) May 3, 2020 at 22:33
1

If you replace \begin{quantikz} with \begin{tikzcd}, it works just fine!

\begin{tabular}{c | c}
     Name  & Circuit \\
     \hline
     Pauli-$Z$    &\begin{tikzcd} & \gate{Z} & \qw \end{tikzcd} \\
     $z$-rotation &\begin{tikzcd} & \gate{R_z(\theta)}&\qw\end{tikzcd} \\
     \hline
\end{tabular}

(This is because tikzcd and quantikz treat the & character slightly differently. IIRC this was part of getting it to work with the external library. If you're not using external, there's no reason to use quantikz rather than tikzcd.)

If you want to make it work with the external library, that's another matter! (I don't have a working setup for this....)

1
  • Worked for me very nicely thanks Nov 15, 2022 at 23:05
0

If you need the external library, add \egroup { after each \end{quantikz}:

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{quantikz}
\usetikzlibrary{external}

\begin{document}

\begin{tabular}{c | c}
     Name  & Circuit \\
     \hline
     Pauli-$Z$    &\begin{quantikz} & \gate{Z}          &\qw\end{quantikz} \egroup {\\
     $z$-rotation &\begin{quantikz} & \gate{R_z(\theta)}&\qw\end{quantikz} \egroup {\\
     \hline
\end{tabular}

\end{document}

You will find that \endgroup and } cannot be used to replace \egroup, and \bgroup and \begingroup cannot be used to replace {.

I am actually very surprised that I found this workaround, and way in over my head to find an explanation of why it works. Hopefully some more knowledgeable person or the quantikz author will manage to fix the package with this. Tested with: pdfTeX, Version 3.14159265-2.6-1.40.19 (TeX Live 2019/dev/Debian) (preloaded format=pdflatex).

You must log in to answer this question.

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