使用 Latex 的树

使用 Latex 的树

我想减小节点的大小,以便在我的演示中让他们感觉更好;问题是节点重叠。

我有来自的代码在 TikZ 中绘制许多节点具有相同子节点的树

  \begin{tikzpicture} [sibling distance=1.5cm]
      \node [size=0.3cm](topnode) at (0,5) { {\{\{1\}\{2\}\}\{3\}\{4\}}\} } 
      child { node[size=0.3cm] {{\{\{1,2\}\{3\}\{4\}}\}} }
      child { node[size=0.3cm] {{\{\{1,3\}\{2\}\{4\}}\}} }
      child { node[size=0.3cm] {{\{\{1,4\}\{2\}\{3\}}\}} }
      child { node[size=0.3cm] {{\{\{2,3\}\{1\}\{4\}}\}} }
      child { node[size=0.3cm] {{\{\{2,4\}\{1\}\{3\}}\}} }
      child { node[size=0.3cm] {{\{\{3,4\}\{1\}\{2\}}\}} }
      ;


      \node[minimum width=3cm](bottomnode) {\{\{1,2,3,4\}\}} [grow'=up]
      child { node[size=0.3cm] {{\{\{1,2,3\}\{4\}}\}} }
      child { node[size=0.3cm] {{\{\{1,2,4\}\{3\}}\}} }
      child { node[size=0.3cm] {{\{\{1,2\}\{3,4\}}\}} }
      child { node[size=0.3cm] {{\{\{1,3,4\}\{2\}}\}} }
      child { node[size=0.3cm] {{\{\{1,3\}\{2,4\}}\}} }
      child { node[size=0.3cm] {{\{\{1,4\}\{2,3\}}\}} }
      child { node[size=0.3cm] {{\{\{2,3,4\}\{1\}}\}} }
      ;
      \foreach \x in {1,2,3}{
      \draw  [blue](topnode-1) -- (bottomnode-\x);
      }

      \foreach \x in {1,4,5}{
      \draw (topnode-2) -- (bottomnode-\x);
      }

      \foreach \x in {2,4,6}{
      \draw  [red] (topnode-3) -- (bottomnode-\x);
      }
      \foreach \x in {2,4,6}{
      \draw  [red] (topnode-3) -- (bottomnode-\x);
      }

      \foreach \x in {1,6,7}{
      \draw  [blue](topnode-4) -- (bottomnode-\x);
      }

      \foreach \x in {2,7,5}{
      \draw  [red](topnode-5) -- (bottomnode-\x);
      }

      \foreach \x in {3,4,7}{
      \draw (topnode-6) -- (bottomnode-\x);
      }

      \end{tikzpicture}

在此处输入图片描述

答案1

最简单的解决方案是减小节点的字体大小。您可以通过以下方式实现:

\tikzset{every node/.append style={font=\tiny}}

以下是 MWE:

\documentclass{beamer}
\usepackage{tikz}
\usetikzlibrary{trees}
\usetheme{Frankfurt}

\begin{document}
\begin{frame}{TITLE}


\begin{tikzpicture} [sibling distance=1.5cm]
\tikzset{every node/.append style={font=\tiny}}
      \node [minimum size=0.3cm](topnode) at (0,5) { {\{\{1\}\{2\}\}\{3\}\{4\}}\} } 
      child { node[minimum size=0.3cm] {{\{\{1,2\}\{3\}\{4\}}\}} }
      child { node[minimum size=0.3cm] {{\{\{1,3\}\{2\}\{4\}}\}} }
      child { node[minimum size=0.3cm] {{\{\{1,4\}\{2\}\{3\}}\}} }
      child { node[minimum size=0.3cm] {{\{\{2,3\}\{1\}\{4\}}\}} }
      child { node[minimum size=0.3cm] {{\{\{2,4\}\{1\}\{3\}}\}} }
      child { node[minimum size=0.3cm] {{\{\{3,4\}\{1\}\{2\}}\}} }
      ;


      \node[minimum width=3cm](bottomnode) {\{\{1,2,3,4\}\}} [grow'=up]
      child { node[minimum size=0.3cm] {{\{\{1,2,3\}\{4\}}\}} }
      child { node[minimum size=0.3cm] {{\{\{1,2,4\}\{3\}}\}} }
      child { node[minimum size=0.3cm] {{\{\{1,2\}\{3,4\}}\}} }
      child { node[minimum size=0.3cm] {{\{\{1,3,4\}\{2\}}\}} }
      child { node[minimum size=0.3cm] {{\{\{1,3\}\{2,4\}}\}} }
      child { node[minimum size=0.3cm] {{\{\{1,4\}\{2,3\}}\}} }
      child { node[minimum size=0.3cm] {{\{\{2,3,4\}\{1\}}\}} }
      ;
      \foreach \x in {1,2,3}{
      \draw  [blue](topnode-1) -- (bottomnode-\x);
      }

      \foreach \x in {1,4,5}{
      \draw (topnode-2) -- (bottomnode-\x);
      }

      \foreach \x in {2,4,6}{
      \draw  [red] (topnode-3) -- (bottomnode-\x);
      }
      \foreach \x in {2,4,6}{
      \draw  [red] (topnode-3) -- (bottomnode-\x);
      }

      \foreach \x in {1,6,7}{
      \draw  [blue](topnode-4) -- (bottomnode-\x);
      }

      \foreach \x in {2,7,5}{
      \draw  [red](topnode-5) -- (bottomnode-\x);
      }

     \foreach \x in {3,4,7}{
     \draw (topnode-6) -- (bottomnode-\x);
      }

      \end{tikzpicture}

\end{frame}

\end{document}

这导致:

在此处输入图片描述

请注意,在您的示例中,由于size=我转换为的选项,我遇到了编译问题minimum size=

相关内容