3

I'd like my months to be listed as single letters (e.g. J, F, M, A, M, J, J...)

What's the easiest way to do this?

This MWE lists months as MM numbers:

\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}
5

The typesetting of the month is done using the pgf library calendar (pgfcalendar.code.tex). If you add month=shortname, you get a three letter representation of the name of the month. If you want only two letters, you need to write your own code. I did that and called the macro \pgfcalendarmonthshortername. Correspondingly you can now say month=shortername. (Needless to say that Ju is now ambiguous.) I also added an option singleletter that brings the month name down to one letter (and J can mean three months). (Let me add that IMHO this is a nice question and pgfgantt is a well written package.)

\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}

enter image description here

|improve this answer|||||
  • beautiful - that's exactly what I wanted! thank you – Colin Rowat Sep 8 '19 at 16:56
  • 1
    @ColinRowat You're welcome! (Please note that there is no language support in this version, i.e. if one would want to, say, get an Ok for October in the German version, this would require more efforts and/or other packages like xstring. So if someone wants a multilingual version of this, I'd like to encourage them to ask a separate question.) – Schrödinger's cat Sep 8 '19 at 17:08
  • 1
    I experimented a bit myself. It is fairly easy to truncate the macro. However, even without these modifications I could not make any basic examples that uses the translator package run. I also came across this thread. If it is really true that you need to provide all these translations yourself, then it is arguably easier to type in 12 times two letters than doing all the fancy stuff. Truncation of the month name is easy: \def\FirstTwoLetters#1#2#3;{#1#2}%. – Schrödinger's cat Sep 9 '19 at 2:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.