tikz - 节点之间的对角线

tikz - 节点之间的对角线

我想用 LaTeX 写这张图片:

三个节点

到目前为止我有以下代码:

\documentclass{standalone}
\usepackage[utf8]{inputenc}

\usepackage{tikz}
\usetikzlibrary{shapes,arrows,calc,positioning}

\begin{document}

\tikzstyle{block} = [rectangle, draw, fill=blue!20, text width=20em, text centered, rounded corners, minimum height=4em]

\begin{tikzpicture}
\node [block] (V1) {There was a machine in the kitchen};
\node [block, below right=of V1] (V2) {which could extract the juice of two hundred oranges in half an hour};
\node [block, below right=of V2] (V3) {if a little button was pressed two hundred times by a butler's thumb.};
\end{tikzpicture}

\end{document}

其结果为: 在此处输入图片描述

有人能帮我添加对角线/箭头吗?非常感谢!

答案1

您可以在节点的东南点和西北点之间画一条线。

我添加了一个负片shorten来触碰节点的圆角。

正如 Zarko 所说,tikzstyle已经过时了,请改用tikzset

\documentclass[border=2pt]{standalone}
%\usepackage[utf8]{inputenc} no more needed in up-to-date distributions

\usepackage{tikz}
\usetikzlibrary{shapes,arrows,calc,positioning}
\tikzset{myline/.style={shorten > = -2pt, shorten < = -2pt},
block/.style={rectangle, draw, fill=blue!20, text width=20em, text centered, rounded corners, minimum height=4em}
}
\begin{document}
\begin{tikzpicture}
\node [block] (V1) {There was a machine in the kitchen};
\node [block, below right=of V1] (V2) {which could extract the juice of two hundred oranges in half an hour};
\node [block, below right=of V2] (V3) {if a little button was pressed two hundred times by a butler's thumb.};
\draw[myline] (V1.south east) -- (V2.north west);
\draw[myline] (V2.south east) -- (V3.north west);
\end{tikzpicture}

\end{document}

在此处输入图片描述

答案2

  • 作为对@CarLaTeX 优秀回答的补充(+1)。
  • 删除了所有过时的 TiZ 语法(\tikzstyle, text centered)。
  • 图片样式定义为 的选项tikzpicture
  • 向节点添加标签,因为它们有问题,如所需结果的图像中所示。
\documentclass[border=3mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,
                positioning}
                
\begin{document}
    \begin{tikzpicture}[
node distance = 4mm and 4mm,
   arr/.style = {semithick, shorten > = -2pt, shorten < = -2pt},
   box/.style = {draw, rounded corners, fill=blue!20, font=\large,
                 text width=20em, align=center, minimum height=3em},
every label/.style = {text=cyan, align=left, anchor=south east, xshift=-1em}
                    ]
\node [box, label=north east:main clause] (V1) {There was a machine in the kitchen};
\node [box, label=north east:subordinate clause - relative\\ (what machine?),
            below right=of V1] (V2) {which could extract the juice of two hundred oranges in half an hour};
\node [box, label=north east:subordinate clause - conditional\\
            (under which conditions\\ could the machine do it?),
            below right=of V2] (V3) {if a little button was pressed two hundred times by a butler's thumb.};
\draw[arr]  (V1.south east) edge (V2.north west)
            (V2.south east) edge (V3.north west);
    \end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容