如何在 Tikz 中绘制 xsd

如何在 Tikz 中绘制 xsd

如何在 TikZ 中使用 xsd 绘图?

在此处输入图片描述

答案1

第二次尝试。您需要添加一些样式来简化代码。一个好方法是创建新的形状,但这是一项漫长的工作。在这里,我用 savedbox 保存了一些图片,然后您可以在新节点内重复使用它们,但您需要采取一些预防措施,例如inner xsep=0。一个问题是在矩形分割部分内获得相同的高度。这里我用了,\mystrut但也许有更好的方法来做到这一点。

\documentclass[11pt,landscape]{scrartcl}
\usepackage{tikz}
\usetikzlibrary{shapes.multipart} 

\def\vstrut{\vrule height 0.75ex depth 0.75ex width 0pt}
 \def\hstrut{\vrule height 0ex depth 0ex width 3mm}  
\begin{document}
\newsavebox{\figone}
\savebox{\figone}{%    
\begin{tikzpicture}
\fill (-2mm,-1mm) rectangle  (2mm,1mm); 
\fill[yshift=3mm] (-2mm,-1mm) rectangle  (2mm,1mm); 
\fill[yshift=-3mm ] (-2mm,-1mm) rectangle  (2mm,1mm);
\draw[thick] (-6mm,0) -- (-2mm,0)  (6mm,0) -- (2mm,0) ; 
\draw[thick]  (-2mm,-3mm) -- ++(-2mm,0) -- ++(0mm,6mm)--++(2mm,0);
\draw[thick]  (2mm,-3mm) -- ++(2mm,0) -- ++(0mm,6mm)--++(-2mm,0); 
\end{tikzpicture}%
}%

\newsavebox{\figtwo}
\savebox{\figtwo}{%    
\begin{tikzpicture}
\draw (0mm,-3mm)--++(0,6mm)--++(3mm,3mm)--++(15mm,0)--++(3mm,-3mm)--++(0,-6mm)--++(-3mm,-3mm)--++(-15mm,0)--cycle;
\end{tikzpicture}%
}   

\newsavebox{\tiret}
\savebox{\tiret}{%
\begin{tikzpicture}
\draw[thick] (-2mm,0mm)--++(4mm,0);
\end{tikzpicture}%
}% 

\newsavebox{\connect} 
\savebox{\connect}{%
\begin{tikzpicture}
  \node{\usebox\figone};
  \node[inner sep=0pt] (ft){\usebox\figtwo};
  \node[draw,minimum size=6mm,anchor=center,inner sep=0pt,fill=white,inner xsep=0](m) at (ft.east){};
  \node[inner sep=0pt] at (m) {\usebox\tiret};
\end{tikzpicture}%
}
\tikzset{split style/.style={rectangle split, rectangle split parts=2, draw,rectangle split part align={left}}}

 \tikzset{square/.style={draw,minimum size=6mm,anchor=center,inner xsep=0pt,fill=white}}  

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\begin{tikzpicture}[font=\small,scale=.75,transform shape]
 \node[split style] (r1)
    {\vstrut\textbf{Root}\hstrut
    \nodepart{two} \vstrut type = Well\hstrut};
 \node[square] (b1) at (r1.east) {\usebox\tiret};
 \node[inner sep=0,anchor=west] (c1) at ([xshift=.5cm]b1.east){\usebox\connect};

 \node[split style,anchor=west] (r2) at ([xshift=0.5cm]c1.east)
    {\vstrut\textbf{BasicInfo}  1.1\hstrut
     \nodepart{two}
     \vstrut   type = Complex Type\hstrut};
  \node[square] (b2) at (r2.east) {\usebox\tiret};  
  \node[inner sep=0,anchor=west] (c2) at ([xshift=0.5cm]b2.east){\usebox\connect};    
  \draw (b1)-- (c1) (c1)-- (r2) (b2) --(c2);   
\end{tikzpicture}

\end{document}        

在此处输入图片描述

相关内容