使 tikz 中的节点高度相同

使 tikz 中的节点高度相同

我希望这些框的高度相同,而不是宽度相同。实现此目的的最佳方法是什么?

\tikzset{
%Define standard arrow tip
>=stealth',
%Define style for boxes
punkt/.style={
      rectangle,
      rounded corners,
      draw=black, very thick,
      text width=6.5em,
      minimum height=4cm,
      text centered}
}

\begin{tikzpicture}[node distance=1cm, auto]

\node[name=dummy] (dummy) {};
\node[punkt, name=oracle, left = 4cm of dummy] (oracle) {Oracle circuit $O_H$ providing access to $H_{xy}$};
\node[punkt, name=block, left = 0cm of dummy] (block) {$U_H$, block encoding of $H_{xy}$, which implements ${\ket{\psi}\mapsto H\ket{\psi}}$};
\node[punkt, name=algo, left = -4cm of dummy] (algo) {A circuit built upon the usage of $U_H$, which implements ${\ket{\psi}\mapsto f(H)\ket{\psi}}$ for some matrix function $f$};

\draw [-stealth] (oracle) edge[bend left=0, every node/.style={left=2cm}] []  (block);
\draw [-stealth] (block) edge[bend left=0, every node/.style={left=2cm}] []  (algo);

\end{tikzpicture}

在此处输入图片描述

增加会minimum height导致以下结果:

在此处输入图片描述

这不是我需要的,因为我不想改变第一个框的高度,而只是想让第二个和第三个框更宽。

答案1

\documentclass[tikz, border=1cm]{standalone}
\usepackage{braket}
\usetikzlibrary{arrows.meta, positioning}
\tikzset{
>=Stealth,
punkt/.style={rectangle, rounded corners, draw, very thick, inner sep=8pt, align=center},
}
\begin{document}
\begin{tikzpicture}[node distance=1cm]
\node[punkt] (oracle) {Oracle circuit\\$O_H$ providing\\access to $H_{xy}$};
\node[punkt, right=of oracle] (block) {$U_H$, block encoding $H_{xy}$,\\which implements of\\${\ket{\psi}\mapsto H\ket{\psi}}$};
\node[punkt, right=of block] (algo) {A circuit built upon the usage of $U_H$,\\which implements ${\ket{\psi}\mapsto f(H)\ket{\psi}}$ for\\some matrix function $f$};
\draw[->] (oracle) -- (block);
\draw[->] (block) -- (algo);
\end{tikzpicture}
\end{document}

三个带有文字和箭头的框

答案2

这是一个有点粗鲁的解决方案,需要对节点宽度进行一些手动调整:

在此处输入图片描述

在上图中,我首先定义第一个节点文本行的宽度,以便完整的文本分布在三行中,第二个节点的宽度大约为第一个节点宽度的 5/3 邮件宽度(因为这是较长的文本),等等。

\documentclass[margin=3mm]{standalone}
\usepackage{braket}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,
                chains,
                positioning}

\begin{document}
  
    \begin{tikzpicture}[
node distance = 7mm,
  start chain = going right,
   arr/.style = {-Stealth},
   box/.style = {draw, thick, rounded corners, align=left,
                 text width=#1, on chain, join=by arr}
                    ]
\node   [box=7em] {Oracle circuit\\
               $O_H$ providing\\ access to $H_{xy}$};
\node   [box=1.6*7em] {$U_H$, block encoding $H_{xy}$, \\
               which implements of \\
               ${\ket{\psi}\mapsto H\ket{\psi}}$};
\node   [box=2.4*7em] {A circuit built upon the usage of $U_H$, \\
               which implements ${\ket{\psi}\mapsto f(H)\ket{\psi}}$ for \\
               some matrix function $f$};
    \end{tikzpicture}
    
\end{document}

您可以计算节点宽度的因素,首先测量每个节点中文本的长度,然后计算它们之间的比率。在上面的 MWE 中,我首先估计文本长度,然后(手动)计算它们之间的比率。

相关内容