使用 TikZ/Graphviz/dot2texi 绘制 ER 图

使用 TikZ/Graphviz/dot2texi 绘制 ER 图

我想使用这些包的组合绘制 ER 图。我尝试遵循并重新创建本指南,图6。

图表必须在 Overleaf 文档中绘制,这给我带来了一些问题。到目前为止,我已经设法使能够--shell-escape,这样dot2texi可以编译,但我仍然得到:

dot2texi警告:转换output-dot2tex-fig1.dot 失败。

我不知道如何继续,实际上让它在 Overleaf 中工作并输出为 TikZ 图形。

到目前为止包设置如下:

\usepackage{tikz}
\usetikzlibrary{automata, shapes}
\usepackage{dot2texi}
\usepackage[pdf]{graphviz}

TikZ 集设置如下:

\definecolor{coolblack}{rgb}{0.0, 0.18, 0.39}
\tikzset{entity/.style={draw=coolblack, fill=coolblack!20}}
\tikzset{attribute/.style={draw =coolblack, fill=coolblack!20}}
\tikzset{multi attribute/.style={draw =coolblack, fill=coolblack!20}}
\tikzset{derived attribute/.style={draw =coolblack, fill=coolblack!20}}
\tikzset{simple relation/.style={-}}
\tikzset{total relation/.style={-, double, double distance=1.5pt}}
\tikzset{relationship/.style ={diamond, draw=coolblack, fill=coolblack!20}}

我想要绘制的图表是:

\begin{tikzpicture}
\begin{dot2tex}[styleonly, mathmode, codeonly, neato, options = - s]
digraph G{
edge [style ="simple relation"];
// nodes
Person [style ="entity"];
pid [ style ="attribute" , label ="\underline{ID}"];
Attribute [ style ="attribute"];
Name [ style ="attribute"];
Phone [ style ="multi attribute"];
Address [ style ="attribute"];
Street [ style ="attribute"];
City [ style ="attribute"];
Age [ style ="derived attribute"];
Uses [ style ="relationship"];
Tool [ style ="entity"];
tid [ style ="attribute" , label ="\underline{ID}"];
tname [ style ="attribute" , label ="Name"];
// edges
Person -> pid;
Person -> Attribute;
Person -> Name;
Person -> Phone;
Person -> Address -> Street;
Person -> City;
Person -> Age;
Person -> Uses;
Tool -> tid;
Tool -> tname;
Tool -> Uses [ style ="total relation"];
}
\end{dot2tex}
\end{tikzpicture}

从编译器日志中我可以看到已--shell-escape正确启用:**main.tex --shell-escape

这是来自编译日志的错误:

Opening dot2tex stream output-dot2tex-fig1.dot
runsystem(dot2tex --codeonly -ftikz   --styleonly   --prog=neato -tmath  -o output-dot2tex-fig1.tex - s output-dot2tex-fig1.dot)...executed.


Package dot2texi Warning: Conversion of output-dot2tex-fig1.dot failed..


Package dot2texi Warning: Please convert output-dot2tex-fig1.dot manually.

编译器设置为LuaLaTeX,完整代码如下:

\documentclass{article}
\usepackage{xcolor}
\usepackage{tikz}
\usetikzlibrary{automata, shapes}
\usepackage{dot2texi}
\usepackage[pdf]{graphviz}
\definecolor{coolblack}{rgb}{0.0, 0.18, 0.39}
\tikzset{entity/.style={draw=coolblack, fill=coolblack!20}}
\tikzset{attribute/.style={draw =coolblack, fill=coolblack!20}}
\tikzset{multi attribute/.style={draw =coolblack, fill=coolblack!20}}
\tikzset{derived attribute/.style={draw =coolblack, fill=coolblack!20}}
\tikzset{simple relation/.style={-}}
\tikzset{total relation/.style={-, double, double distance=1.5pt}}
\tikzset{relationship/.style ={diamond, draw=coolblack, fill=coolblack!20}}

\begin{document}


\begin{tikzpicture}
\begin{dot2tex}[styleonly, mathmode, codeonly, neato, options = - s]
digraph G{
edge [style ="simple relation"];
// nodes
Person [style ="entity"];
pid [ style ="attribute" , label ="\underline{ID}"];
Attribute [ style ="attribute"];
Name [ style ="attribute"];
Phone [ style ="multi attribute"];
Address [ style ="attribute"];
Street [ style ="attribute"];
City [ style ="attribute"];
Age [ style ="derived attribute"];
Uses [ style ="relationship"];
Tool [ style ="entity"];
tid [ style ="attribute" , label ="\underline{ID}"];
tname [ style ="attribute" , label ="Name"];
// edges
Person -> pid;
Person -> Attribute;
Person -> Name;
Person -> Phone;
Person -> Address -> Street;
Person -> City;
Person -> Age;
Person -> Uses;
Tool -> tid;
Tool -> tname;
Tool -> Uses [ style ="total relation"];
}
\end{dot2tex}
\end{tikzpicture}


\end{document}

我想要的是 TikZ 环境中的图表,以便它可以包含在 Overleaf 生成的 PDF 中。

我需要做什么才能编译并将此图表包含到 Overleaf PDF 中?

答案1

事实证明,这与 Overleaf 无关。修复缩进就可以解决问题:

\begin{tikzpicture}
\begin{dot2tex}[styleonly, mathmode, codeonly, neato, options=-s]
digraph G {
    edge[style ="simple relation"];
    // nodes
    Person [style ="entity"];
    pid [style ="attribute", label ="\underline{ID}"];
    Attribute [style ="attribute"];
    Name [style ="attribute"];
    Phone [style ="multi attribute"];
    Address [style ="attribute"];
    Street [style ="attribute"];
    City [style ="attribute"];
    Age [style ="derived attribute"];
    Uses [style ="relationship"];
    Tool [style ="entity"];
    tid [style ="attribute" , label ="\underline{ID}"];
    tname [style ="attribute" , label ="Name"];
    // edges
    Person -> pid;
    Person -> Attribute;
    Person -> Name;
    Person -> Phone;
    Person -> Address -> Street;
    Person -> City;
    Person -> Age;
    Person -> Uses;
    Tool -> tid;
    Tool -> tname;
    Tool -> Uses [ tyle ="total relation"];
    }
\end{dot2tex}
\end{tikzpicture}

相关内容