tikz를 사용한 더 나은 타임라인 그림

tikz를 사용한 더 나은 타임라인 그림

아래 손으로 그린 ​​그림과 최대한 가까운 그림을 그리고 싶습니다.

여기에 이미지 설명을 입력하세요

나는 다음을 시도했습니다.

\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   Households can produce or consume $x$ with equal probability
                    \item Young entrepreneurs borrow bank deposits to buy $x$ for investment
                    \item Young bankers issue deposits and loans
                \end{itemize}
            };
            \node (n2) [box, below right=of n1.north east]
            {   \begin{itemize}
                    \item  $\frac{1}{4}$ probability of type $l$ consumers
                    \item  $\frac{1}{4}$ probability of type $h$ consumers
                    \item  $\frac{1}{2}$ probability of producers
                \end{itemize}
            };
            \node (n3) [box, below right=of n2.north east]
            {   \begin{itemize}
                    \item   Old entrepreneurs get output, repay loans, consume $x$ and die
                    \item   Old bankers receive loan repayments, consume $x$ and die
                \end{itemize}
            };
            \draw[thick, -latex]    (n1.north west) -- (n3.north east);
            \draw (n1.north) -- + (0,3mm) node[above] {Day};
            \draw (n2.north) -- + (0,3mm) node[above] {Night};
            \draw (n3.north) -- + (0,3mm) node[above] {Day};
        \end{tikzpicture}
      \end{figure}
    \end{document}

위의 코드는 다음 그림을 생성합니다. 여기에 이미지 설명을 입력하세요

이것은 내가 원하는 것과 다릅니다. $t$ 및 $t+1$을 포함하고 눈금 표시가 선을 통과하도록 하여 그것이 의미가 있다면 선 중앙에 표시되도록 하고 싶습니다. 또한 손으로 그린 ​​그림에 나타나는 것처럼 선 위에 텍스트 덩어리를 가져오는 것이 더 나을 것입니다.

답변1

다음은 목록의 각 요소에 대해 네 가지 값 , , 을 \tikztimeline모두 설정하거나 전혀 설정할 수 없는 항목 목록을 예상하는 PGFKeys 기반 접근 방식입니다 .topabovebelowbottom

\tikztimelineset전역 규모에서 기본값을 조정하는 데 사용 하거나 선택적 인수를 사용하여 \tikztimeline하나의 다이어그램에 대해서만 값을 설정할 수 있습니다.

길이 segment widthtick length조정이 가능합니다.

segment width× 항목이 페이지에 비해 너무 길지 않은지 확인해야 합니다 .

암호

\documentclass[a4paper, 12pt]{article}
\usepackage{tikz}
\usetikzlibrary{arrows.meta}
\newcommand*\tikztimelineset{\pgfqkeys{/tikz/timeline}}
\tikztimelineset{
  segment width/.initial=4cm, tick length/.initial=6pt,
  topbot/.style={
    align=flush left,
    text width=\pgfkeysvalueof{/tikz/timeline/segment width}
           -2*(\pgfkeysvalueof{/pgf/inner xsep})},
  top/.initial=, above/.initial=, below/.initial=, bottom/.initial=}
\newcommand*\tikztimeline[2][]{
\begin{tikzpicture}[timeline/every timeline/.try,timeline/.cd,#1]
\foreach[count=\CNT] \elem in {#2}{
  \tikztimelineset{/tikz/style/.expand once=\elem}
  \tikzset{xshift=\CNT*(\pgfkeysvalueof{/tikz/timeline/segment width})}
  \unless\ifnum\CNT=1\relax
  \draw (down:\pgfkeysvalueof{/tikz/timeline/tick length}) -- coordinate (lasttick)
        (  up:\pgfkeysvalueof{/tikz/timeline/tick length});
  \fi
  \node[above] (@above) at (right:{.5*(\pgfkeysvalueof{/tikz/timeline/segment width})})
    {\strut$\pgfkeysvalueof{/tikz/timeline/above}$};
  \node[above, timeline/topbot] at (@above.north) {\pgfkeysvalueof{/tikz/timeline/top}};
  \node[below] (@below) at (@above.south) {\strut\pgfkeysvalueof{/tikz/timeline/below}};
  \node[below, timeline/topbot] at (@below.south) {\pgfkeysvalueof{/tikz/timeline/bottom}};
}
\draw[->] (right:\pgfkeysvalueof{/tikz/timeline/segment width})
      -- ([xshift=\pgfkeysvalueof{/tikz/timeline/segment width}] lasttick);
\end{tikzpicture}}

\tikztimelineset{every timeline/.append style={>=Latex}}

\begin{document}
\tikztimeline{
  {
    top=Households can produce or consume $x$ with equal probabilit.,
    above=t,
    below=Day,
    bottom=Young entrepreneurs borrow bank deposits to buy $x$ for investment.\\
           Young bankers issue deposits and loans.
  }, {
    top=$\frac{1}{4}$ probability of type $l$ consumers.
        $\frac{1}{4}$ probability of type $h$ consumers.
        $\frac{1}{2}$ probability of producers.,
    below=Night
  }, {
    above=t+1,
    below=Day,
    bottom={Old entrepreneurs get output, repay loans, consume $x$ and die.\\
            Old bankers receive loan repayments, consume $x$ and die.}
  }}
\end{document}

산출

여기에 이미지 설명을 입력하세요

관련 정보