# tikzcalendar days name and anchors

I'm using tikzcalendar and I'd like to:

1. insert name of days on top (maybe abbreviated Mon, Tue, Wed, and so on)
2. automatically insert dashed vertical lines to separate the weekend days.

In the following MWE I had some progress on (2), but it is not good since I have to inform when the first Friday of calendar occurs and use that node as reference.

When date changes, I have to edit the code again.

MWE

\documentclass[12pt]{report}
\usepackage[a4paper,landscape,margin=1cm]{geometry}
\usepackage{tikz}
\usetikzlibrary{calendar,calc}

\begin{document}\centering
\begin{tikzpicture}[%
every day/.style={anchor=mid,opacity=1,minimum width=2.5ex},%
every node/.style={inner sep=2pt,rectangle}%
]
\calendar (cal) [dates=2018-06-01 to 2018-12-10,
month list,%
month label left,%
month text=\textcolor{black}{\%mt},%
month yshift=1.7em,%
day xshift=3.5ex,%
]
if (Sunday) [every day/.append style={font=\slshape},red]
;
%%
%% we need to use 1st Friday node to compute the (up) node
%%
\node (up) at ($(cal-2018-06-01.north east)!.5!(cal-2018-06-02.north west)$ ) {};
%%
%% we need to use last month 1st Friday node to compute the (down) node
%%
\node (down) at (%
%% repeat (up) node
{$(cal-2018-06-01.north east)!.5!(cal-2018-06-02.north west)$}%
|-%
{$(cal-2018-12-01.south east)!.5!(cal-2018-12-02.south west)$}%
) {};
%%
%% dashed lines from (up) to (down)
%%
\foreach \i in {0,...,4}{% <-- the number could change
\draw[dashed]%
([xshift=3.5*7*\i ex]up.center)--([xshift=3.5*7*\i ex]down.center)
([xshift=3.5*7*\i ex + 7ex]up.center)--([xshift=3.5*7*\i ex + 7ex]down.center)
;
}
\end{tikzpicture}
\end{document}


• added parameters \dateFrom, \dateTo, \xDist
• added function \dayOfWeek, which does a modulo calculation and selects the day of the week
• used new parameters everywhere
• define coordinate for (up) and (down)

Comment:

Because the week starts always with a monday and there is even left space if there is no monday at the begin of any selected month, there is the magic number 4.5 for getting the x-position of the first friday. If you start with another day this value must be changed.

Code:

\documentclass[12pt]{report}
\usepackage[a4paper,landscape,margin=1cm]{geometry}
\usepackage{tikz}
\usetikzlibrary{calendar,calc}

\usepackage{ifthen}
\usepackage[nomessages]{fp}% http://ctan.org/pkg/fp

\newcommand{\dayOfWeek}[1]{%
% give back day of week (here in german)
% calc #1 modulo 7
\FPeval{\result}{trunc(#1-(7*trunc(#1/7,0)),0)}
\ifthenelse{\equal{\result}{0}}{
Mo
}{\ifthenelse{\equal{\result}{1}}{
Di
}{\ifthenelse{\equal{\result}{2}}{
Mi
}{\ifthenelse{\equal{\result}{3}}{
Do
}{\ifthenelse{\equal{\result}{4}}{
Fr
}{\ifthenelse{\equal{\result}{5}}{
Sa
}{\ifthenelse{\equal{\result}{6}}{
So
}{}}}}}}}
}

% Parameters %%%%%%%%%%%%%%%%%%%%%%%%%%%
\newcommand{\dateFrom}{2018-06-01}
\newcommand{\dateTo}{2018-12-10}
\newcommand{\xDist}{3.5ex}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\begin{document}
\centering
\begin{tikzpicture}[%
every day/.style={anchor=mid,opacity=1,minimum width=2.5ex},%
every node/.style={inner sep=2pt,rectangle}%
]

\calendar (cal) [
dates=\dateFrom to \dateTo,
month list,%
month label left,%
month text=\textcolor{black}{\%mt},%
month yshift=1.7em,%
day xshift=\xDist,%
]
if (Sunday) [every day/.append style={font=\slshape},red];

% Friday is on a fix position (4), because week starts always with monday.
% Therefore 4.5 for line between friday and saturday.
\coordinate (up) at (4.5*\xDist,0 |- cal-\dateFrom.north);
\coordinate (down) at (4.5*\xDist,0 |- cal-\dateTo.south);

% dashed lines from (up) to (down)
\foreach \i in {0,...,4}{% <-- the number could change
\draw[dashed]%
([xshift=7*\i*\xDist]up.center)--([xshift=7*\i*\xDist]down.center)
([xshift=7*\i*\xDist + 2*\xDist]up.center)--([xshift=7*\i*\xDist + 2*\xDist]down.center);
}

% write day of week above:  A month starting with sunday (day 6) and
% having 31 days would have the maximum x-position 6+31=37.
% Therefore the range goes from 0 to 36.
\foreach \i in {0,...,36}{
\node[] at (\i*\xDist,0 |- cal-\dateFrom.north) [above=2mm]{\dayOfWeek{\i}};
}
\end{tikzpicture}

\end{document}


Result:

• Thanks for your effort. So, the range for \foreach (in your example, 0,...,36) should be changed manually? From where comes the mysterious value 36? – Sigur Dec 10 '18 at 18:22
• I tested a lot and it seems that it is automatically adapted. – Sigur Dec 10 '18 at 18:35
• 36 is the maximum of a month starting with sunday (day 6) and having 31 days: 6+31=37. Because for starts with 0 it is 36. Yes, it has to be adapted manually at the moment. – dexteritas Dec 10 '18 at 18:57
• But I think it is perfect since all cals I use have Mon as 1st day. – Sigur Dec 10 '18 at 21:13
• In most cases, if you have multiple months nothing has to be changed. Only if you have for example just months from 2018-10-01 to 2018-11-30, you could change the 36 to 32. To automate that, one could iterate over the last day of each month and look at the maximum x-position. – dexteritas Dec 11 '18 at 9:52