我正在尝试创建类似于下面的图表
但该图也存在一些问题。
- 能否通过 90 度转弯来简化该图?
- 是否有简单的方法可以消除绘制线条之间的间距?
- 为什么右边有一条很大的黑色横线?
- 还有其他方法可以生成类似的图像吗?(我觉得我的方法太过暴力)
提前致谢 =)
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{matrix}
\begin{document}
\begin{tikzpicture}
\matrix (m) [matrix of math nodes,
row sep=3em,
column sep=2em,
minimum width=2em,
nodes in empty cells,
nodes={anchor=center}]
{
& & & & & & \neg t & & & \\
& & & q & & & r & & & \\
T & & & r & & & t & & & T \\
& & & t & & & p & & & \\
& & & \neg r & & & & & & \\};
\draw (m-3-1) -- (m-3-2) ;
\draw (m-2-6) -- (m-2-4) -- (m-2-2) -- (m-4-2) -- (m-4-3);
\draw (m-4-3) -- (m-3-3) -- (m-3-4) -- (m-3-5) -- (m-4-5);
\draw (m-4-3) -- (m-4-4) -- (m-4-5);
\draw (m-4-3) -- (m-5-3) -- (m-5-4) -- (m-5-5) -- (m-4-5);
\draw (m-2-6) -- (m-1-6) -- (m-1-7) -- (m-1-8) -- (m-2-8);
\draw (m-2-6) -- (m-2-7) -- (m-2-8);
\draw (m-2-6) -- (m-3-6) -- (m-3-7) -- (m-3-8) -- (m-2-8);
\draw (m-4-5) -- (m-4-7) -- (m-4-9) -- (m-2-9) -- (m-2-8);
\draw (m-3-9) -- (m-3-10);
\end{tikzpicture}
\end{document}
答案1
您还可以使用 less&
并借助++(...)
和来绘制线条xshift
。
Overfull \hbox
如果您在草稿模式下运行实际文档,则黑色垂直规则可能是由于造成的。
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{matrix}
\begin{document}
\begin{tikzpicture}
\matrix (m) [matrix of math nodes,
row sep=3em,
column sep=8em,
minimum width=2em,
nodes in empty cells,
nodes={anchor=center}]
{
& & \neg t & \\
& q & r & \\
T & r & t & T \\
& t & p & \\
& \neg r & & \\
};
\draw (m-3-1.east) -- ++(2em,0) |- (m-2-2) -- (m-2-3);
\draw (m-3-4.west) -- ++(-2em,0) |- (m-2-3);
\draw ([xshift=2em]m-3-1.east) |- (m-4-2) -- (m-4-3);
\draw ([xshift=-2em]m-3-4.west) |- (m-4-3);
\draw (m-3-2.east) -- ++(2.5em,0) |- (m-5-2);
\draw (m-5-2.west) -- ++(-2.5em,0) |- (m-3-2);
\draw (m-1-3.east) -- ++(2.5em,0) |- (m-3-3);
\draw (m-3-3.west) -- ++(-2.5em,0) |- (m-1-3);
\end{tikzpicture}
\end{document}
答案2
我只能提供一点小小的改进。
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{matrix}
\begin{document}
\begin{tikzpicture}
\matrix (m) [matrix of math nodes,
row sep=3em,
column sep=2em,
minimum width=2em,
nodes in empty cells,
nodes={anchor=center}]
{
& & & & & & \neg t & & & \\
& & & q & & & r & & & \\
T & & & r & & & t & & & T \\
& & & t & & & p & & & \\
& & & \neg r & & & & & & \\};
\draw (m-3-1) -- (m-3-2.center) ;
\draw (m-2-6.center) -- (m-2-4) -- (m-2-2.center) -- (m-4-2.center) -| (m-4-3.center);
\draw (m-4-2.center) -- (m-4-3.center) -- (m-3-3.center) -- (m-3-4) -- (m-3-5.center) -- (m-4-5.center);
\draw (m-4-3.center) -- (m-4-4) -- (m-4-5.center);
\draw (m-4-3.center) -- (m-5-3.center) -- (m-5-4) -- (m-5-5.center) -- (m-4-5.center);
\draw (m-2-6.center) -- (m-1-6.center) -- (m-1-7) -- (m-1-8.center) -- (m-2-8.center);
\draw (m-2-6.center) -- (m-2-7) -- (m-2-8.center);
\draw (m-2-6.center) -- (m-3-6.center) -- (m-3-7) -- (m-3-8.center) -- (m-2-8.center);
\draw (m-4-5.center) -- (m-4-7) -- (m-4-9.center) -- (m-2-9.center) -- (m-2-8.center);
\draw (m-3-9.center) -- (m-3-10);
\end{tikzpicture}
\end{document}
我用中心替换了除第 4、7 和 10 列之外的节点。黑条从未出现。
答案3
一个pstricks
办法:
\documentclass{article}
\PassOptionsToPackage{svgnames}{xcolor}
\usepackage[utf8]{inputenc}
\usepackage{lmodern}
\usepackage{mathtools, amssymb}
\usepackage{pst-node, pst-tree, multido}
\usepackage{auto-pst-pdf} %% To compile with pdflatex --enable-write18 (MiKTeX) or pdflatex --shell-escape (TeX Live, MacTeX)
\begin{document}
\[
\def\pscolhookii{\hskip 0.6cm}
\begin{psmatrix}[emnode = p, colsep = 0.6cm, rowsep = 0.5cm]
& & & & &[name = nt] ¬ t & \\
& & [name = q] q & & & [name = ra] r & \\
[name = Tb] T & & [name = rb] r & & & [name = ta] t & & [name = Te] T \\
& & [name = tb] t & & & [name = p] p \\
& & [name = nr] ¬ r
\psset{linecolor = LightSteelBlue, linejoin = 1, armB = 0.5cm, angleB = 180, nodesep = 3pt}
%% Upper \branch
{\psset{nodesepB =0pt, armB = 0.7}\ncangle{Tb}{2,2} \ncangle{Tb}{4,2}}
{\psset{nodesepA =0pt}\ncline{2,2}{q}
\ncangle[angleA = 90]{2,5}{nt}\ncangle[angleA = -90]{2,5}{ta}}
\ncline{q}{ra}
{\psset{nodesepB = 0pt}
\ncangle[angleB = 90]{nt}{2,7}\ncangle[angleB = -90]{ta}{2,7}}
\ncangle[angleB = 90]{ra}{Te}
%% Lower branch
{\psset{nodesepA = 0pt}
\ncline{4,2}{tb}\ncangle[angleA = 90]{4,2}{rb}\ncangle[angleA = -90]{4,2}{nr}}
\ncline{tb}{p}
{\psset{nodesepB = 0pt}
\ncangle[angleB = 90]{rb}{4,4}\ncangle[angleB = -90]{nr}{4,4}}
\ncangle[angleB = -90]{p}{Te}
\end{psmatrix}
\]%
\end{document}