1

I'm attempting to make a calendar which shows one month per column and each month is a day list downward. I could only do this so far by creating one calendar for each month and using xshift to manually position them as I'd like. Perhaps there's a better way to achieve this by using execute before day scope but I don't know how to do that.

Any hints?

Here's my current implementation:

\documentclass[margin=2mm, crop]{standalone}

\usepackage{tikz}
\usetikzlibrary{calendar}

\begin{document}
\begin{tikzpicture}
  \calendar
      [
        dates=2022-10-01 to 2022-10-31,
        name=oct,
        day list downward,
        month label above left,
      ]
      if (weekend) [gray];

  \calendar
      [
        dates=2022-11-01 to 2022-11-30,
        name=nov,
        day list downward,
        month yshift=1em,
        month label above left,
        xshift=5cm,
      ]
      if (weekend) [gray];

  \calendar
      [
        dates=2022-12-01 to 2022-12-31,
        name=dec,
        day list downward,
        month label above left,
        xshift=10cm,
      ]
      if (weekend) [gray];

  \calendar
      [
        dates=2023-01-01 to 2023-01-31,
        name=jan,
        day list downward,
        month label above left,
        xshift=15cm,
      ]
      if (weekend) [gray];
\end{tikzpicture}
\end{document}

And what it looks like:

sample

PS: the long xshift is because I will add annotations to the days by referencing the specific nodes in the calendar. Something like:

\node [anchor=base west] at (cal-2022-01-01.base east) {Foo};
2
  • For some ideas to maybe automatically add info text to the dates: 1, 2 and possibly more. Jan 9 at 12:48
  • You could also put each month in its own \matrix column. Has its own advantages and disadvantages. Jan 9 at 14:43

1 Answer 1

0

The day list downward continually shifts the coordinate system down, to get back up to the top you'd need to shift the coordinate system back to the top (which could be done mathematically which needs the code to figure out what the last day of a month is or by using a coordinate at the top).

I believe, it is easier to implement our own day list downward months horizontal style where the day-to-day-shifting is done locally for every day (and not globally as the day list downward style does. For every first of a month the month xshift (stored in \tikz@lib@cal@month@xshift) length is shifted to the right – but not for the very first month of the calendar which is only noticeable if you have more than just the calendar in your picture.

For the day-to-day-shifting (day yshift will be stored in \tikz@lib@cal@yshift) we need to subtract 1 from the day of the month (or adjust the month label above left style). The code

\if0\pgfcalendarcurrentday\else\pgfcalendarcurrentday\fi

gobbles the leading 0 in \pgfcalendarcurrentday (011, 022, …, 1010, etc.) so that it can be used in PGFMath. (Leading zeros are interpreted as octal numbers.)

Code

\documentclass[margin=2mm, tikz]{standalone}
\usetikzlibrary{calendar}
\makeatletter
\tikzset{
  day list downward months horizontal/.style={
    tikz@lib@cal@width=1,
    execute at begin day scope={
      \pgftransformyshift{
        -(\if0\pgfcalendarcurrentday\else\pgfcalendarcurrentday\fi - 1)
        *(\tikz@lib@cal@yshift)}
    },
    execute before day scope={
      \ifdate{day of month=1}{
        \ifdate{equals=\pgfcalendarbeginiso}{}{
          \pgftransformxshift{\tikz@lib@cal@month@xshift}
        }
      }{}
    }
  }
}
\makeatother
\begin{document}
\begin{tikzpicture}
  \calendar[
        dates=2022-10-01 to 2023-01-31,
        day list downward months horizontal,
        month label above left,
        month xshift=5cm,
        month text={\%mt \%y0}
      ]
      if (weekend) [gray];
\end{tikzpicture}
\end{document}

Output

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .