beamer
我正在尝试使用创建树forest
。添加长文本会使内容移出框架。有人能帮忙吗?
\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]
\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}
链接在这里[https://www.sharelatex.com/read/yhsvqfxzfgbv ] 到 sharelatex 项目,来源
答案1
我认为您从其他人那里获得了该代码,但您没有承认。如果能提供链接,我将不胜感激;注明出处只是出于礼貌,而且可能也很有用。
无论如何,你真的不想grow=45
在这里使用。你的节点内容有时很长,而且变化很大。结果可想而知是有问题的。
为什么不直接使用内置folder
风格?
\documentclass{beamer}
\colorlet{ProcessBlue}{blue!50!cyan}
\usepackage[edges]{forest}
\usetikzlibrary{shadows,arrows.meta}
\tikzset{
selected/.style={draw=ProcessBlue, thick, rounded corners=2pt, inner color=ProcessBlue!25, outer color=ProcessBlue!35, drop shadow,},
}
\begin{document}
\setbeamertemplate{caption}[numbered]
\subsection{frame 2}
\begin{frame}[fragile]
\begin{forest}
folder indent'+=10pt,
for tree={
folder,
grow'=0,
l sep'+=20pt,
s sep'+=10pt,
selected,
font=\sffamily,
edge+={thick, -{Stealth[]}},
},
before typesetting nodes={
for tree={
if level=0{}{
content/.process={OOw2{level}{content}{#1. #2}},
},
},
}
[\LaTeX
[TestTest
[StartTestStartTestStartTestStartTest
[DoTest
[MakeTest
[TestTest
]
]
]
]
]
]
\end{forest}
\end{frame}
\end{document}
顺便说一句,将文本设为白色并不是在 Beamer 演示文稿中隐藏内容的好方法!目前已经有很多专门为此设计的样式,您最好使用这些样式。(甚至还有一些专门针对 Forest 树的样式。)
答案2
我不知道森林包,但用蒂克兹仅此而已。一个非常简单的代码是:
\documentclass[11pt]{beamer}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usetheme{default}
\usepackage{tikz}
\usetikzlibrary{shadows,positioning}
\begin{document}
\begin{frame}[shrink=25]
\frametitle{Test}
\colorlet{ProcessBlue}{blue!50!cyan}
\begin{center}
\begin{tikzpicture}[inner sep=2mm,
ar/.style={->,>=stealth,thick},
every node/.style={rectangle,rounded corners=2pt,
drop shadow,draw=ProcessBlue,fill=ProcessBlue!35,thick,
node distance=1.2cm %vertical distance
}]
%leaf
\node (n0) {\LaTeX};
\node (n1) [below = of n0,xshift=9ex] {1. TestTest};
\node (n2) [below = of n1,xshift=23ex] {2.StartTestStartTestStartTestStartTest};
\node (n3) [below = of n2,xshift=18ex] {3. DoTest};
\node (n4) [below = of n3,xshift=12ex] {4. MakeTest};
\node (n5) [below = of n4,xshift=12ex] {5.TestTest};
%arrows
\foreach \ns/\ne in{0/1,1/2,2/3,3/4,4/5}
\draw[ar] (n\ns) |- (n\ne);
\end{tikzpicture}
\end{center}
\end{frame}
\end{document}
树的所有“叶子”之间的垂直距离由 控制node distance
,单个叶子与上方叶子之间的水平距离由 控制xshift
。结果是