我有下图:
到目前为止,我在 Word/Powerpoint 中创建了此文件,并将屏幕截图粘贴到 LaTeX 文件中。有没有办法在本地创建它?此外,这样做有什么好处?
表格只是占位符,实际的表格设计/内容可能会发生变化。但我更希望它是可编辑的而不是固定的。我甚至不知道从哪里开始或如何去做。我以前从来不需要在 LaTeX 中画任何东西。
答案1
使用forest
:
\documentclass{article}
\usepackage{forest}
\newcommand\mytable[5]{%
#1\\
\begin{tabular}[t]{*{3}{|c}|}
\hline
& T1 & T2 \\
\hline
T1 & #2 & #3 \\
\hline
T2 & #4 & #5 \\
\hline
\end{tabular}%
}
\begin{document}
\begin{forest}
for tree={parent anchor=south, child anchor=north,l=2cm,edge={->}},
for descendants={text width=4.2cm,align=c}
[Developers
[\mytable{Type I probability: 0.2}{A,B}{C,D}{E,F}{G,H}]
[\mytable{Type II probability: 0.5}{P,Q}{R,S}{U,V}{W,X}]
[\mytable{Type III probability: 0.3}{A,B}{C,D}{E,F}{G,H}]
]
\end{forest}
\end{document}
作为姆博克通知他的评论,也许你可以避免表格中的大部分行:
\documentclass{article}
\usepackage{forest}
\newcommand\mytable[5]{%
#1\\[1ex]
{%
\renewcommand\arraystretch{1.3}%
\begin{tabular}[t]{c|cc}
& T1 & T2 \\
\hline
T1 & #2 & #3 \\
T2 & #4 & #5 \\
\end{tabular}%
}%
}
\begin{document}
\begin{forest}
for tree={parent anchor=south, child anchor=north,l=2cm,edge={->}},
for descendants={text width=4.2cm,align=c}
[Developers
[\mytable{Type I probability: 0.2}{A,B}{C,D}{E,F}{G,H}]
[\mytable{Type II probability: 0.5}{P,Q}{R,S}{U,V}{W,X}]
[\mytable{Type III probability: 0.3}{A,B}{C,D}{E,F}{G,H}]
]
\end{forest}
\end{document}
答案2
与 cmhughes 的答案相同,但进行了细微的调整。
\documentclass[tikz,border=10pt]{standalone}
\usetikzlibrary{positioning}
\begin{document}
\begin{tikzpicture}
\node (a) at (0,0) {Developers};
\node[below left=3cm and 4cm of a,align=center,anchor=east] (b) {%
Type I: Probability = 0.2\\
\begin{tabular}{|c|c|c|}\hline
& 2 & 3 \\\hline
4 & 5 & 6 \\\hline
7 & 8 & 9 \\\hline
\end{tabular}
};
\node[below=3cm of a,align=center,anchor=center] (c) {%
Type I: Probability = 0.5\\
\begin{tabular}{|c|c|c|}\hline
& 2 & 3 \\\hline
4 & 5 & 6 \\\hline
7 & 8 & 9 \\\hline
\end{tabular}
};
\node[below right=3cm and 4cm of a,align=center,anchor=west] (d) {%
Type I: Probability = 0.3\\
\begin{tabular}{|c|c|c|}\hline
& 2 & 3 \\\hline
4 & 5 & 6 \\\hline
7 & 8 & 9 \\\hline
\end{tabular}
};
\draw[->] (a.south)--(b.north);
\draw[->] (a.south)--(c.north);
\draw[->] (a.south)--(d.north);
\end{tikzpicture}
\end{document}
3cm and 4cm
根据表的内容和大小调整定位(通过更改)。
答案3
你有很多选择——tikz
该包功能非常强大,可以以多种不同的方式使用。
在下面的代码中我使用了该positioning
库。
% arara: pdflatex
% !arara: indent: {overwrite: yes}
\documentclass[border=1mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning}
\begin{document}
\begin{tikzpicture}
\node (developers){Developers};
\node (probI)[below left=of developers,align=center]{Type I: Probability\\
\begin{tabular}{ccc}
1 & 2 & 3 \\
1 & 2 & 3 \\
\end{tabular}
};
\node (probII)[below =of developers,align=center]{Type II: Probability\\
\begin{tabular}{ccc}
1 & 2 & 3 \\
1 & 2 & 3 \\
\end{tabular}
};
\node (probIII)[below right=of developers,align=center]{Type III: Probability\\
\begin{tabular}{ccc}
1 & 2 & 3 \\
1 & 2 & 3 \\
\end{tabular}
};
% draw the connections
\draw[->] (developers)--(probI);
\draw[->] (developers)--(probII);
\draw[->] (developers)--(probIII);
\end{tikzpicture}
\end{document}
您可以使用以下方法调整箭头的位置:
\draw[->] (developers)--(probI.north);
\draw[->] (developers)--(probII);
\draw[->] (developers)--(probIII.north);
这使
要不然
\draw[->] (developers.south)--(probI.north);
\draw[->] (developers.south)--(probII);
\draw[->] (developers.south)--(probIII.north);
这使