TikZ 将形状连接在一起

TikZ 将形状连接在一起

我是 TeX 编程新手。我想绘制如附图所示的对象。

在此处输入图片描述

它不必具有完全相同的形状。

到目前为止我唯一学到的东西就是绘制形状。

\draw[blue] (0,0)rectangle (3,2);
\draw[blue] (5,0)rectangle (8,2);

问题是如何将不同的形状连接在一起。连接和箭头是必需的。

答案1

也许像这样

在此处输入图片描述

\documentclass{article}


\usepackage{tikz}


\begin{document}

\begin{tikzpicture}

\draw (0,0) node 
  [fill=blue!20, shape=rectangle, minimum height=1cm, minimum width=3cm]
 (A){dataset};
\draw (5,0) node 
  [fill=yellow!20, shape=rectangle, minimum height=1cm, minimum width=3cm]
 (B){};
\draw (7,3) node 
  [fill=red!20, shape=circle,  minimum width=30]
 (C){};

\draw[line width=2pt]  (A) -- (B);
\draw [line width=2pt,->] (B) -- (C);

\end{tikzpicture}

\end{document}

答案2

如果使用相对定位而不是绝对定位,则以后修改代码会更容易。on grid放置有助于保持整洁。shapes.geometric提供diamond形状和样式以保持格式一致。arrows.meta提供增强的箭头提示和graphs库使绘制连接变得更容易。shadows.blur是为了令人震惊的金光闪闪。

\documentclass[border=10pt,multi,tikz,dvipsnames,svgnames,rgb]{standalone}
\usetikzlibrary{shapes.geometric,arrows.meta,positioning,graphs,shadows.blur}
\begin{document}

\begin{tikzpicture}
  [
    >=Latex,
    thick,
    base/.style={draw=#1!50, fill=#1!20, font=\sffamily, text opacity=1, on grid, node distance=20mm, blur shadow},
    my diamond/.style={base=green, aspect=7.5, diamond, minimum height=10mm},
    block/.style={base=blue, minimum width=20mm, minimum height=10mm},
    my circle/.style={base=red, circle, minimum size=10mm},
  ]
  \node (ds) [block] {DATASET};
  \node (c1) [my circle, above right=of ds] {};
  \node (dia) [my diamond, above right=of c1] {};
  \node (c2) [my circle, below right=of dia] {};
  \node (blk) [block, below right=of c2] {};
  \graph [use existing nodes] {
    ds -- c1 -> dia -- c2 -> blk
  };
\end{tikzpicture}

\end{document}

Ti*k*Z 功能让流程图更显闪亮

相关内容