这是该问题的后续问题:使 Tikz 自动节点放置工作
特别是 Mark Wibrow 的职位(第二位)。
他的解决方案适用于 16 个节点,但我正在寻找一个可以完成相同操作但适用于 32 个节点的解决方案,如下所示:
\foreach \bytes [count=\y from 0] in {
{null},
{a,b,c,d,e},
{ab,ac,ad,ae,bc,bd,be,cd,ce,de},
{abc,abd,abe,acd,ace,ade,bcd,bce,bde,cde},
{abcd,abce,abde,acde,bcde},
{abcde}}
您能帮我编辑以下内容吗:
这
at ({\x+abs(2-\y)+(mod(\y, 4)==0)/2}, -\y)
所有 32 个节点都是中心对称的。
上述解决方案仅适用于 16 个节点!
我的节点 a -> ab、a -> ac、a -> ad 等等都是连接的。
解决方案
\foreach \x in {0,...,15}{ \foreach \y in {\x,...,15}{ \ifnum\x=\y \else \process{\x}{\y} \ifnum\pgfmathresult=1 \draw [<->] (\x) -- (\y); \fi \fi } }
不起作用。
我想要绘制这样的图形(取自[1],第 8 页)
答案1
位置问题可以按照上面的评论中提到的那样,通过计算二项式系数来解决,如下所示:
\documentclass[border=0.125cm]{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric}
\begin{document}
\begin{tikzpicture}[x=2cm,y=2cm]
\foreach \l [count=\y from 0] in {{null},
{a,b,c,d,e},
{ab,ac,ad,ae,bc,bd,be,cd,ce,de},
{abc,abd,abe,acd,ace,ade,bcd,bce,bde,cde},
{abcd,abce,abde,acde,bcde},
{abcde}}
\foreach \m [count=\x from 0] in \l
\node [ellipse, draw, anchor=base, minimum width=1cm, minimum height=0.75cm]
(\m) at ({-(5!/\y!/(5-\y)!)/2+\x},-\y) {\m};
\end{tikzpicture}
\end{document}
这样就可以完成连接。
\documentclass[border=0.125cm]{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric}
\newcount\incount
\def\in#1#2{\incount=0\relax\edef\marshal{\noexpand\In#1@@;#2@@;}\marshal}
\def\In#1#2;#3#4;{%
\ifx#1@%
\ifx#3@%
\incount=\ifnum0>\incount-\fi\incount%
\let\next=\relax%
\else%
\advance\incount by-1%
\def\next{\In#1#2;#4;}%
\fi%
\else%
\def\test##1#1##2##3?{\ifx##2*\else\advance\incount by1\fi}%
\test#3#4;#1**?%
\def\next{\In#2;#3#4;}%
\fi%
\next%
}
\begin{document}
\begin{tikzpicture}[declare function={nchoosek(\n,\k)=\n!/(\k!*(\n-\k)!);}, x=2cm,y=3cm]
\foreach \R [count=\y from 0, evaluate={\s=nchoosek(5,\y);}, remember=\R as \r] in {{null},
{a,b,c,d,e},
{ab,ac,ad,ae,bc,bd,be,cd,ce,de},
{abc,abd,abe,acd,ace,ade,bcd,bce,bde,cde},
{abcd,abce,abde,acde,bcde},
{abcde}}
\foreach \C [count=\x from 0] in \R {
\node [ellipse, draw, anchor=base, minimum width=1cm, minimum height=0.75cm]
(\C) at (-\s/2+\x,-\y+1) {\C};
\foreach \c in \r {
\in{\c}{\C}
\ifnum\incount=1
\draw (\c.south) -- (\C.north);
\fi
}
}
\end{tikzpicture}
\end{document}