我希望我的月份以单个字母列出(例如 J,F,M,A,M,J,J......)
做到这一点最简单的方法是什么?
此 MWE 将月份列为 MM 数字:
\documentclass[tikz]{standalone}
\usepackage{pgfgantt}
\begin{document}
\begin{ganttchart}[
time slot format=isodate-yearmonth,
time slot unit=month
]{2019-01}{2020-09}
\gantttitlecalendar{year, month=letter} \\
\ganttgroup[]{foo}{2019-07}{2020-03} \\
\ganttgroup[]{bar}{2020-01}{2020-07} \\
\end{ganttchart}
\end{document}
答案1
月份的排版是使用 pgf 库日历 ( pgfcalendar.code.tex
) 完成的。如果添加month=shortname
,您将获得月份名称的三个字母表示。如果只想要两个字母,则需要编写自己的代码。我这样做了,并调用了宏\pgfcalendarmonthshortername
。相应地,您现在可以说month=shortername
。(不用说,这Ju
现在是模棱两可的。)我还添加了一个选项singleletter
,将月份名称缩减为一个字母(J
可以表示三个月)。(让我补充一点,恕我直言,这是一个好问题,也是pgfgantt
一个写得很好的包。)
\documentclass[tikz]{standalone}
\usepackage{pgfgantt}
\makeatletter
\def\pgfcalendarmonthshortername#1{%
\pgfutil@translate{\ifcase#1\or Ja\or Fe\or Ma\or Ap\or
Ma\or Ju\or Ju\or Au\or Se\or Oc\or
No\or De\fi}%
}
\def\pgfcalendarmonthsingleletter#1{%
\pgfutil@translate{\ifcase#1\or J\or F\or M\or A\or
M\or J\or J\or A\or S\or O\or
N\or D\fi}%
}
\makeatother
\begin{document}
\begin{ganttchart}[
time slot format=isodate-yearmonth,
time slot unit=month
]{2019-01}{2020-09}
\gantttitlecalendar{year, month=shortername} \\
\ganttgroup[]{foo}{2019-07}{2020-03} \\
\ganttgroup[]{bar}{2020-01}{2020-07} \\
\end{ganttchart}
\begin{ganttchart}[
time slot format=isodate-yearmonth,
time slot unit=month
]{2019-01}{2020-09}
\gantttitlecalendar{year, month=singleletter} \\
\ganttgroup[]{foo}{2019-07}{2020-03} \\
\ganttgroup[]{bar}{2020-01}{2020-07} \\
\end{ganttchart}
\end{document}