答案1
如果您只需要骨架,这很容易。否则使用forest
。
\documentclass[tikz,border=3mm]{standalone}
\tikzset{pics/tournament/.style={code={
\def\pv##1{\pgfkeysvalueof{/tikz/tournament/##1}}
\tikzset{tournament/.cd,#1}
\foreach \XX [remember=\XX as \LastXX] in {\pv{n},...,0}
{\pgfmathtruncatemacro{\mym}{pow(2,\XX)}
\ifnum\XX=\pv{n}
\foreach \YY in {1,...,\mym}
{\draw (-\XX*\pv{d},{(\YY-\mym/2-1/2)*\pv{l}})
-- ++ (\pv{d},0) |- coordinate[pos=0.25] (p-\XX-\YY)
(-\XX*\pv{d},{(\YY-\mym/2-1)*\pv{l}})
;}
\else
\foreach \YY [evaluate=\YY as \ZZ using {int(2*\YY)}] in {1,...,\mym}
{
\draw (p-\LastXX-\ZZ) -- ++ (\pv{d},0)
|- coordinate[pos=0.25] (p-\XX-\YY)
(p-\LastXX-\the\numexpr\ZZ-1);
}
\fi}
\draw (p-0-1) -- ++ (\pv{d},0);
}},tournament/.cd,n/.initial=2,l/.initial=1,d/.initial=2}
\begin{document}
\begin{tikzpicture}
\pic{tournament};
\end{tikzpicture}
\begin{tikzpicture}
\pic{tournament={n=3,d=1.5}};
\end{tikzpicture}
\end{document}