我正在尝试创建一个时间线,显示某项政策在某些州实施的时间。我是 tikzpicture 的新手。我的样本期是 2000 - 2023 年。政策处理从 2003 - 2016 年开始,采用交错处理。有没有办法让年份位于线上方,并且在交错政策处理期间将线的颜色更改为蓝色?
我生成的代码将所有内容都放在了该线以下。
\begin{frame}
\begin{figure}
\begin{tikzpicture}[x=1.5cm,nodes={text width=1.0cm,align=left}]
\draw[black,->,thick,>=latex,line cap=rect]
(0,0) -- (10,0);
\foreach \Text [count=\Xc starting from 0] in
{{2000.},%
{2001.},%
{2002.},%
{2003. Louisiana. Vermont. Arkansas.},%
{2004. Nebraska.},
{2006. Ohio},
{2007. New Hampshire.},
{2008. Michigan.},
{2010. New York.},
{2012. Florida.},
{2015. New Mexico.},
{2016. Colorado.},
{2018.},
{2019.},
{2021.}}
{\fill (\Xc,0) circle[radius=1.5pt];
\node[below=0.2ex] at (\Xc,0) {\Text};}
\end{tikzpicture}
\end{figure}
\end{frame}
答案1
您可以将列表拆分为年份部分和文本部分:
\documentclass{beamer}
\usepackage{tikz}
\begin{document}
\begin{frame}
\begin{figure}
\begin{tikzpicture}[x=1.5cm,nodes={text width=1.0cm,align=left},scale=0.45,transform shape]
\draw[black,->,thick,>=latex,line cap=rect]
(0,0) -- (15,0);
\draw[blue,ultra thick,>=latex,line cap=rect]
(3,0) -- (11,0);
\foreach \yr/\Text [count=\Xc starting from 0] in
{{2000/},%
{2001/},%
{2002/},%
{2003/Louisiana Vermont Arkansas},%
{2004/Nebraska},
{2006/Ohio},
{2007/New Hampshire},
{2008/Michigan},
{2010/New York},
{2012/Florida},
{2015/New Mexico},
{2016/Colorado},
{2018/},
{2019/},
{2021/}}
{
\fill (\Xc,0) circle[radius=1.5pt];
\node[above=0.2ex] at (\Xc,0) {\yr};
\node[below=0.2ex,text width=1cm,align=center] at (\Xc,0) {\Text};
}
\end{tikzpicture}
\end{figure}
\end{frame}
\end{document}