我该如何改进这个动画的代码,以便我可以写出更多的单词?我想要一个更智能的代码。
\documentclass{article}
\usepackage{tikz}
\usepackage[active,tightpage]{preview}
\PreviewEnvironment{tikzpicture}
\setlength\PreviewBorder{0pt}%
\begin{document}
\foreach \t in {
L,
La,
LaT,
LaTe,
LaTeX
}{
\begin{tikzpicture}[scale=1]
\clip[fill=white] (0,-1) rectangle (6,1);
\node[right] at (1,0) {\Huge \t};
\end{tikzpicture}
}
\end{document}
答案1
我对该软件包的卑微尝试xstring
:
\documentclass{article}
\usepackage{tikz}
\usepackage[active,tightpage]{preview}
\PreviewEnvironment{tikzpicture}
\setlength\PreviewBorder{0pt}
\usepackage{xstring}
\def\mytext{Hello world}
\StrLen{\mytext}[\mylen]
\begin{document}
\foreach \t in {0,...,\mylen}{%
\begin{tikzpicture}[scale=1]
\clip[] (0,-1) rectangle (6,1);
\node[right] at (1,0) {\Huge \StrLeft{\mytext}{\t}};
\end{tikzpicture}
}%
\end{document}
我们还可以将代码放入新命令中\typewriter
:
\newcommand{\typewriter}[1]{%
\StrLen{#1}[\mylen]
\foreach \t in {0,...,\mylen}{%
\begin{tikzpicture}[scale=1]
\clip[] (0,-1) rectangle (6,1);
\node[right] at (1,0) {\Huge \StrLeft{#1}{\t}};
\end{tikzpicture}
}%
}%
然后调用它:
\typewriter{Hello world}
就这样。:)