绘制带有颜色和文字的图表

绘制带有颜色和文字的图表

我想画出附图,但由于它包含颜色和文本,我无法得到一张好的图片。如果有人能帮我编写代码那就太好了。注意,这些框的大小相同!谢谢。在此处输入图片描述

答案1

matrix of nodes或都tikz-cd允许您绘制这个。

\documentclass[tikz,border=3.14mm]{standalone}
\usetikzlibrary{matrix,quotes}
\begin{document}
\begin{tikzpicture}[M/.style={draw=blue,fill=yellow},font=\sffamily,>=stealth]
 \matrix[matrix of nodes,column sep=3em,row sep=3em,nodes={minimum size=1cm},row 3/.style={nodes=M}] (mat)
 { A & & \\
  \phantom{C} & C & \phantom{F}& F \\
  B & D & |[draw=none,fill=none,minimum size=0em]| \phantom{F}& G\\
 };
 \draw[->] (mat-1-1) edge (mat-3-1)
  (mat-2-1) edge (mat-2-2) 
  (mat-2-2) edge["E"] (mat-3-2)
  (mat-2-4) edge["F"] (mat-3-4)
  (mat-2-2) edge[dashed] (mat-2-4)
  (mat-3-2) edge[dashed] (mat-3-4)
  (mat-2-3) edge[dashed] (mat-3-3);
\end{tikzpicture}
\end{document}

在此处输入图片描述

\documentclass[tikz,border=3.14mm]{standalone}
\usepackage{tikz-cd}
\tikzset{M/.style={draw=blue,fill=yellow,minimum size=2em}}
\begin{document}
\begin{tikzcd}[column sep=3em,row sep=3em]
  A\arrow[dd] & & \\
  \phantom{C} \arrow[r] & C \arrow[d,"E"] \arrow[rr,dashed] & \phantom{F} \arrow[d,dashed]& F \arrow[d,"H"]\\
  |[M]|B  & |[M]|D \arrow[rr,dashed] & \phantom{F}& |[M]|G\\
\end{tikzcd}
\end{document}

在此处输入图片描述

相关内容