The calendar
TikZ library creates for each day a node called (<name>-<year>-<month>-<day>)
. But there is a leading zero for <day>
from 1
to 9
, that is, to use the node of the first day we have to refer to it by (<name>-<year>-<month>-01)
.
Since I'm trying to connect some nodes using a \foreach
loop, I'm having trouble with the leading zero. For example,
! Package pgf Error: No shape named cal-2015-01-2 is known.
! Package pgf Error: No shape named cal-2015-09-4 is known.
But if I insert the leading zero (cal-2015-09-0\x.north east)
the error changes to
! Package pgf Error: No shape named cal-2015-01-016 is known.
So, I think that working with integer numbers with exactly two digits could solve the problem.
I'd like to have the same two dashed lines as in the 1st calendar below, but translated to separate the other weekends.
MWE
\documentclass[11pt]{report}
\usepackage[margin=1cm,landscape,a4paper]{geometry}
\usepackage{tikz}
\usetikzlibrary{calendar,calc,math}
\begin{document}
\begin{tikzpicture}%
[every day/.style={anchor=mid},
every node/.style={inner sep=2pt,rectangle,thick}
]
\calendar (cal)%
[dates=\the\year-1-1 to \the\year-12-last,
month list,
month label left,
month text=\textcolor{black}{\%mt},
month yshift=1.7em,
black
]
if (Saturday) [blue]
if (Sunday) [red]
;
\draw[dashed]
( $(cal-\the\year-01-02.north east)!.5!(cal-\the\year-01-03.north west)$ ) --
( $(cal-\the\year-12-04.south east)!.5!(cal-\the\year-12-05.south west)$ )
%%
( $(cal-\the\year-01-04.north east)!.5!(cal-\the\year-01-05.north west)$ ) --
( $(cal-\the\year-12-06.south east)!.5!(cal-\the\year-12-07.south west)$ )
;
\end{tikzpicture}
\vfill\noindent\hrulefill\vfill
\begin{tikzpicture}%
[every day/.style={anchor=mid},
every node/.style={inner sep=2pt,rectangle,thick}
]
\calendar (cal)%
[dates=\the\year-1-1 to \the\year-12-last,
month list,
month label left,
month text=\textcolor{black}{\%mt},
month yshift=1.7em,
black
]
if (Saturday) [blue]
if (Sunday) [red]
;
%% use only one foreach below
%% the first has problems with leading zeros on day numbers
%%
\foreach \i in {0,7,...,31}{% should be tested if is >31
%\foreach \i in {16,23,...,31}{% should be tested if is >31
%%
%% January 02 and 04 are starting days
\tikzmath{integer \xaa; \xaa = 2+\i;}
\tikzmath{integer \xab; \xab = \xaa+1;}
\tikzmath{integer \xba; \xba = 4+\i;}
\tikzmath{integer \xbb; \xbb = \xba+1;}
%% December 04 and 06 are ending days
\tikzmath{integer \yaa; \yaa = 4+\i;}
\tikzmath{integer \yab; \yab = \yaa+1;}
\tikzmath{integer \yba; \yba = 6+\i;}
\tikzmath{integer \ybb; \ybb = \yba+1;}
\draw[dashed]
( $(cal-\the\year-01-\xaa.north east)!.5!(cal-\the\year-01-\xab.north west)$ ) --
( $(cal-\the\year-12-\xba.south east)!.5!(cal-\the\year-12-\xbb.south west)$ )
%%
( $(cal-\the\year-01-\yaa.north east)!.5!(cal-\the\year-01-\yab.north west)$ ) --
( $(cal-\the\year-12-\yba.south east)!.5!(cal-\the\year-12-\ybb.south west)$ )
;
}
\end{tikzpicture}
\end{document}