这是我的问题:我怎样才能制作出这个图形?
我发现在同一个门中创建两条线相当困难。例如,所有这些门(或 mbox?)都在两条线上,但我不知道如何插入一条新线!
有什么帮助吗?谢谢
答案1
matrix of nodes
这是使用from的一种可能性tikz
。Dirac Kets 定义为
\newcommand{\ket}[1]{\ensuremath{\left|#1\right\rangle}}
并定义了两个运算符(绘制矩形)
\tikzset{
operator/.style = {draw,fill=white,minimum size=1cm,text width=2cm, align=center},
operator2/.style = {draw,fill=white,minimum height=7em,text width=1cm, align=center},
},
代码
\documentclass[border=1cm]{standalone}
\usepackage{tikz}
\usetikzlibrary{backgrounds,calc,positioning}
% Dirac Kets
\newcommand{\ket}[1]{\ensuremath{\left|#1\right\rangle}}
\begin{document}
\begin{tikzpicture}[thick]
% `operator' will only be used by Hadamard (H) gates here.
% `operator2' is for large H gates
\tikzset{
operator/.style = {draw,fill=white,minimum size=1cm,text width=2cm, align=center},
operator2/.style = {draw,fill=white,minimum height=7em,text width=1cm, align=center},
},
\matrix[row sep=0.4cm, column sep=0.8cm] (circuit) { % 8 columns % First row.
\node (q1) {\ket{0}$^{\otimes7}$};
&\node[operator] (H11) {FT prepare\\ \ket{0_L}};
&\node[operator] (H12) {FT error correct};
&\node[operator] (H13) {FT H};
&\node[operator] (H14) {FT error correct};
&\node[](H15){};
&\node[operator] (H16) {FT error correct};
&\node[operator] (H17) {FT measure};\\
% Second row.
\node (q2) {\ket{0}$^{\otimes7}$};
&\node[operator] (H21) {FT prepare\\\ket{0_L}};
&\node[operator] (H22) {FT error correct};
&
&\node[operator] (H24) {FT error correct};
&\node[](H25){};
&\node[operator] (H26) {FT error correct};
&\node[operator] (H27) {FT measure};\\
};
\begin{pgfonlayer}{background}
\draw[thick] (q1) -- (H17.west) (q2) -- (H27.west);
\node[] at ($(q1)!0.35!(H11)$) {/};
\node[] at ($(q2)!0.35!(H21)$) {/};
\node[operator2] at ($(H15)!0.5!(H25)$){FT \\CNOT}; %<-- for large rectangle
%}
\end{pgfonlayer}
%
\end{tikzpicture}
\end{document}
答案2
门命令(例如)\gate
接受各种 LaTeX 作为有效的门标签,因此您只需弄清楚如何在 LaTeX 中为门排版您想要的任何标签。对于您来说,最简单的方法可能是使用该\parbox
命令生成一个包含多行文本的框。
我在下面提供了一个简单示例的代码和输出。
\documentclass{standalone}
\input{Qcircuit}
\begin{document}
\begin{tabular}{c}
\vspace{-.6em}\\
\Qcircuit @R=.2em @C=.5em @!R {
& \gate{\parbox{1.5cm}{\centering FT error\\ correct}} & \qw
}
\vspace{1.2em}\\
\end{tabular}
\end{document}