12

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?

15

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

  • 1
    BTW: A slash is missing between \d and \l (it should be \foreach \d/\l in {0/M,1/T,2/W,3/T,4/F,5/S,6/S} {, otherwise, I get an error message). – diabonas Feb 4 '11 at 12:39
  • 1
    @diabonas Thanks! I've added the missing slash. Interestingly, it worked fine without it for me, although according to the manual it shouldn't. Maybe something changed in recent versions of pgf. – Jake Feb 4 '11 at 12:59

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.