在 Beamer 中排列树的节点

在 Beamer 中排列树的节点

我正在尝试使用 创建一棵树beamerforest两个相邻节点之间的线间距不等。有人能帮忙吗?

\documentclass{beamer}
\usepackage{tikz-cd}
\colorlet{ProcessBlue}{blue!50!cyan}
\tikzset{
  selected/.style={draw=ProcessBlue, thick, rounded corners=2pt, inner color=ProcessBlue!25, outer color=ProcessBlue!35, drop shadow,}
}
\usepackage{forest}
\usetikzlibrary{shadows,arrows.meta}
\usetikzlibrary{trees}

\tikzset{hide on/.code={\only<#1>{\color{white}}}}

\begin{document}
\setbeamertemplate{caption}[numbered]
\subsection{frame 2}
\begin{frame}[fragile,shrink=20]
\begin{forest}
  for tree={
    parent anchor=south,
    child anchor=west,
    anchor=west,
    selected,
    grow=-45,
    font=\sffamily,
    edge path={
      \noexpand\path [draw, thick, -{Stealth[]}, \forestoption{edge}] (!u.parent anchor) |- (.child anchor)\forestoption{edge label};
    },
  },
  before typesetting nodes={
    for tree={
      if level=0{}{
        content/.wrap 2 pgfmath args={#1. #2}{level()}{content()},
      },
    },
  }
  [\LaTeX
    [TestTest
      [StartTestStartTestStartTestStartTest
        [DoTest
          [MakeTest
            [TestTest
            ]
          ]
        ]
      ]
    ]
  ]
\end{forest}
\end{frame}
\end{document}

答案1

该行为由指令触发grow=-45。如果要保持距离不变,您可能需要使用ls键。

\documentclass{beamer}
\usepackage{tikz-cd}
\colorlet{ProcessBlue}{blue!50!cyan}
\tikzset{
  selected/.style={draw=ProcessBlue, thick, rounded corners=2pt, inner color=ProcessBlue!25, outer color=ProcessBlue!35, drop shadow,}
}
\usepackage{forest}
\usetikzlibrary{shadows,arrows.meta}
\usetikzlibrary{trees}

\tikzset{hide on/.code={\only<#1>{\color{white}}}}

\begin{document}
\setbeamertemplate{caption}[numbered]
\subsection{frame 2}
\begin{frame}[fragile,shrink=20]
\begin{forest}
  for tree={l=1.2cm,s=1.2cm,
    parent anchor=south west,
    child anchor=west,
    anchor=west,
    selected,
    font=\sffamily,
    edge path={
      \noexpand\path [draw, thick, -{Stealth[]}, \forestoption{edge}] (!u.parent anchor) |- (.child anchor)\forestoption{edge label};
    },
  },
  before typesetting nodes={
    for tree={calign=fixed edge angles,
      if level=0{}{
        content/.wrap 2 pgfmath args={#1. #2}{level()}{content()},
      },
    }
  }
  [\LaTeX
    [TestTest
      [StartTestStartTestStartTestStartTest,l sep=0
        [DoTest
          [MakeTest
            [TestTest
            ]
          ]
        ]
      ]
    ]
  ]
\end{forest}
\end{frame}
\end{document}

在此处输入图片描述

相关内容