如何使用带有 itemize/enumerate 函数的 tikz 绘制时间线(附加图形示例)

如何使用带有 itemize/enumerate 函数的 tikz 绘制时间线(附加图形示例)

我怎样才能使用 tikz 绘制如下所示的时间线?

在此处输入图片描述

我尝试使用自己的代码,但无法逐项列出/枚举,并且格式看起来很混乱。

\documentclass[a4paper,12 pt]{article}
\usepackage{tikz}
\begin{document}
\begin{figure}
\centering
\begin{tikzpicture}[x=4.5cm]
\draw[black,->,thick,>=latex]
  (0,0) -- (4,0) node[below right] {$\scriptstyle t$};
\foreach \Xc in {0,...,3}
{
  \draw[black,thick] 
    (\Xc,0) -- ++(0,5pt) node[above] {$\scriptstyle \Xc$};
}
\node[below,align=left,anchor=north,inner xsep=0pt,color=black] 
  at (0,0) 
  {Nature determines the state of the economy.};  
\node[below,align=left,anchor=north,inner xsep=0pt] 
  at (1,0) 
  {Trading occurs};  
\node[below,align=left,anchor=north,inner xsep=0pt] 
  at (2,0) 
  {The manager of each firm privately observes its entry cost};  
\node[below,align=left,anchor=north,inner xsep=0pt] 
  at (3,0) 
  {Firms are liquidated.};   
\end{tikzpicture}
\end{figure}
\end{document}

答案1

您的问题的一些要点:

  • \documentclass[tikz, border=5pt]{standalone}让你的tikzpicture更加紧凑。
  • 画箭头:使用\draw [->] (<start point>) -- (<end point>);您可以根据需要更改箭头形状。(我[-stealth]在下面的示例中使用了。)
  • 指定坐标:\coordinate (<name>) at (<x>,<y>);
  • 计算坐标:\coordinate (<point1>) at ($(<point1>)+(<xshift>,<yshift>)$);$...$这里指的是临时计算环境,而不是数学公式。
  • 文本定位:使用[anchor=...]选项。
  • 添加itemize环境:只需将它们放入节点即可:\node [...] at (...) {\begin{itemize} ... \end{itemize}};

这是一个可行的示例,您可以使用foreach语法来改进它。

在此处输入图片描述

\documentclass[tikz, border=5pt]{standalone}

\usepackage{tikz}
\usepackage{lipsum}

\begin{document}
\begin{tikzpicture}
\usetikzlibrary{calc}

% draw arrow
\coordinate (start) at (-4,0);
\coordinate (end) at (26,0);
\draw [line width=2pt, -stealth] (start) -- (end);

% You can use `foreach` to improve the following codes
\coordinate (s0) at (1,0);
\coordinate (t0) at ($(s0)+(0,0.3)$);
\coordinate (s1) at (11,0);
\coordinate (t1) at ($(s1)+(0,0.3)$);
\coordinate (s2) at (21,0);
\coordinate (t2) at ($(s2)+(0,0.3)$);

% draw ticks
\draw [line width=2pt] (s0) -- (t0);
\node [anchor=south] at (t0.north) {$t=0$};

\draw [line width=2pt] (t1) -- (s1);
\node [anchor=south] at (t1.north) {$t=1$};

\draw [line width=2pt] (t2) -- (s2);
\node [anchor=south] at (t2.north) {$t=2$};

% add texts
\node [anchor=north, align=left, text width=9cm] at (s0.south) {
\begin{itemize}
\item \lipsum[1]
\item \lipsum[2]
\end{itemize}
};

\node [anchor=north, align=left, text width=9cm] at (s1.south) {
\begin{itemize}
\item \lipsum[3]
\item \lipsum[4]
\end{itemize}
};

\node [anchor=north, align=left, text width=9cm] at (s2.south) {
\begin{itemize}
\item \lipsum[5]
\item \lipsum[6]
\end{itemize}
};

\end{tikzpicture}
\end{document}

答案2

替代:

  • 使用enumitem节点列表包
  • positioning节点通过使用库来定位
  • 时间线从第一个节点的左上角绘制到最后一个节点的右上角
  • foreach时间事件由循环决定

通过这种方式,文档示例的代码更简单,更干净,更简短。

编辑: 哎呀,现在我发现我忘了添加 mwe :-(。现在它在这里:

\documentclass[a4paper, 12 pt]{article}
\usepackage{tikz}
\usetikzlibrary{positioning}
\usepackage{enumitem}

\begin{document}
    \begin{figure}
    \setlist[itemize]{nosep, leftmargin=*}
\begin{tikzpicture}[
 node distance = 0mm and 0.02\linewidth,
    box/.style = {inner xsep=0pt, outer sep=0pt,
                  text width=0.32\linewidth,
                  align=left, font=\small}
                    ]
\node (n1) [box]
        {   \begin{itemize}
        \item   The shareshoulders design compensation contract for the manager simultaneously.
            \end{itemize}
        };
\node (n2) [box, below right=of n1.north east]
        {   \begin{itemize}
        \item   The manager of each firm privately observes its entry cost;
        \item   The manager make entry decision simultaneously;
        \item   Trading and financial market occurs.
            \end{itemize}
        };
\node (n3) [box, below right=of n2.north east]
        {   \begin{itemize}
        \item   Entry cost and profits are realised;
        \item   Manager receive their compensation;
        \item   Firms are liquidated.
         \end{itemize}
         };
\draw[thick, -latex]    (n1.north west) -- (n3.north east);
\foreach \x [count=\xx from 1] in {0,1,2}
    \draw (n\xx.north) -- + (0,3mm) node[above] {$t=\x$};
\end{tikzpicture}
    \end{figure}
\end{document}

在此处输入图片描述

(红线表示文本边框)

相关内容