I'm putting together a multi-month calendar in TikZ and am seeing some awkward and undesired alignment in the month labels despite using the month label above centered
style. In particular, the month label appears to be centered only over the first six columns, rather than over all seven:
I've reproduced my code below in a minimal context. Two questions: What's going on here, and how can I correct this alignment?
\documentclass[letterpaper]{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usetikzlibrary{calendar,shapes}
\makeatletter%
\tikzstyle{week list sunday}=[
% Note that we cannot extend from week list,
% the execute before day scope is cumulative
execute before day scope={%
\ifdate{day of month=1}{\ifdate{equals=\pgfcalendarbeginiso}{}{
% On first of month, except when first date in calendar.
\pgfmathsetlength{\pgf@y}{\tikz@lib@cal@month@yshift}%
\pgftransformyshift{-\pgf@y}
}}{}%
},
execute at begin day scope={%
% Because for TikZ Monday is 0 and Sunday is 6,
% we can't directly use \pgfcalendarcurrentweekday,
% but instead we define \c@pgf@counta (basically) as:
% (\pgfcalendarcurrentweekday + 1) % 7
\pgfmathsetlength\pgf@x{\tikz@lib@cal@xshift}%
\ifnum\pgfcalendarcurrentweekday=6
\c@pgf@counta=0
\else
\c@pgf@counta=\pgfcalendarcurrentweekday
\advance\c@pgf@counta by 1
\fi
\pgf@x=\c@pgf@counta\pgf@x
% Shift to the right position for the day.
\pgftransformxshift{\pgf@x}
},
execute after day scope={
% Week is done, shift to the next line.
\ifdate{Saturday}{
% But not if it's already the last day of the month.
\ifdate{end of month=1}{}{
\pgfmathsetlength{\pgf@y}{\tikz@lib@cal@yshift}%
\pgftransformyshift{-\pgf@y}
}%
}{}%
},
% This should be defined, glancing from the source code.
tikz@lib@cal@width=7
]
\tikzoption{day headings}{\tikzstyle{day heading}=[#1]}
\tikzstyle{every calendar}=[week list sunday,
month label above centered,
month text=\textbf{\%mt~\%y-},
day xshift = 0.5cm,
day letter headings]
\tikzstyle{every day}=[anchor=base]
\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/S,1/M,2/T,3/W,4/T,5/F,6/S} {
\pgf@xa=\d\pgf@xa%
\pgftransformxshift{\pgf@xa}%
\pgftransformyshift{\pgf@ya}%
\node[every day,day heading]{\l};%
}
}{}%
}%
]
\makeatother%
% ==================================================
\begin{document}
\begin{tikzpicture}
\calendar (K) [dates=2013-01-01 to 2013-03-last]
if (weekend) [black!40];
\draw[black](K-2013-01-21) circle (0.6em);
\draw[black](K-2013-02-13) circle (0.6em);
\draw[black](K-2013-03-10) circle (0.6em);
\draw[black](K-2013-03-31) circle (0.6em);
\end{tikzpicture}
\end{document}