微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何用 Tikz 在别人身上画块?

如何解决如何用 Tikz 在别人身上画块?

这是我尝试使用 tikz 制作的图表。块 A、B 和 C 位于一个块内(此处为红色背景块),而块 E 和 F 位于另一个块内。两个巨大的块(红色背景)顶部有标签(LabA 和 LabB)。此外,我希望块 E 是正确的,并且在块 A 和 B 的中间。并且指向块 E 的箭头应该有一些弯曲角度;所以,不像我试过的那样。

Expected

这是我的代码

\documentclass[varwidth,border=7]{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning,fit,calc}
\tikzstyle{block} = [draw=black,thick,text width=2cm,minimum height=1cm,align=center]  
\tikzstyle{arrow} = [thick,->,>=stealth]

\begin{document}

    \begin{tikzpicture}
    
        \node[block] (a) {a};
        \node[block,below=of a,yshift=0.7cm] (b) {b};
        \node[block,below=of b,yshift=0.7cm] (c) {c};
        \node[block,right=of c,xshift=0.7cm] (d) {d};
        
        \node[block,right=of a,xshift=0.7cm,yshift=-0.4cm] (e) {e};
        
        \draw [arrow] (a) -- (e);
        \draw [arrow] (b) -- (e);
        \draw [arrow] (c) -- (d);
        
    \end{tikzpicture}

\end{document}

如何在一些节点上添加一个矩形并在其上写一个标签
如何使此处的箭头具有一定的倾斜角度(不是直的),以及如何在 A 和 B 块的中间和右侧放置 E 块。我虽然可以用 \draw [arrow] (a) -|- (e); 获得箭头,但它不起作用。
提前致谢

Current state

解决方法

我试了一下,希望能满足要求:

\documentclass[varwidth,border=7]{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning,fit,calc}
\tikzstyle{block} = [draw=none,thick,text width=.4cm,minimum height=.5cm,align=center,fill=blue!50]  
\tikzstyle{arrow} = [thick,->,>=stealth]

\begin{document}


    \begin{tikzpicture}
    \Large
        %red rectangles    
        \node (r1) [draw=none,fill=red,minimum width=1.2cm,minimum height=3.5cm]{};
        \node (r2) [right=2cm of r1.center,anchor=center,draw=none,minimum height=3.5cm]{};
        \node (r1Label)[above=0cm of r1] {\textbf{LabA}};
        \node (r2Label)[above=0cm of r2]{\textbf{LabB}};
    
        %nodes
        \node[block,below=3mm of r1.north,anchor=north] (a) {\color{white}A};
        \node[block,below=4mm of a] (b) {\color{white}B};
         \node[block,below=4mm of b] (c) {\color{white}C};
        \node[block,right=2cm of c.center,anchor=center] (d) {\color{white}D};
        \node at ($(a.south)+(2,-.2)$) [block] (e) {\color{white}E};
        
        %arrows
        \draw [arrow,rounded corners=2] (a) -- ($(a)+(1,0)$) |- ($(e.west)+(0,.1)$);
        \draw [arrow,rounded corners=2] (b) -- ($(b)+(1,-.1)$);
        \draw [arrow] (c) -- (d);
        
    \end{tikzpicture}

\end{document}

结果如下:

latex output

一些解释:

  • 您可以通过在其他节点之前定义矩形来在后面绘制矩形。还有更复杂的使用层的方法,但我认为在这个例子中就足够了。
  • 我主要使用绝对距离,就像在给定的示例代码中一样。您可能需要调整...但是,使用这些您可以轻松找出 A 和 B 之间的中间(距离 4 毫米)以找到 E 的 y 位置(a.south+ 2mm)。使用 ($(node1)+(node2)$) 可以计算节点位置。
  • 您提到的 -|- 选项分两步工作。首先将 -- 绘制到某个锚点(否则这是不明确的),然后将 |- 绘制到目标节点。
  • 绘制的圆角选项将圆角半径作为参数。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。