在 quantikz2 中排列空线

在 quantikz2 中排列空线

我希望能够用编织线绘制一些电路。tikzlibrary quantikz2这里) 有一个\permute门,它几乎可以满足我的要求,但如果某一行有一根空线,就会出现问题。

我想要绘制的是这样的:在此处输入图片描述

我创建了新命令(见下文代码),称为\mypermute和,它们与和\mywirepair@end@完全相同,但调用会在绘制导线之前检查目标是否大于零。我将这些命令放在名为(见下文)的新 tikzlibrary 文件中。\permute\wirepair@end@\mypermute\mywirepair@end@tikzlibrarymypermute.code.tex

现在我可以制作一个看起来几乎正如我想要的那样,除了在门的输入端有一些杂散的电线\mypermute

在此处输入图片描述

这是由以下代码生成的:

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{quantikz2, mypermute}

\begin{document}

\begin{quantikz}[row sep = .75em, column sep =.5em]
 &\mypermute{4,2,3,0,5}&\setwiretype{n} & & &\mypermute{0,4,3,1,5} &\setwiretype{q} & & \mypermute{1,0,4,2,5}& & \mypermute{1,2,0,3,5}& \\
 &&&&&&\setwiretype{n}&&\setwiretype{q}&&&\\
 &&&&&&&&\setwiretype{n}&&&\setwiretype{q}\\
 [1em]\setwiretype{n}&&\setwiretype{q}&\gate[2]{U}&&\setwiretype{q}&\gate[2]{U}&&\setwiretype{q}&\gate[2]{U}&&\setwiretype{n}& \\
 &&&&&&&&&&&\\
\end{quantikz}

\end{document}

我怎样才能除掉那些浮线?


tikzlibrarymypermute.code.tex这里提供了tikzlibrary的内容mypermute

\RequirePackage{xargs,ifthen,xstring,xparse,etoolbox,mathtools,pgfmath}
\RequirePackage{environ} %in an attempt to help with compatibility with the external library of tikz.
%\RequirePackage{tikz}
\usetikzlibrary{cd,decorations.pathreplacing,calc,positioning,fit,shapes.symbols,decorations.pathmorphing,shapes.misc,decorations.markings,math,quantikz2}
\pgfdeclarelayer{background}
\pgfdeclarelayer{quantback}


\newcommand{\mypermute}[1]{%
\hphantom{Wide}%
\def\firstlist{#1}
    \edef\n{\the\pgfmatrixcurrentrow} %the row
    \edef\m{\the\pgfmatrixcurrentcolumn} %the column
    \edef\mn{\the\numexpr\m-1\relax}
    \edef\mp{\the\numexpr\m+1\relax}
    \settowidth{\myl}{$Wide$}
    \setcounter{wirenumberpermute}{0}
    \foreach \x [count=\c] in \firstlist {%
        \edef\start{\the\numexpr\c+\n-1\relax}%
        \edef\endy{\the\numexpr\x+\n-1\relax}%
        %apply auto width to the cell, and make sure we unset the setting so that it doesn't apply to later circuits.
    \csxdef{cell@width@\start-\m}{\the\myl} %save the cell width for every row in a global variable
        \stepcounter{wirenumberpermute}
        }
        \expandafter\expandafter\expandafter\pgfutil@g@addto@macro\expandafter\expandafter\expandafter\tikzcd@atendsavedpaths\expandafter\expandafter\expandafter{%
        \expandafter\expandafter\expandafter\mywirepair@end\expandafter\expandafter\expandafter{\expandafter\n\expandafter}\expandafter{\m}{#1}%
        }
    \edef\lim{\the\numexpr\arabic{wirenumberpermute}+\n-1\relax}
        \foreach \i in {\n,...,\lim} {%
         \edef\newcom{\noexpand\vqwexplicit{\i-\m}{\i-\mn}}
             \newcom%
        }
}

\newcommand{\mywirepair@end}[3]{%#row,col of left-most site. #row of right-most site.
    \xdef\LoopGG{}
    \edef\i{#1}
    \def\firstlist{#3}
    %\show\i
    %\show\j
    %create a list of cell names to be included in this grouped gate
    \foreach \n in \firstlist {%
    \ifnodedefined{\tikzcdmatrixname-\the\numexpr\n+\i-1\relax-#2}{%
        \xdef\LoopGG{\LoopGG(\tikzcdmatrixname-\the\numexpr\n+\i-1\relax-#2)}
        }{}
    }
    \ifnodedefined{\tikzcdmatrixname-\i-#2}{%
        \xdef\LoopGG{\LoopGG(\tikzcdmatrixname-\i-#2)}
        }{}
    \node (group\tikzcdmatrixname-#1-#2) [fit=\LoopGG,transparent,inner sep=0pt] {\phantom{Wide}};
        \foreach \n [count=\c] in \firstlist{%
        \ifnum\n>0
            \draw [line width=3pt,\pgfkeysvalueof{/tikz/commutative diagrams/background color},shorten >=0.9pt,shorten <=0.9pt] (group\tikzcdmatrixname-#1-#2.west|-\tikzcdmatrixname-\the\numexpr\i+\c-1\relax-#2.center) to[out=0,in=180] (group\tikzcdmatrixname-#1-#2.east|-\tikzcdmatrixname-\the\numexpr\i+\n-1\relax-#2.center);
            \draw [thickness] (group\tikzcdmatrixname-#1-#2.west|-\tikzcdmatrixname-\the\numexpr\i+\c-1\relax-#2.center) to[out=0,in=180] (group\tikzcdmatrixname-#1-#2.east|-\tikzcdmatrixname-\the\numexpr\i+\n-1\relax-#2.center);
        \fi
        }
}

相关内容