将 tikz 树级别拆分为两部分

将 tikz 树级别拆分为两部分

我想为我的学士论文重建这张图形。XML Schema 中的预定义数据类型

我遇到的问题是,我不知道如何在第二层分割图表,如上图所示。我能够重建图形,除了“分割树级别”和图形下方的图例。

解决方案:

%
% rebuild of graphic from
% http://www.w3.org/TR/xmlschema-2/#built-in-datatypes
%
\documentclass[12pt]{article}

\usepackage[utf8x]{inputenc}
\usepackage{tikz}
\usetikzlibrary{trees}

\begin{document}

\begin{figure}[htb]
    \centering
    \resizebox{\textwidth}{!}{
        \begin{tikzpicture}[level distance=1.1cm,
          level 1/.style={sibling distance=4cm},
          level 2/.style={sibling distance=2cm},
          level 3/.style={sibling distance=2.5cm},
          box/.style={rectangle, fill={blue!15}, draw, font=\sffamily},
          grayBox/.style={rectangle, fill=lightgray, text=black, font=\sffamily, draw},
          violetBox/.style={rectangle, fill=violet, text=white, font=\sffamily, draw},
          greenBox/.style={rectangle, fill=green!50, text=black, font=\sffamily, draw}]
          \node[violetBox] {anyType}
            [edge from parent fork down]
            child {node[grayBox] {all complex types}
                edge from parent[dotted]
            }
            child {node[violetBox] {anySimpleType}
                    child {node[box] {duration}}
                    child {node[box] {dateTime}}
                    child {node[box] {time}}
                    child {node[box] {date}}
                    child {node[box] {gYearMonth}}
                    child {node[box] {gYear}}
                    child {node[box] {gMonthDay}}
                    child {node[box] {gDay}}
                    child {node[box] {gMonth}}
                    child {
                        child [sibling distance = 3cm]{
                            child {node[box] {string}
                                child {node[greenBox] {normalizedString}}
                                child {node[greenBox] {token}
                                    child {node[greenBox] {language}}
                                    child {node[greenBox] {Name}
                                        child {node[greenBox] {NCName}
                                            child {node[greenBox] {ID}}
                                            child {node[greenBox] {IDREF}
                                                child {node[greenBox] {IDREFS}
                                                    edge from parent[dashed]
                                                }
                                            }
                                            child {node[greenBox] {ENTITY}
                                                child {node[greenBox] {ENTITIES}
                                                    edge from parent[dashed]
                                                }
                                            }
                                        }
                                    }
                                    child {node[greenBox] {NMTOKEN}
                                        child  {node [greenBox] {NMTOKENS}
                                            edge from parent[dashed]
                                        }
                                    }
                                }
                            }
                        }
                        child {node[box] {boolean}}
                        child {node[box] {base64Binary}}
                        child {node[box] {hexBinary}}
                        child {node[box] {float}}
                        child [sibling distance = 3cm] {
                            child {node[box] {decimal}
                                child [sibling distance = 4cm] {node[greenBox] {integer}
                                    child {node[greenBox] {nonPositiveInteger}
                                        child {node[greenBox] {negativeInteger}}
                                    }
                                    child {node[greenBox] {long}
                                        child {node[greenBox] {int}
                                            child {node[greenBox] {short}
                                                child {node[greenBox] {byte}}
                                            }
                                        }
                                    }
                                    child {node[greenBox] {nonNegativeInteger}
                                        child {node[greenBox] {unsignedLong}
                                            child {node[greenBox] {unsignedInt}
                                                child {node[greenBox] {unsignedShort}
                                                    child {node[greenBox] {unsignedByte}}
                                                }
                                            }
                                        }
                                        child {node[greenBox] {positiveInteger}}
                                    }
                                }
                            }
                        }
                        child {node[box] {double}}
                        child {node[box] {anyURI}}
                        child {node[box] {QName}}
                        child {node[box] {NOTATION}}
                    }
            };
        \end{tikzpicture}
    }
    \caption{vordefinierte XSD Datentypen nach \cite{XMLSchema11Specification} Kapitel 3}
    \label{fig:xsddatatypes}
\end{figure}

\end{document}

现在看起来是这样的:

完成版本

PS:在图形内部创建第二个图形作为图例是否合理?有没有更好的方法来制作图例?

答案1

这里有一个带图例的版本

%
% rebuild of graphic from
% http://www.w3.org/TR/xmlschema-2/#built-in-datatypes
%
\documentclass[12pt, landscape]{scrartcl}

\usepackage[utf8x]{inputenc}
\usepackage{tikz}
\usetikzlibrary{shapes} % rounded rectangle
\usetikzlibrary{trees}
\usetikzlibrary{backgrounds} %framed 
\usetikzlibrary{positioning}

\begin{document}

    \begin{figure}[htb]
        \centering
        \tikzstyle{blueBox}=[
            rounded rectangle,
            fill={blue!15},
            draw,
            font=\sffamily
        ]      
        \tikzstyle{grayBox}=[
            rounded rectangle,
            fill=lightgray,
            text=black,
            font=\sffamily,
            draw
        ]
        \tikzstyle{violetBox}=[
            rounded rectangle,
            fill=violet,
            text=white,
            font=\sffamily,
            draw
        ]
        \tikzstyle{greenBox}=[
            rounded rectangle,
            fill=green!50,
            text=black,
            font=\sffamily,
            draw
        ]
        \tikzstyle{derivedFromList}=[
            dashed,
            cyan
        ]
        \resizebox{\textwidth}{!}{
            \begin{tikzpicture}[
                level distance=1.1cm,
                level 1/.style={sibling distance=4cm},
                level 2/.style={sibling distance=2cm},
                level 3/.style={sibling distance=2.5cm},
              ]
              \node (root) [violetBox] {anyType}
                [edge from parent fork down]
                child {node[grayBox] {all complex types}
                    edge from parent[loosely dashed, magenta]
                }
                child {node[violetBox] {anySimpleType}
                        child {node[blueBox] {duration}}
                        child {node[blueBox] {dateTime}}
                        child {node[blueBox] {time}}
                        child {node[blueBox] {date}}
                        child {node[blueBox] {gYearMonth}}
                        child {node[blueBox] {gYear}}
                        child {node[blueBox] {gMonthDay}}
                        child {node[blueBox] {gDay}}
                        child {node[blueBox] {gMonth}}
                        child {
                            child [sibling distance = 3cm]{
                                child {node[blueBox] {string}
                                    child {node[greenBox] {normalizedString}}
                                    child {node[greenBox] {token}
                                        child {node[greenBox] {language}}
                                        child {node[greenBox] {Name}
                                            child {node[greenBox] {NCName}
                                                child {node[greenBox] {ID}}
                                                child {node[greenBox] {IDREF}
                                                    child {node[greenBox] {IDREFS}
                                                        edge from parent[derivedFromList]
                                                    }
                                                }
                                                child {node[greenBox] {ENTITY}
                                                    child {node[greenBox] {ENTITIES}
                                                        edge from parent[derivedFromList]
                                                    }
                                                }
                                            }
                                        }
                                        child {node[greenBox] {NMTOKEN}
                                            child  {node [greenBox] {NMTOKENS}
                                                edge from parent[derivedFromList]
                                            }
                                        }
                                    }
                                }
                            }
                            child {node[blueBox] {boolean}}
                            child {node[blueBox] {base64Binary}}
                            child {node[blueBox] {hexBinary}}
                            child {node[blueBox] {float}}
                            child [sibling distance = 3cm] {
                                child {node[blueBox] {decimal}
                                    child [sibling distance = 4cm] {node[greenBox] {integer}
                                        child {node[greenBox] {nonPositiveInteger}
                                            child {node[greenBox] {negativeInteger}}
                                        }
                                        child {node[greenBox] {long}
                                            child {node[greenBox] {int}
                                                child {node[greenBox] {short}
                                                    child {node[greenBox] {byte}}
                                                }
                                            }
                                        }
                                        child {node[greenBox] {nonNegativeInteger}
                                            child {node[greenBox] {unsignedLong}
                                                child {node[greenBox] {unsignedInt}
                                                    child {node[greenBox] {unsignedShort}
                                                        child {node[greenBox] {unsignedByte}}
                                                    }
                                                }
                                            }
                                            child {node[greenBox] {positiveInteger}}
                                        }
                                    }
                                }
                            }
                            child {node[blueBox] {double}}
                            child {node[blueBox] {anyURI}}
                            child {node[blueBox] {QName}}
                            child {node[blueBox] {NOTATION}}
                        }
                };
            \end{tikzpicture}
        }

        \vspace{\baselineskip}

        \resizebox{0.5\textwidth}{!}{
            \begin{tikzpicture}[framed]
                \node (title) [font=\bfseries] {Legende:};
                \node (base) [violetBox, right = of title] {Basis Typ};
                \node (primitive) [blueBox, right = of base] {Primitiver Typ};
                \node (derived) [greenBox, right = of primitive] {Abgeleiteter Typ};
                \node (complex) [grayBox, right = of derived] {Komplexer Typ};
                \node (d1) [below = of base] {};
                \node (d2) [below = of primitive] {}
                    edge [] node[swap, align=center]{Abgeleitet durch\\Einschränkung} (d1);
                \node (d3) [below = of derived] {};
                \node (d4) [below = of complex] {}
                    edge [dashed, cyan] node[swap, align=center]{von Liste\\abgeleitet} (d3);
                \node (d5) [below = of d2] {};
                \node (d6) [below = of d3] {}
                    edge [loosely dashed, magenta] node[swap, align=center]{Abgeleitet durch\\Erweiterung/Einschränkung} (d5);
            \end{tikzpicture}
        }
        \caption{vordefinierte XSD Datentypen nach \cite{XMLSchema11Specification} Kapitel 3}
        \label{fig:xsddatatypes}
    \end{figure}

\end{document}

带图例的图形

相关内容