我想让文本节点自动弹出到投影仪幻灯片中定义的部分/框中的随机位置。目前,我将带有节点文本的字符串存储在数组中,并使用循环遍历该数组foreach
。
我的问题:
- 每次循环步骤都会重新计算所有节点位置。由于
rand
节点位置已显示节点也会获得新坐标。我可以为已显示节点设置固定坐标吗? - 我如何使用
tikzpicture
完整的右栏? - 是否可以通过使每个节点在一定时间后可见来在一张幻灯片/帧上为该覆盖设置动画,而不必单击每个覆盖?
平均能量损失
\documentclass{beamer}
\usepackage{tikz}
\usetikzlibrary{calc}
\usetikzlibrary{fit}
\usetikzlibrary{positioning}
\usetikzlibrary{shapes}
\begin{document}
\begin{frame}[t]{test}
\begin{columns}
\begin{column}{0.39\textwidth}
\begin{itemize}
\item Some text
\end{itemize}
\end{column}
\begin{column}{0.6\textwidth}
\centering
\def\namelist{{"test1","test2","test3","test4","test5","test6","test7"}}%
\tikzset{%
cloudstyle/.style={%
cloud,
cloud puffs=11.5,
aspect=3,
align=center,
inner sep=0pt,
draw,
fill=lightgray,
}%
}
\begin{tikzpicture}
\foreach \i in {0,...,3} {
\pgfmathtruncatemacro\z{\i+1}
\visible<\z->{
\pgfmathsetmacro\mynodename{\namelist[\i]}
\node[cloudstyle] (\mynodename) at (rand,rand) {\mynodename};
}
}
\end{tikzpicture}
\end{column}
\end{columns}
\end{frame}
\end{document}
它看起来怎么样
答案1
在此代码中,使用命令一次性创建列表
\CreateRandomCoordinateList{<list>}{<# of entries>}{<prefactor x>}{<prefactor y>}
第二个技巧是给图片添加一个边界框,否则节点看起来会跳跃。(也可以编写一个没有边界框的解决方案。)下面生成一个动画。要使其自动动画,请acroread
在全屏模式下使用。\transduration<2-6>{1}
表示步骤之间有 1 秒。
\documentclass{beamer}
\usepackage{tikz}
\usetikzlibrary{calc}
\usetikzlibrary{fit}
\usetikzlibrary{positioning}
\usetikzlibrary{shapes,overlay-beamer-styles}
\newcommand{\CreateRandomCoordinateList}[4]{
\foreach \X in {1,...,#2}
{\pgfmathsetmacro{\myx}{rand*#3}
\pgfmathsetmacro{\myy}{rand*#4}
\ifnum\X=1
\xdef#1{(\myx,\myy)}
\else
\xdef#1{#1,(\myx,\myy)}
\fi}
}
\begin{document}
\CreateRandomCoordinateList{\lstRnd}{6}{2}{2}
%\typeout{\lstRnd}
\newcount\NumClouds
\begin{frame}[t]{test}
\animate<2-6>
\animatevalue<1-6>{\NumClouds}{1}{6}
\transduration<2-6>{1}
\begin{columns}
\begin{column}{0.39\textwidth}
\begin{itemize}
\item Some text
\end{itemize}
\end{column}
\begin{column}{0.6\textwidth}
\centering
\edef\namelist{{"test1","test2","test3","test4","test5","test6","test7"}}%
\tikzset{%
cloudstyle/.style={%
cloud,
cloud puffs=11.5,
aspect=3,
align=center,
inner sep=0pt,
draw,
fill=lightgray,
}%
}
\begin{tikzpicture}
\path[use as bounding box] (-1,-1) rectangle (3,3);
\foreach \Coord [count=\z,evaluate=\z as \i using {int(\z-1)}] in
\lstRnd {
\pgfmathsetmacro\mynodename{\namelist[\i]}
\ifnum\i<\NumClouds
\node[cloudstyle] (\mynodename) at \Coord {\mynodename};
\fi
}
\end{tikzpicture}
\end{column}
\end{columns}
\end{frame}
\end{document}
这是我使用的一个小变化杰克的代码建立一个坐标列表,使得云不会重叠。
\documentclass{beamer}
\usepackage{tikz}
\usetikzlibrary{calc}
\usetikzlibrary{fit}
\usetikzlibrary{positioning}
\usetikzlibrary{shapes,overlay-beamer-styles}
% from https://tex.stackexchange.com/a/87518/121799
\def\xlist{2}
\def\ylist{2}
\newcommand{\fillrandomly}[4]{
\pgfmathsetmacro\diameter{#3*2}
%\draw (0,0) rectangle (#1,#2);
\foreach \i in {1,...,#4}{
\pgfmathsetmacro\x{rnd*#1}
\pgfmathsetmacro\y{rnd*#2}
\xdef\collision{0}
\foreach \element [count=\i] in \xlist{
\pgfmathtruncatemacro\j{\i-1}
\pgfmathsetmacro\checkdistance{ sqrt( 0.25*({\xlist}[\j]-(\x))^2 + ({\ylist}[\j]-(\y))^2 ) }
\ifdim\checkdistance pt<\diameter pt
\xdef\collision{1}
\breakforeach
\fi
}
\ifnum\collision=0
\xdef\xlist{\xlist,\x}
\xdef\ylist{\ylist,\y}
%\draw [red, thick] (\x,\y) circle [radius=#3];
\fi
}
}
\begin{document}
% creates random list
\fillrandomly{6}{8}{0.6}{7}
%\typeout{xlist=\xlist,ylist=\ylist}
\begin{frame}[t]{test}
\begin{columns}
\begin{column}{0.39\textwidth}
\begin{itemize}
\item Some text
\end{itemize}
\end{column}
\begin{column}{0.6\textwidth}
\centering
\edef\namelist{{"test1","test2","test3","test4","test5","test6","test7"}}%
\tikzset{%
cloudstyle/.style={%
cloud,
cloud puffs=11.5,
aspect=3,
align=center,
inner sep=0pt,
draw,
fill=lightgray,
}%
}
\begin{tikzpicture}[scale=0.5]
\path[use as bounding box] (-1,-1) rectangle (7,9);
\foreach \X [count=\z,evaluate=\z as \i using {int(\z-1)}] in
\xlist {
\pgfmathsetmacro{\Y}{{\ylist}[\i]}
\pgfmathsetmacro\mynodename{\namelist[\i]}
%\typeout{x=\X,y=\Y,name=\mynodename}
\node[cloudstyle,visible on=<\z->] (\mynodename) at (\X,\Y) {\mynodename};
}
\end{tikzpicture}
\end{column}
\end{columns}
\end{frame}
\end{document}