Quantikz:控制门没有通过线连接

Quantikz:控制门没有通过线连接

我正在使用 quantikz 库绘制类似于此的电路图研究论文。我可以看到第 1 和第 4 个量子比特的第 4 个 S 门后的导线中有一个间隙。我尝试摆弄符号 (&),但似乎没有任何效果。我该如何强制显示这些线条?

我得到的输出是这样的: 在此处输入图片描述

我的乳胶代码是这样的:

\documentclass{article}
\usepackage{graphicx} % Required for inserting images
\usepackage{quantikz} % for drawing Quantum Circuits

\begin{document}


\begin{figure}
\centering
\begin{quantikz}
  \lstick{$q_0\  \ket{0}$} & &  \gate{S(0)} & \gate{S(12)} & \ctrl{1} &  \gate{S(0)} & \gate{S(12)} &  &\ctrl{3} & \meter{}  \\
  \lstick{$q_1 \ \ket{0}$} & &  \gate{S(3)} & \gate{S(15)} & \ctrl{} &  \gate{S(3)} & \gate{S(15)}   &   \ctrl{1} & \\
  \lstick{$q_2\  \ket{0}$} & &  \gate{S(6)} & \gate{S(18)} & \ctrl{1} &  \gate{S(6)} & \gate{S(18)} &   \ctrl{} & \\
  \lstick{$q_3 \ \ket{0}$} & &  \gate{S(9)} & \gate{S(21)} & \ctrl{} &  \gate{S(9)} & \gate{S(21)}  & & \ctrl{}   \\
\end{quantikz}

\end{figure}

\end{document}

答案1

的参数\ctrl不能为空。\ctrl{}因此会导致几个错误:

Missing number, treated as zero.
<to be read again> 
                   \relax 
l.15 \end
         {quantikz}

笔记:你永远不应该忽视错误!即使生成了 PDF,您也无法确定 PDF 是否正确。即使它看起来正确,下一次更改也可能破坏它。出现错误后,TeX 只会尝试找到一种简单的语法解决方法,通常是通过忽略代码或添加数学模式或花括号。TeX 无法保证此类解决方法的语义正确性。通常解决方法甚至会导致另一个错误,而此后续错误的解决方法也可能导致其他错误等。因此,如果出现问题,请始终从纠正第一个错误开始。

我认为你们都\ctrl{}应该\ctrl{0}

\listfiles
\documentclass{article}
%\usepackage{graphicx} % Not needed for the example
\usepackage{quantikz} % for drawing Quantum Circuits

\begin{document}


\begin{figure}
\centering
\begin{quantikz}
  \lstick{$q_0\  \ket{0}$} & &  \gate{S(0)} & \gate{S(12)} & \ctrl{1} &  \gate{S(0)} & \gate{S(12)} &  &\ctrl{3} & \meter{}  \\
  \lstick{$q_1 \ \ket{0}$} & &  \gate{S(3)} & \gate{S(15)} &  \ctrl{0} &  \gate{S(3)} & \gate{S(15)}   &   \ctrl{1} & \\
  \lstick{$q_2\  \ket{0}$} & &  \gate{S(6)} & \gate{S(18)} & \ctrl{1} &  \gate{S(6)} & \gate{S(18)} & \ctrl{0}  & \\
  \lstick{$q_3 \ \ket{0}$} & &  \gate{S(9)} & \gate{S(21)} &  \ctrl{0} &  \gate{S(9)} & \gate{S(21)}  & & \ctrl{0}   \\
\end{quantikz}

\end{figure}

\end{document}

但我不知道结果的数字是否正确:

第 2 行和第 3 行末尾有线条

或者你想要:

在此处输入图片描述

其结果是(请注意&第二行和第三行末尾的缺失):

\listfiles
\documentclass{article}
%\usepackage{graphicx} % Not needed for the example
\usepackage{quantikz} % for drawing Quantum Circuits

\begin{document}


\begin{figure}
\centering
\begin{quantikz}
  \lstick{$q_0\  \ket{0}$} & &  \gate{S(0)} & \gate{S(12)} & \ctrl{1} &  \gate{S(0)} & \gate{S(12)} &  &\ctrl{3} & \meter{}  \\
  \lstick{$q_1 \ \ket{0}$} & &  \gate{S(3)} & \gate{S(15)} &  \ctrl{0} &  \gate{S(3)} & \gate{S(15)}   &   \ctrl{1}  \\
  \lstick{$q_2\  \ket{0}$} & &  \gate{S(6)} & \gate{S(18)} & \ctrl{1} &  \gate{S(6)} & \gate{S(18)} & \ctrl{0}   \\
  \lstick{$q_3 \ \ket{0}$} & &  \gate{S(9)} & \gate{S(21)} &  \ctrl{0} &  \gate{S(9)} & \gate{S(21)}  & & \ctrl{0}   \\
\end{quantikz}

\end{figure}

\end{document}

我正在使用 LaTeX2e <2023-11-01> 和 L3 编程层 <2023-11-09>(请参阅文件的开头)以及以下文件版本(请参阅上述示例文件的log结尾):log

 *File List*
 article.cls    2023/05/17 v1.4n Standard LaTeX document class
  size10.clo    2023/05/17 v1.4n Standard LaTeX file (size option)
quantikz.sty    2023/05/24 typeset quantum circuit diagrams
    tikz.sty    2023-01-15 v3.1.10 (3.1.10)
     pgf.sty    2023-01-15 v3.1.10 (3.1.10)
  pgfrcs.sty    2023-01-15 v3.1.10 (3.1.10)
pgfrcs.code.tex
 pgfcore.sty    2023-01-15 v3.1.10 (3.1.10)
graphicx.sty    2021/09/16 v1.2d Enhanced LaTeX Graphics (DPC,SPQR)
  keyval.sty    2022/05/29 v1.15 key=value parser (DPC)
graphics.sty    2022/03/10 v1.4e Standard LaTeX Graphics (DPC,SPQR)
    trig.sty    2021/08/11 v1.11 sin cos tan (DPC)
graphics.cfg    2016/06/04 v1.11 sample graphics configuration
  pdftex.def    2022/09/22 v1.2b Graphics/color driver for pdftex
  pgfsys.sty    2023-01-15 v3.1.10 (3.1.10)
pgfsys.code.tex
pgfsyssoftpath.code.tex    2023-01-15 v3.1.10 (3.1.10)
pgfsysprotocol.code.tex    2023-01-15 v3.1.10 (3.1.10)
  xcolor.sty    2023/11/15 v3.01 LaTeX color extensions (UK)
   color.cfg    2016/01/02 v1.6 sample color configuration
mathcolor.ltx
pgfcore.code.tex
pgfcomp-version-0-65.sty    2023-01-15 v3.1.10 (3.1.10)
pgfcomp-version-1-18.sty    2023-01-15 v3.1.10 (3.1.10)
  pgffor.sty    2023-01-15 v3.1.10 (3.1.10)
 pgfkeys.sty    
pgfkeys.code.tex
 pgfmath.sty    
pgfmath.code.tex
pgffor.code.tex
tikz.code.tex
   xargs.sty    2008/03/22 v1.1  extended macro definitions  (mpg)
 xkeyval.sty    2022/06/16 v2.9 package option processing (HA)
 xkeyval.tex    2014/12/03 v2.7a key=value parser (HA)
  ifthen.sty    2022/04/13 v1.1d Standard LaTeX ifthen package (DPC)
 xstring.sty    2023/08/22 v1.86 String manipulations (CT)
  xparse.sty    2023-10-10 L3 Experimental document command parser
   expl3.sty    2023-11-09 L3 programming layer (loader) 
l3backend-pdftex.def    2023-11-09 L3 backend support: PDF output (pdfTeX)
etoolbox.sty    2020/10/05 v2.5k e-TeX tools for LaTeX (JAW)
mathtools.sty    2022/06/29 v1.29 mathematical typesetting tools
    calc.sty    2023/07/08 v4.3 Infix arithmetic (KKT,FJ)
 mhsetup.sty    2021/03/18 v1.4 programming setup (MH)
 amsmath.sty    2023/05/13 v2.17o AMS math features
 amstext.sty    2021/08/26 v2.01 AMS text
  amsgen.sty    1999/11/30 v2.0 generic functions
  amsbsy.sty    1999/11/29 v1.2d Bold Symbols
  amsopn.sty    2022/04/08 v2.04 operator names
 environ.sty    2014/05/04 v0.3 A new way to define environments
trimspaces.sty    2009/09/17 v1.1 Trim spaces around a token list
supp-pdf.mkii
epstopdf-base.sty    2020-01-24 v2.11 Base part for package epstopdf
epstopdf-sys.cfg    2010/07/13 v1.3 Configuration of (r)epstopdf for TeX Live
 ***********

对于旧版本,quantikz您还需要添加\phantomgate{…}\hphantomgate作为解决方法,以避免电线出现间隙。对于上面的最后一个例子,这将是,例如:

\listfiles
\documentclass{article}
%\usepackage{graphicx} % Required for inserting images
\usepackage{quantikz} % for drawing Quantum Circuits

\begin{document}


\begin{figure}
\centering
\begin{quantikz}
  \lstick{$q_0\  \ket{0}$} & &  \gate{S(0)} & \gate{S(12)} & \ctrl{1} &
  \gate{S(0)} & \gate{S(12)} & \hphantomgate{}  &\ctrl{3} & \meter{}  \\
  \lstick{$q_1 \ \ket{0}$} & &  \gate{S(3)} & \gate{S(15)} &  \ctrl{0} &  \gate{S(3)} & \gate{S(15)}   &   \ctrl{1}  \\
  \lstick{$q_2\  \ket{0}$} & &  \gate{S(6)} & \gate{S(18)} & \ctrl{1} &  \gate{S(6)} & \gate{S(18)} & \ctrl{0}   \\
  \lstick{$q_3 \ \ket{0}$} & &  \gate{S(9)} & \gate{S(21)} &  \ctrl{0} &
  \gate{S(9)} & \gate{S(21)}  & \hphantomgate{} & \ctrl{0}   \\
\end{quantikz}

\end{figure}

\end{document}

参数的宽度\hphantomgate用于表示隐形门的宽度。例如,如果您使用\hphantomgate{this is a very wide gate}水平线,则水平线将比显示的更长\hphantomgate{}。由于旧版本中的错误,quantikz参数\hphantomgate也会导致更大的垂直距离。目前已修复此问题。

相关内容