chronosys 不仅仅使用年份

chronosys 不仅仅使用年份

我想生成一条时间线,但它从一年中的某个月份开始,而不仅仅是从一月开始。此外,时间线的结束时间应该可以修改,以便与十二月不同。我喜欢 chronosys 包,但这似乎不可能,因为在编译时它会出错,而当只指定年份时它会正常工作。

对于事件,也可以指定具体日期,但对于时间周期,这些时间周期总是跨越一整年,从 1 月到 12 月,而我只想指定几个月。我该如何实现这一点?

下面是有效代码和非有效代码,以显示我的目标:

\documentclass{beamer}

\usepackage{chronosys}

\begin{document}


% working
\catcode`\@=11
\def\chron@selectmonth#1{\ifcase#1\or January\or February\or
March\or April\or May\or June\or
July\or August\or September\or
October\or November\or December\fi}
\definechronoperiode{Leave}[color=red, textstyle=\it]

\begin{frame}
\frametitle{Time line}
\startchronology[startyear=2010,stopyear=2016]
    \chronoLeave{2011}{2012}{Leave}
    \chronoevent{1/10/2015}{test}
\endchronology
\end{frame}

% what I want -> not working

\begin{frame}
\frametitle{Time line}
\startchronology[startyear=01/10/2010,stopyear=01/10/2016]
    \chronoLeave{10/10/2011}{16/01/2012}{Leave}
    \chronoevent{1/10/2015}{test}
\endchronology
\end{frame}
\end{document}

答案1

chronos 的当前版本可在以下位置获得:
https://tex.stackexchange.com/a/342699/ (2016年12月6日)

这是我发布的代码的增强版本这个答案作为的替代chronosys,因为后者很难修改。

除了上面解释的按键之外,

  • event是一种用于一日活动的风格;
  • event line是用于绘制这些事件的线条的样式;
  • period是一种用于在时间线上绘制表示持续时间的线的样式;
  • period event是一种用于较长活动的方式;
  • period event line是用于绘制这些事件的线条的样式。

提供了两个新命令:

  • \chronosevent [<options for event line>] {<date>} [<options for event node>] {<text>} (<distance of event node from timeline>)
  • \chronosperiod [<options for line marking period on timeline>] [<start date>] [<options for period event line>] {<end date>} [<options for period event node>] {<text>} (<distance of period event node from timeline>)

可选参数允许覆盖特定事件/时期事件的默认样式。

\documentclass[tikz,multi,border=10pt]{standalone}
\usepackage{datenumber,xparse}
\usetikzlibrary{arrows.meta,backgrounds}
\newcounter{chronosstartdate}
\newcounter{chronosenddate}
\newcounter{chronosstartyear}
\newcounter{chronosendyear}
\newcounter{chronosyeardate}
\newcounter{chronosthingdate}
\newcounter{chronosotherthingdate}
\pgfkeys{/pgf/number format,
  int detect,
  set thousands separator={},
}
\tikzset{
  chronos/.code={% https://tex.stackexchange.com/a/159856/ - Claudio Fiandrino
    \tikzset{%
      align=center,
      anchor=mid,
      /chronos/.cd,
      #1
    }%
    \setstartyear{\chronosstartyear}%
    \setmydatenumber{chronosstartdate}{\chronosstartyear}{\chronosstartmonth}{\chronosstartday}%
    \setmydatenumber{chronosenddate}{\chronosendyear}{\chronosendmonth}{\chronosendday}%
    \pgfmathsetmacro\chronosunit{(\chronoswidth-20pt)/(\thechronosenddate-\thechronosstartdate)}%
    \draw [line width=\chronosheight] (-10pt,0) coordinate (chronos pre) -- +(\chronoswidth,0) coordinate (chronos post);
    \coordinate (chronos start) at (0,0);
    \coordinate (chronos end) at ([xshift=-10pt]chronos post);
    \setcounter{chronosstartyear}{\chronosstartyear}%
    \setcounter{chronosendyear}{\chronosendyear}%
    \def\tempa{01}%
    \ifx\chronosstartmonth\tempa
      \ifx\chronosstartday\tempa
        \else\stepcounter{chronosstartyear}%
      \fi
      \else\stepcounter{chronosstartyear}%
    \fi
    \def\tempa{12}%
    \def\tempb{31}%
    \ifx\chronosendmonth\tempa
      \ifx\chronosendday\tempb
        \stepcounter{chronosendyear}%
      \fi
    \fi
    \foreach \i in {\thechronosstartyear,...,\thechronosendyear} {%
      \setmydatenumber{chronosyeardate}{\i}{01}{01}%
      \node [above, anchor=south, yshift=.5*\chronosheight] at ({(\thechronosyeardate-\thechronosstartdate)*\chronosunit pt},0) {\i}; }
  },
  chronos set date/.code args={#1-#2-#3:#4}{%
    \tikzset{%
      /chronos/.cd,
      #4 year={#1},
      #4 month={#2},
      #4 day={#3},
    }%
    \setmydatenumber{chronos#4date}{\csname chronos#4year\endcsname}{\csname chronos#4month\endcsname}{\csname chronos#4day\endcsname}%
  },
  chronos date/.style args={#1-#2-#3}{%
    chronos set date/.expanded={#1-#2-#3:thing}%
  },
  chronos period date/.style args={#1-#2-#3}{%
    chronos set date/.expanded={#1-#2-#3:otherthing}%
  },
  /chronos/.search also={/tikz},
  /chronos/.cd,
  start year/.store in=\chronosstartyear,
  start month/.store in=\chronosstartmonth,
  start day/.store in=\chronosstartday,
  end year/.store in=\chronosendyear,
  end month/.store in=\chronosendmonth,
  end day/.store in=\chronosendday,
  thing year/.store in=\chronosthingyear,
  thing month/.store in=\chronosthingmonth,
  thing day/.store in=\chronosthingday,
  otherthing year/.store in=\chronosotherthingyear,
  otherthing month/.store in=\chronosotherthingmonth,
  otherthing day/.store in=\chronosotherthingday,
  start date/.style args={#1-#2-#3}{%
    start year={#1},
    start month={#2},
    start day={#3},
  },
  end date/.style args={#1-#2-#3}{%
    end year={#1},
    end month={#2},
    end day={#3},
  },
  width/.store in=\chronoswidth,
  height/.store in=\chronosheight,
  period/.style={draw=gray},
  period event line/.style={draw=gray, -{Triangle[width=1.5pt, reversed, length=.75pt, fill=gray]}},
  period event/.style={anchor=north, fill=gray!25, draw=gray, rounded corners, align=center, font=\footnotesize},
  event line/.style={draw=gray, -{Triangle[width=1.5pt, reversed, length=.75pt, fill=gray]}},
  event/.style={anchor=north, fill=gray!25, draw=gray, rounded corners, align=center, font=\footnotesize},
  start date=1001-10-01,
  end date=1003-06-14,
  width=100mm,
  height=1pt,
  chronos date=1850-01-01,
  chronos period date=1851-01-01,
}
\NewDocumentCommand \chronosevent { O {} m O {} +m D () { -10pt-.5*\chronosheight } }
{%
  \scoped[on background layer]{\path [postaction={/chronos/event line, #1}, chronos date/.expanded={#2}] ({(\thechronosthingdate-\thechronosstartdate)*\chronosunit pt},0) -- +(0,#5) node [/chronos/event, #3] {\chronosthingday/\chronosthingmonth/\chronosthingyear\\#4};}
}
\NewDocumentCommand \chronosperiod { O {} m O {} m O {} +m D () { -10pt-.5*\chronosheight } }
{%
  \tikzset{%
    chronos date/.expanded={#2}, chronos period date/.expanded={#4}
  }
  \path [postaction={line width=\chronosheight, /chronos/period, #1}] ({(\thechronosthingdate-\thechronosstartdate)*\chronosunit pt},0) -- ({(\thechronosotherthingdate-\thechronosstartdate)*\chronosunit pt},0);
  \scoped[on background layer]{\path [postaction={/chronos/period event line, #3}] ({(.5*\thechronosotherthingdate+.5*\thechronosthingdate-\thechronosstartdate)*\chronosunit pt},0) -- +(0,#7) node [/chronos/period event, #5] {\chronosthingday/\chronosthingmonth/\chronosthingyear--\chronosotherthingday/\chronosotherthingmonth/\chronosotherthingyear\\#6};}
}
\begin{document}
\begin{tikzpicture}
  [
    chronos={%
      width=120mm,
      height=10pt,
      start date=2010-10-01,
      end date=2016-10-01,
      period/.style={draw=green},
      event line/.append style={draw=blue},
      period event line/.append style={draw=green},
      event/.append style={fill=blue!25, draw=blue, text=blue},
      period event/.append style={fill=green!25, draw=green!75!black, text=green!75!black},
    }
  ]
  \chronosperiod [draw=red] {2011-10-10} [draw=red] {2012-01-16} [fill=red!25, draw=red, text=red] {Leave}
  \chronosperiod {2013-03-23} {2014-05-27} {training}
  \chronosevent {2015-10-01} {test}
\end{tikzpicture}
\end{document}

chronosys 替代品

相关内容