[Tex/LaTex] Weekday captions with the TikZ library “calendar”

calendartikz-pgf

I use the TikZ library calendar to produce a week list. The code looks like this:

\documentclass{article}

\usepackage{pgf,tikz}
\usetikzlibrary{calendar}

\begin{document}
    \tikz\calendar[dates=2011-02-01 to 2011-02-last,week list];
\end{document}

However, I want to add abbreviated captions for the weekdays (M, T, W, …) in the first line of the week list:

 M  T  W  T  F  S  S
    1  2  3  4  5  6
 7  8  9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28

I couldn't find any option to the \calendar macro which produces this effect. Is there any other solution to achieve my goal?

Best Answer

There's no way of doing this with a single option, but the following code is a way of getting the weekday headings in a way that keeps all options of the week list calendar. It adds the style day letter headings (which in this form only makes sense to use with the week list style). The style of the headings can be set with the option day headings.

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{calendar}

\makeatletter%
\tikzoption{day headings}{\tikzstyle{day heading}=[#1]}
\tikzstyle{day heading}=[]
\tikzstyle{day letter headings}=[
    execute before day scope={ \ifdate{day of month=1}{%
      \pgfmathsetlength{\pgf@ya}{\tikz@lib@cal@yshift}%
      \pgfmathsetlength\pgf@xa{\tikz@lib@cal@xshift}%
      \pgftransformyshift{-\pgf@ya}
      \foreach \d/\l in {0/M,1/T,2/W,3/T,4/F,5/S,6/S} {
        \pgf@xa=\d\pgf@xa%
        \pgftransformxshift{\pgf@xa}%
        \pgftransformyshift{\pgf@ya}%
        \node[every day,day heading]{\l};%
      } 
    }{}%
  }%
]

\makeatother%

\begin{document}
    \tikz\calendar[dates=2011-02-01 to 2011-04-last,
        week list,
        month label above centered,
        day xshift = 0.8cm,
        day headings=orange,
        day letter headings
    ];
\end{document}

Week list calendar with single letter day headings