如何使用 chronology 包绘制该时间线?

如何使用 chronology 包绘制该时间线?

我想使用chronology包绘制一条从 2011 年到 2016 年的时间线,其中每年应该是一个主刻度,并且每个主刻度之间应该有 3 个小刻度。

我尝试像这样实现它:

\documentclass{article}
\usepackage{chronology}
\begin{document}
\begin{chronology}[3]{2011}{2016}{3ex}{\textwidth}

\end{chronology}
\end{document}

然而,最终的时间线是这样的:

输出

我怎样才能实现我想要的时间表?

答案1

原始chronology环境不允许这样做。下面我定义了一个markschronology环境,其行为方式与chronology(它具有相同的参数,并且它是按照原始定义定义的)类似,并允许您指定中间刻度数;中间刻度数由\Marks默认值控制0(即没有中间刻度):

\documentclass{article}
\usepackage{chronology}

\def\Marks{0}

\makeatletter
\def\@marks{}
\newenvironment{markschronology}
  {%
    \@ifstar{\chronology@startrue\markschronology@i*}  {\chronology@starfalse\markschronology@i*}%
  }
  {%
    \end{tikzpicture}%
    \end{lrbox}%
    \raisebox{2ex}{%
      \resizebox{\timelinewidth}{!}{\usebox{\timelinebox}}%
    }%
  }

\def\markschronology@i*{%
    \@ifnextchar[{\markschronology@ii*}{\markschronology@ii*[{5}]}%
}

\def\markschronology@ii*[#1]#2#3#4{%
    \@ifnextchar[{\markschronology@iii*[{#1}]{#2}{#3}{#4}}{\markschronology@iii*[{#1}]{#2}{#3}{#4}[{#4}]}%
}

\def\markschronology@iii*[#1]#2#3#4[#5]{%
  \newif\ifflipped%
  \ifchronology@star%
    \flippedtrue%
  \else%
    \flippedfalse%
  \fi%
  \setcounter{step}{#1}%
  \setcounter{yearstart}{#2}\setcounter{yearstop}{#3}%
  \setcounter{deltayears}{\theyearstop-\theyearstart}%
  \setlength{\unit}{#5/\thedeltayears}%
  \setlength{\timelinewidth}{#4}%
  \pgfmathsetcounter{stepstart}{\theyearstart+\thestep-mod(\theyearstart,\thestep)}%
  \pgfmathsetcounter{stepstop}{\theyearstop-mod(\theyearstop,\thestep)}%
  \addtocounter{step}{\thestepstart}%
  \begin{lrbox}{\timelinebox}%
  \begin{tikzpicture}[baseline={(current bounding box.north)}]%
    \draw [|->] (0,0) -- (\thedeltayears*\unit+\unit, 0);%
    \foreach \x in {1,...,\thedeltayears}
    {
      \draw[xshift=\x*\unit] (0,-0.1\unit) -- (0,0.1\unit);%
    }
    \pgfmathsetmacro{\@marks}{1+(1/(\Marks+1))}
    \foreach \x in {1,\@marks,...,\thedeltayears}
    {
      \draw[xshift=\x*\unit] (0,-0.05\unit) -- (0,0.05\unit);%
    }
    \addtocounter{deltayears}{1}%
    \foreach \x in {\thestepstart,\thestep,...,\thestepstop}
    {%
      \pgfmathsetlength\xstop{(\x-\theyearstart)*\unit}%
      \ifflipped%
        \node at (\xstop,0) [above=.2\unit] {\x};%
      \else%
        \node at (\xstop,0) [below=.2\unit] {\x};%
      \fi%
    }%
}
\makeatother

\begin{document}

\noindent\begin{markschronology}[1]{2010}{2016}{\textwidth}
\end{markschronology}\par\bigskip

\def\Marks{3}
\noindent\begin{markschronology}[1]{2010}{2016}{\textwidth}
\end{markschronology}\par\bigskip

\def\Marks{5}
\noindent\begin{markschronology}[1]{2010}{2016}{\textwidth}
\end{markschronology}

\end{document}

在此处输入图片描述

相关内容