编辑

编辑

我正在做一个涉及足球比赛的数学项目。我希望我能制作出这样的树形图。有人能帮我提供基本代码吗?我觉得制作这个图表需要 tikz,而我不擅长。谢谢你的帮助! 在此处输入图片描述

顺便说一句,我不需要有关比赛日期和地点的文字。再次感谢您的关注!

答案1

与其他一些解决方案相比,这个forest解决方案需要的输入要少一些。

基本思路是将图表视为一棵树,最右边有一个不可见的根节点。它有两个子节点:最后一个节点和分离的第三名节点。为了避免影响主树,分离节点是在所有其他节点排版并设置其位置后绘制的。

matchnode={<flag-1>}{<team-1>}{<score-1>}{<flag-2>}{<team-2>}{<score-3>}是用于定义每个匹配项的表格内容的样式。每个应为包含相关 标志<flag>的图像文件的名称。<team>

round name={<name>}是用于定义顶部标记的比赛阶段的样式。季军赛的标题直接添加到相关节点,因为这是一次性的。

颜色设置为linebluefillbluetextblue。所有节点的整体外观使用 样式设置footnode,可根据需要进行修改。分支的一般形状和厚度使用 来设置forestedge例如,如果您想要直边,只需说edge={ultra thick},删除rounded corners...规范。

\PassOptionsToPackage{dvipsnames,svgnames,x11names,rgb,table}{xcolor}
\documentclass[tikz,border=10pt]{standalone}
\usepackage{array,forest}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usetikzlibrary{positioning,shadows}
\colorlet{textblue}{blue!75!black}
\colorlet{lineblue}{blue}
\colorlet{fillblue}{blue!10}
\newlength\Tht
\settoheight{\Tht}{T}
\begin{document}
\arrayrulecolor{lineblue}
\begin{forest}
  /tikz/footnode/.style={
    font=\sffamily,
    text=textblue,
    draw=lineblue,
    inner color=fillblue!75,
    outer color=fillblue,
    drop shadow,
    rounded corners=1pt,
  },
  matchnode/.style n args=6{
    footnode,
    inner sep=0pt,
    content={\includegraphics[height=\Tht]{#1} \textcolor{textblue}{#2}&\textcolor{black}{#3}\\\hline\includegraphics[height=\Tht]{#4} \textcolor{textblue}{#5}&\textcolor{black}{#6}},
  },
  round name/.style={
    tikz={\node [above=of .center |- pen.north, anchor=mid, footnode, minimum height=4ex] {#1};}
  },
  match align/.style={
    align={l|c},
    parent anchor=west,
    child anchor=east,
    anchor=west,
  },
  for tree={
    edge path={
      \noexpand\path [draw, \forestoption{edge}] (!u.parent anchor) -- +(-10pt,0) |- (.child anchor)\forestoption{edge label};
    },
    l sep+=20pt,
    match align,
    grow=180,
    edge={ultra thick, rounded corners},
    footnode,
    tier/.wrap pgfmath arg={tier #1}{level()},
  },
  [, phantom,
    before drawing tree={
      append={[, match align, matchnode={example-image-a}{Team E}{0}{example-image-b}{Team M}{2}, typeset node, afterthought={\node [above=10pt of .north, anchor=south, footnode, minimum height=4ex] {Third place};}]},
    }
    [, matchnode={example-image-a}{Team A}{1}{example-image-b}{Team I}{0}, round name=Final
      [, matchnode={example-image-a}{Team A}{1}{example-image-b}{Team E}{0}, round name=Semi-Finals
        [, matchnode={example-image-a}{Team A}{1}{example-image-b}{Team C}{0}, round name=Quarter-Finals
          [, matchnode={example-image-a}{Team A}{1}{example-image-b}{Team B}{0}, name=pen, round name=Round of 16]
          [, matchnode={example-image-a}{Team C}{1}{example-image-b}{Team D}{0}]
        ]
        [, matchnode={example-image-a}{Team E}{2}{example-image-b}{Team G}{1}
          [, matchnode={example-image-a}{Team E}{1}{example-image-b}{Team F}{0}]
          [, matchnode={example-image-a}{Team G}{1}{example-image-b}{Team H}{0}]
        ]
      ]
      [, matchnode={example-image-a}{Team I}{1}{example-image-b}{Team M}{0}
        [, matchnode={example-image-a}{Team I}{1}{example-image-b}{Team K}{0}
          [, matchnode={example-image-a}{Team I}{0 (4)}{example-image-b}{Team J}{0 (2)}]
          [, matchnode={example-image-a}{Team K}{1}{example-image-b}{Team L}{0}]
        ]
        [, matchnode={example-image-a}{Team M}{1}{example-image-b}{Team O}{0}
          [, matchnode={example-image-a}{Team M}{1}{example-image-b}{Team N}{0}]
          [, matchnode={example-image-a}{Team O}{1}{example-image-b}{Team P}{0}]
        ]
      ]
    ]
  ]
\end{forest}

\end{document}

足球世界杯

编辑

这是另一个版本,它使用免费软件字体提供旗帜符号,并使用颜色系列随机为其应用颜色。样式的第一个和第四个参数matchnode现在不再指定相关旗帜的图像文件,而是指定免费软件字体中的相关字符。

该解决方案需要lualatexxelatex请注意不是工作。(当然,pdflatexlatex也不会工作,因为代码要求fontspec。)

\PassOptionsToPackage{dvipsnames,svgnames,x11names,rgb,table}{xcolor}
\documentclass[tikz,border=10pt]{standalone}
\usepackage{array,forest}
\usepackage{fontspec}
\newfontfamily\fflag{Flags.ttf}
\usetikzlibrary{positioning,shadows}
\colorlet{textblue}{blue!75!black}
\colorlet{lineblue}{blue}
\colorlet{fillblue}{blue!10}
\newlength\Tht
\settoheight{\Tht}{T}
% xcolor manual: 34
\definecolorseries{colours}{hsb}{grad}[hsb]{.575,1,1}{.987,-.234,0}
\resetcolorseries[12]{colours}
\begin{document}
\arrayrulecolor{lineblue}
\begin{forest}
  /tikz/footnode/.style={
    font=\sffamily,
    text=textblue,
    draw=lineblue,
    inner color=fillblue!75,
    outer color=fillblue,
    drop shadow,
    rounded corners=1pt,
  },
  matchnode/.style n args=6{
    footnode,
    inner sep=0pt,
    content={\raisebox{-.25em}{\fflag\color{colours!!+}#1} \textcolor{textblue}{#2}&\textcolor{black}{#3}\\\hline\raisebox{-.25em}{\fflag\color{colours!!+}#4} \textcolor{textblue}{#5}&\textcolor{black}{#6}},
  },
  round name/.style={
    tikz={\node [above=of .center |- pen.north, anchor=mid, footnode, minimum height=4ex] {#1};}
  },
  match align/.style={
    align={l|c},
    parent anchor=west,
    child anchor=east,
    anchor=west,
  },
  for tree={
    edge path={
      \noexpand\path [draw, \forestoption{edge}] (!u.parent anchor) -- +(-10pt,0) |- (.child anchor)\forestoption{edge label};
    },
    l sep+=20pt,
    match align,
    grow=180,
    edge={ultra thick, rounded corners},
    footnode,
    tier/.wrap pgfmath arg={tier #1}{level()},
  },
  [, phantom,
    before drawing tree={
      append={[, match align, matchnode={E}{Team E}{0}{M}{Team M}{2}, typeset node, afterthought={\node [above=10pt of .north, anchor=south, footnode, minimum height=4ex] {Third place};}]},
    }
    [, matchnode={A}{Team A}{1}{I}{Team I}{0}, round name=Final
      [, matchnode={A}{Team A}{1}{E}{Team E}{0}, round name=Semi-Finals
        [, matchnode={A}{Team A}{1}{C}{Team C}{0}, round name=Quarter-Finals
          [, matchnode={A}{Team A}{1}{B}{Team B}{0}, name=pen, round name=Round of 16]
          [, matchnode={C}{Team C}{1}{D}{Team D}{0}]
        ]
        [, matchnode={E}{Team E}{2}{G}{Team G}{1}
          [, matchnode={E}{Team E}{1}{F}{Team F}{0}]
          [, matchnode={G}{Team G}{1}{H}{Team H}{0}]
        ]
      ]
      [, matchnode={I}{Team I}{1}{M}{Team M}{0}
        [, matchnode={I}{Team I}{1}{K}{Team K}{0}
          [, matchnode={I}{Team I}{0 (4)}{J}{Team J}{0 (2)}]
          [, matchnode={K}{Team K}{1}{L}{Team L}{0}]
        ]
        [, matchnode={M}{Team M}{1}{O}{Team O}{0}
          [, matchnode={M}{Team M}{1}{N}{Team N}{0}]
          [, matchnode={O}{Team O}{1}{P}{Team P}{0}]
        ]
      ]
    ]
  ]
\end{forest}

\end{document}

带有 LuaLaTeX 的字体标志版本

我使用的字体是 Sunwalk 的“Flags”,可以这里

答案2

通过定义基本block样式并使用节点对齐,这是一种可能性。

在此处输入图片描述

代码

\documentclass[border=15pt]{standalone}
\usepackage{tikz}
\usepackage{graphicx}
\usetikzlibrary{positioning,arrows,calc}
\tikzset{block/.style = {rectangle, draw,fill=blue!10,
text width=5cm, minimum height=0.5cm},
}
\begin{document}
\begin{tikzpicture}
\path (0,0) 
node[block,text centered](a){Round of 16} 
node[block,text centered,right=2cm of a](b){Quarter-finals}
node[block,text centered,right=2cm of b](c){Semi-finals}
node[block,text centered,right=2cm of c](d){Finals};

\node[block,below=0.5cm of a]  (r1){\includegraphics[scale=0.05]{example-image-a}\,Brazil\hfill 1(2)};
\node[block,below=0cm of r1]   (r2){\includegraphics[scale=0.05]{example-image-b}\,Chile\hfill 1(2)};
\node[block,below=0.5cm of r2] (r3){\includegraphics[scale=0.05]{example-image-a}\,Brazil\hfill 1(2)};
\node[block,below=0cm of r3]   (r4){\includegraphics[scale=0.05]{example-image-b}\,Chile\hfill 1(2)};
\node[block,below=0.5cm of r4] (r5){\includegraphics[scale=0.05]{example-image-a}\,Brazil\hfill 1(2)};
\node[block,below=0cm of r5]   (r6){\includegraphics[scale=0.05]{example-image-b}\,Chile\hfill 1(2)};
\node[block,below=0.5cm of r6] (r7){\includegraphics[scale=0.05]{example-image-a}\,Brazil\hfill 1(2)};
\node[block,below=0cm of r7]   (r8){\includegraphics[scale=0.05]{example-image-b}\,Chile\hfill 1(2)};
\node[block,below=0.5cm of r8] (r9){\includegraphics[scale=0.05]{example-image-a}\,Brazil\hfill 1(2)};
\node[block,below=0cm of r9]   (r10){\includegraphics[scale=0.05]{example-image-b}\,Chile\hfill 1(2)};
\node[block,below=0.5cm of r10](r11){\includegraphics[scale=0.05]{example-image-a}\,Brazil\hfill 1(2)};
\node[block,below=0cm of r11]  (r12){\includegraphics[scale=0.05]{example-image-b}\,Chile\hfill 1(2)};
\node[block,below=0.5cm of r12](r13){\includegraphics[scale=0.05]{example-image-a}\,Brazil\hfill 1(2)};
\node[block,below=0cm of r13]  (r14){\includegraphics[scale=0.05]{example-image-b}\,Chile\hfill 1(2)};
\node[block,below=0.5cm of r14](r15){\includegraphics[scale=0.05]{example-image-a}\,Brazil\hfill 1(2)};
\node[block,below=0cm of r15]  (r16){\includegraphics[scale=0.05]{example-image-b}\,Chile\hfill 1(2)};
%------------
\node[block,below=1.5cm of b] (q1){\includegraphics[scale=0.05]{example-image-a}\,Brasil\hfill 1(2)};
\node[block,below=0cm of q1]  (q2){\includegraphics[scale=0.05]{example-image-b}\,Colombia\hfill 1(2)};
\node[block,below=2.8cm of q2](q3){\includegraphics[scale=0.05]{example-image-a}\,Brasil\hfill 1(2)};
\node[block,below=0cm of q3]  (q4){\includegraphics[scale=0.05]{example-image-b}\,Colombia\hfill 1(2)};
\node[block,below=2.8cm of q4](q5){\includegraphics[scale=0.05]{example-image-a} Brasil\hfill1(2)};
\node[block,below=0cm of q5]  (q6){\includegraphics[scale=0.05]{example-image-b}\,Colombia\hfill 1(2)};
\node[block,below=2.8cm of q6](q7){\includegraphics[scale=0.05]{example-image-a}\,Brasil\hfill 1(2)};
\node[block,below=0cm of q7]  (q8){\includegraphics[scale=0.05]{example-image-b}\,Colombia\hfill 1(2)};

%-------------semifinal
\node[block,below=3.6cm of c] (s1){\includegraphics[scale=0.05]{example-image-a}\,Brasil\hfill 1(2)};
\node[block,below=0cm of s1]  (s2){\includegraphics[scale=0.05]{example-image-b}\, Germany\hfill1(2)};
\node[block,below=7.5cm of s2](s3){\includegraphics[scale=0.05]{example-image-a}\,Brasil\hfill 1(2)};
\node[block,below=0cm of s3]  (s4){\includegraphics[scale=0.05]{example-image-b}\,Germany\hfill 1(2)};
%--------- final
\node[block,below=8cm of d] (f1){\includegraphics[scale=0.05]{example-image-a}\,Brasil\hfill 1(2)};
\node[block,below=0cm of f1](f2){\includegraphics[scale=0.05]{example-image-b}\,Colombia\hfill 1(2)};
\node[block,below=3cm of f2,text centered]{Third places};
\node[block,below=4cm of f2](t1){\includegraphics[scale=0.05]{example-image-a}\,Brasil\hfill 1(2)};
\node[block,below=0cm of t1](t2){\includegraphics[scale=0.05]{example-image-b}\,Colombia\hfill 1(2)};

%---- connecting lines

\foreach \i/\j/\k in {1/3/1,5/7/3,9/11/5,13/15/7}{
\draw[thick] (r\i.south east) -- +(1,0) |- (q\k.south west);
\draw[thick] (r\j.south east) -- +(1,0) |- (q\k.south west);
}

\foreach \i/\j/\k in {1/3/1,5/7/3}{
\draw[thick] (q\i.south east) -- +(1,0) |- (s\k.south west);
\draw[thick] (q\j.south east) -- +(1,0) |- (s\k.south west);
}
\foreach \i/\j/\k in {1/3/1}{
\draw[thick] (s\i.south east) -- +(1,0) |- (f\k.south west);
\draw[thick] (s\j.south east) -- +(1,0) |- (f\k.south west);
}

\def\box{1.5cm}
\foreach \i/\j in {1/2,3/4,5/6,7/8,9/10,11/12,13/14,15/16}{
\draw[thick] ([xshift=\box]r\i.north) -- ([xshift=\box]r\j.south);
}
\foreach \i/\j in {1/2,3/4,5/6,7/8}{
\draw[thick] ([xshift=\box]q\i.north) -- ([xshift=\box]q\j.south);
}
\foreach \i/\j in {1/2,3/4}{
\draw[thick] ([xshift=\box]s\i.north) -- ([xshift=\box]s\j.south);
}
\foreach \i/\j in {1/2}{
\draw[thick] ([xshift=\box]f\i.north) -- ([xshift=\box]f\j.south);
}
\draw[thick] ([xshift=\box]t1.north) -- ([xshift=\box]t2.south);
\end{tikzpicture}
\end{document}

相关内容