quantikz 表格内的电路图

quantikz 表格内的电路图

我想将电路列表制成表格。不幸的是,quantikz 使用类似表格环境的对象“&”。我在这里看到了一个使用 savebox 的解决方案:

Quantikz 并排和标题

但对于大表来说,这种解决方案不切实际。有没有更好的方法?

以下是代码示例

\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}

它给出了正确的输出,但也为每个声明的 quantikz 给出了以下错误。

 ! Missing { inserted.
<inserted text> 
                {

答案1

如果您只想要一个具有两列的非常简单的表格,您可以这样做:

\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}

当然,您可以调整框的大小以适应。

在此处输入图片描述

答案2

共有 256 个盒子寄存器,但其中只有不到 200 个可用。如果将表格放入独立程序中,则所有空闲寄存器都可使用。

注意:第三列仅用于演示目的。

\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}

演示

答案3

如果您\begin{quantikz}用替换\begin{tikzcd},它就可以正常工作!

\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}

(这是因为 tikzcd 和 quantikz 对 & 字符的处理略有不同。IIRC 这是使其与外部库一起工作的一部分。如果您不使用外部,则没有理由使用 quantikz 而不是 tikzcd。)

如果您想让它与外部库一起工作,那就是另一回事了!(我没有为此准备的设置……)

答案4

如果需要该external库,请\egroup {在每个库后添加\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}

你会发现\endgroup}不能用来替代\egroup,且\bgroup\begingroup不能用来替代{

我真的很惊讶我找到了这个解决方法,并且花了很大力气才找到解释它为什么有效的方法。希望一些更有知识的人或作者quantikz能够设法用这个来修复这个包。测试用: pdfTeX, Version 3.14159265-2.6-1.40.19 (TeX Live 2019/dev/Debian) (preloaded format=pdflatex)

相关内容