I'm programming a Calendar in TikZ and I'm running into a problem while trying to display vacations. In the code below, the loop is what I'm trying to do, because it's more dynamic and I don't have to hard code it inside the actual \calendar[]
function. The commented out code works well. All the days that are between the dates are grayed out. With the loop, nothing happens. There is no error message (which is good I think), but there is also no grayed out cell, which is bad...
Why doesn't this work and how could I get it working?
Calendar
\documentclass[landscape, a4paper, ngerman, 10pt]{article}
\usepackage[utf8]{inputenc}
\usepackage[ngerman]{babel}
\usepackage[T1]{fontenc}
\usepackage{tikz, xparse}
\usepackage{lmodern}
\usepackage{translator} % German Month and Day names
\usepackage{fancyhdr} % header and footer
\usepackage{color} % Colors
\usepackage[
headheight = 11ex,
margin=.5cm,
top = 3.2cm,
nofoot,
]{geometry}
\usetikzlibrary{calc, calendar}
\renewcommand*\familydefault{\sfdefault}
% -------------------------------------------------------
%
% User defined
%
% -------------------------------------------------------
% Input the variables.tex
% Defines the user variables
\input{variables}
% Header
\renewcommand{\headrulewidth}{0pt}
\fancyhf{}
\lhead{%
\fontsize{60}{70}\selectfont\bfseries{%
SS \currentyear
}
}
% -------------------------------------------------------
%
% Calendar
%
% -------------------------------------------------------
\begin{document}
\pagestyle{fancy}
\centering
% -------------------------------------------------------
%
% Summersemester
% April to September
%
% -------------------------------------------------------
\begin{tikzpicture}[every day/.style={anchor = north}]
\calendar[
dates = \currentyear-04-01 to \currentyear-09-30,
name = cal,
day yshift = 3em,
day code = {
\node[name = \pgfcalendarsuggestedname, every day, minimum height = .53cm, text width = 4.4cm, draw = gray] {\tikzdaytext};
\draw (-1.8cm, -.1ex) node [anchor = west, font=\footnotesize] {\pgfcalendarweekdayshortname{\pgfcalendarcurrentweekday}};
},
execute before day scope={
\ifdate{day of month = 1} {
\pgftransformxshift{4.8cm}
\draw (0,0) node [minimum height = .53cm, text width = 4.4cm, fill = definedcolor, text = white, draw = definedcolor, text centered] {\textbf{\pgfcalendarmonthname{\pgfcalendarcurrentmonth}\strut}};
}{}
\ifdate{workday} {
\tikzset{every day/.style = {fill = white}}
\foreach \vacationBegin/\vacationEnd in \vacations {
\ifdate{between = \vacationBegin and \vacationEnd}{%
\tikzset{every day/.style = {fill = gray!30}}%
}{}
}
% \ifdate{between = \sommerbegin and \sommerend}{%
% \tikzset{every day/.style = {fill = gray!30}}%
% }{}
% \ifdate{between = \pfingstenbegin and \pfingstenend}{%
% \tikzset{every day/.style = {fill = gray!30}}%
% }{}
% \ifdate{between = \winterbegin and \winterend}{%
% \tikzset{every day/.style = {fill = gray!30}}%
% }{}
}{}
\ifdate{Saturday} {
\tikzset{every day/.style = {fill = definedcolor!10}}%
}{}
\ifdate{Sunday} {
\tikzset{every day/.style = {fill = definedcolor!20}}%
}{}
},
execute at begin day scope = {
\pgftransformyshift{-.53*\pgfcalendarcurrentday cm}
}
];
\end{tikzpicture}
\end{document}
Variables
\newcommand*\vacations{%
\currentyear-02-10/\currentyear-04-18,%
\currentyear-07-28/\currentyear-10-02,%
\currentyear-06-05/\currentyear-06-10
}
% Semester break (Winter)
% \newcommand*\winterbegin{\currentyear-02-10}
% \newcommand*\winterend{\currentyear-04-18}
% Semester break (Summer)
% \newcommand*\summerbegin{\currentyear-07-28}
% \newcommand*\summerend{\currentyear-10-02}
% Pentecost vacation
% \newcommand*\pentecostbegin{\currentyear-06-05}
% \newcommand*\pentecostend{\currentyear-06-10}
Oh and while I'm here: Is there a possibility to also write the name of the vacation inside the cell?
So that my array would look like this:
\newcommand*\vacations{%
\currentyear-02-10/\currentyear-04-18/{Winter},%
\currentyear-07-28/\currentyear-10-02/{Summer},%
\currentyear-06-05/\currentyear-06-10/{Pentecost}%
}
\documentclass
and ending with\end{document}
, making sure to include only the relevant packages so it is compilable, yet minimal.\foreach
? In that case,\foreach
is quite fragile and will crash if there are\def
or\edef
inside.\calendar[];
I can use the same\foreach
with another\newcommand
"array" to input some events.\foreach \subject/\eventdate in \events {\event{\eventdate}{\subject}}
where\event{}{}
is defined as\newcommand*\event[2]{\node [ anchor = north west, text width = 3.4cm, font = \bfseries ] at ($(cal-#1.north west)+(3em, -0.2em)$) {\scriptsize{#2}};}