如何在 LaTeX 中绘制类似此图的图形?顶点的不等式尺寸很大,它们不是像 A、B 这样的小标签。如果不太混乱的话,我也希望在边缘上有一些表达(图中未显示)。
请注意,左侧有 10 个顶点,右侧有 20 多个顶点,但并未显示所有顶点。节点之间有多个连接。因此,如果有一种类似数组的方式来指定边(例如,从边 = {(u1, v1), (u1, v2), (u2, v2), (u2, v3), (u3, v4)...} 绘制每条边,那么比在图中手动指定每条边要好。(例如,绘制边 (u1, v1)、绘制边 (u1, v2) 等。)
另外,我想我也需要更大的页面尺寸(我不会打印它,所以任意大的尺寸都可以)。
最好的情况下,我想要类似这样的内容:顶点列表 = (v1,v2,...),边列表 = ((u1,v1),(u2,v2),...) 并且使用 tikz/LaTeX 来处理其余的安排。
答案1
TikZ
我使用和库解决了这个问题shapes
,但我认为省略号对于这么长的内容来说不太好。有两个链,都向下(below
),所有节点都有固定的高度(minimum height=
并且两个链上的“nner ysep=) such that they are aligned by using the same step
节点距离”,
\documentclass{standalone}
\usepackage{tikz} \usetikzlibrary{chains,positioning,scopes,shapes}
\begin{document}
\tikzstyle{myNode}=[on chain, align=center,shape=ellipse,draw, minimum width=3cm, minimum height=1cm,inner ysep=0pt]
\begin{tikzpicture}
\begin{scope}[start chain=going below, node distance=2cm]
\node [on chain, myNode] (L1) at (0,-3) {\(x_1\quad x_2\)\\\(v_2\geq0\)};
\node [on chain, myNode] (L2) {\(x_1\quad (1-x_2)\)\\\((k-1)v_2 - (k+1)v_3 \geq 0\)};
\node [on chain, myNode] (L3) {\(1-x_1\quad (1-x_2)\)\\\((k+1)v_1 - (2k-1)v_2 \geq 1\)};
\end{scope}
\begin{scope}[start chain=going below, node distance=2cm]
\node [on chain, myNode] (K1) at (7,0) {\(x_1\quad x_2\quad x_3\)\\\(2v_2\geq0\)};
\node [on chain, myNode] (K2) {\(x_1\quad x_2 \quad (1-x_3)\)\\\(v_2 + (k-2)v_3\geq 0 \geq 0\)};
\node [on chain, myNode] (K3) {\(x_1(1-x_2)(1-x_3)\)\\\((k-1)v_2 - (2k-2)v_3\geq 0\)};
\node [on chain, myNode] (K4) {\(x_1(1-x_b)(1-x_c)\)\\\(\cdots\)};
\end{scope}
\draw[->] (L1) -- (K1);
\draw[->] (L1) -- (K2);
%
\draw[->] (L2) -- (K2);
\draw[->] (L2) -- (K3);
%
\draw[->] (L3) -- (K4);
\end{tikzpicture}
\end{document}
请注意,第一个(左)链的开始位置恰好早一个高度(1cm
高度和2cm
节点距离)。
结果仍然需要一些样式(也许还有其他形状,ellipse
但这是一个起点。
编辑/更新
在第一种情况下,所有边都从中心点开始,因为\draw
起点/终点始终是中心。要改变这一点,可以使用节点的元坐标(,和.north
).east
,即用于绘制边.south
.west
\draw[->] (L1.east) -- (K1.west);
\draw[->] (L1.east) -- (K2.west);
%
\draw[->] (L2.east) -- (K2.west);
\draw[->] (L2.east) -- (K3.west);
%
\draw[->] (L3.east) -- (K4.west);
获得(包括移除shape=ellipse
并因此得到矩形):
答案2
以下是一种方法元帖子为了进行比较,使用一些拉长的超椭圆。
prologues := 3;
outputtemplate := "%j%c.eps";
% a little TeX alignment for each "node"
verbatimtex
\def\m#1{$\vcenter{\let\\\cr\halign{\hfil$##$\hfil\cr#1\crcr}}$}
etex
beginfig(1);
% "se" is a shape to surround each text block
path se; se = (superellipse(3 right, up, 3 left, down, 0.89)) scaled 23;
% define the source and target equations
picture source[], target[];
source1 = btex \m{x_1 x_2\\v_2\ge0} etex;
source2 = btex \m{x_1(1-x_2)\\(k-1)v_2-(k+1)v_3\ge0} etex;
source3 = btex \m{(1-x_1)(1-x_2)\\(k+1)v_1-(2k-1)v_2\ge1} etex;
target1 = btex \m{x_1 x_2 x_3\\2v_3\ge0} etex;
target2 = btex \m{x_1 x_2 (1-x_3)\\v_2+(k-2)v_3\ge0} etex;
target3 = btex \m{x_1 (1-x_2) (1-x_3)\\(k-1)v_2-(2k-2)v_3\ge0} etex;
target4 = btex \m{x_1 (1-x_b) (1-x_c)\\\dots} etex;
% u = horizontal separation, v = vertical
u = 120; v = 64;
% redefine each node with background, edge, and position; and then draw it
for i=1 upto 3:
source[i] := image(fill se withcolor .9[blue,white]; draw se; label(source[i], origin)) shifted (-u,v*(3-i));
draw source[i];
endfor
for i=1 upto 4:
target[i] := image(fill se withcolor .9[red,white]; draw se; label(target[i], origin)) shifted (+u,v*(3.5-i));
draw target[i];
endfor
% a macro to do the connnections, with neat line crossings
vardef connect(expr i,j) =
save A; path A;
A = center source[i] shifted 24 right --
center target[j] shifted 24 left
cutbefore se shifted center source[i]
cutafter se shifted center target[j];
undraw subpath (0.2,0.8) of A withpen pencircle scaled 3;
drawarrow A;
enddef;
% one loop of each source "node"
forsuffixes $=1,2: connect(1,$); endfor
forsuffixes $=2,3,4: connect(2,$); endfor
forsuffixes $=3,4: connect(3,$); endfor
endfig;
end.