我尝试了一种“for”循环策略,但没有效果。代码如下:
\documentclass{beamer}
\usepackage{tikz}
\usetikzlibrary{positioning,calc}
\usetikzlibrary{shapes,arrows,chains}
\begin{document}
\begin{frame}
\begin{tikzpicture}
\draw[->] (-3.5,0) -- (3.5,0) node [below] {};
\foreach \x in {-1,...,2}
\draw (\x, 0.1) -- (\x, -0.1) node [below] {\x};
\end{tikzpicture}
\end{frame}
\end{document}
但是,我不明白如何用日期/年份替换整数,可能通过节点下方(和某些数学运算上方)的某些文本突出显示。您有什么建议?
提前感谢一切
最好的
1dre
答案1
我会命名节点,然后明确添加信息 — 尤其是当信息不是自动生成时。例如,在下面的例子中,您将线路上的节点命名point1
为point5
,您可以使用它们做很多事情:
\documentclass{beamer}
\usepackage{tikz}
\usepackage[T1]{fontenc} % These are to avoid the problem with
\usepackage{lmodern} % missing font shapes
\usetikzlibrary{positioning,calc}
\usetikzlibrary{shapes,arrows,chains}
\begin{document}
\begin{frame}
\begin{tikzpicture}
\draw[thick, ->] (0,0) -- (6,0) node [below] {};
\foreach \x in {1,...,5}
\draw (\x, 0.1) -- node[pos=0.5] (point\x) {} (\x, -0.1);
% node's content --- access them as point1...point5
\path (point1) node [below] {Below of 1};
\path (point1) node [above] {$A=1$};
\path (point4) node [red, above] {Above 4};
\draw [blue, ->] (point3) -- ++(0,2) node [above] {and this!};
\path (point2) edge[green, bend right, <->] (point4);
% you got the idea...
\end{tikzpicture}
\end{frame}
\end{document}
答案2
第一个解决方案:
\documentclass{beamer}
\usepackage{tikz}
\usetikzlibrary{positioning,calc}
\usetikzlibrary{shapes,arrows,chains}
\begin{document}
\begin{frame}
\begin{tikzpicture}
\draw[->] (-3.5,0) -- (3.5,0) node [below] {};
\foreach \x/\d in {-1/1965,0/1980,1/2003,2/2005}
\draw (\x, 0.1) -- (\x, -0.1) node [below] {\shortstack{\d\\Text}};
\end{tikzpicture}
\end{frame}
\end{document}