# TikZ Calendar - dashes in empty day nodes

I have modified code given by cfr in the answer to this question about current day nodes.

I want to fill in "blank" days with dashes in the first and last rows of my calendar. The first two months from the example code should look like this:

August
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
29  30  31  --  --  --  --

September
--  --  --   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  29  30  --  --


I think there is probably a straight forward way to accomplish this. [Or at least that I should be able to use the day of the week that the first and last of the month fall on to figure out what extra nodes I need,but I have no idea how to even start something like that.] Any suggestions?

\documentclass[border=10pt,multi,tikz]{standalone}
\usetikzlibrary{calendar}
\begin{document}
\begin{tikzpicture}
\calendar (cal)
[%
week list,
dates=2016-08-01 to 2016-10-last,
day xshift=1.5em,
month xshift=1pt,
month label above left,
]
if (weekend) [text=black!25]
[%
execute at end day scope={%
\draw[red]
(cal-\%y0-\%m0-\%d0.north east) --
(cal-\%y0-\%m0-\%d0.south east);
}][%
execute at end day scope={%
\draw[green]
(cal-\%y0-\%m0-\%d0.south east) --
(cal-\%y0-\%m0-\%d0.south west);
}];
\end{tikzpicture}
\end{document}


[Note: This is one of two questions about modifying the same code. The other is here.]

Here you go. This is pretty simple -- I add code that executes on the first and last days of the month to add the dashes. To add the dashes, I have a \foreach loop that iterate from Monday to the day before the current day adding dashes in each day. This doesn't add dashes for partial months, if you want me to update it to do that I can.

\documentclass[border=10pt,multi,tikz]{standalone}
\usetikzlibrary{calendar}
\makeatletter
% #1 -- an integer 0-6 representing the day of the week
% This helper macro shifts the position to the appropriate place to insert a node on the given weekday
\newcommand\dayshift[1]{%
\pgfmathsetlength\pgf@x{\tikz@lib@cal@xshift}%
\pgf@x = #1 \pgf@x
\pgftransformxshift {\pgf@x }%
}
\makeatother
\begin{document}
\newcount\tempcount
\begin{tikzpicture}
\calendar (cal)
[%
week list,
dates=2016-08-01 to 2016-11-3,
day xshift=1.5em,
month xshift=1pt,
month label above left,
execute before day scope={
\ifdate{day of month=1}{ % If we are the first day of the month
% no dashes need be added if the first day is a Monday
\ifnum\pgfcalendarcurrentweekday>0\relax
% Iterate from Monday to day before current day
\foreach \i in {0,...,\the\numexpr\pgfcalendarcurrentweekday-1}{
}
\fi
}{}
\pgfcalendardatetojulian{\pgfcalendarcurrentyear-\pgfcalendarcurrentmonth-last}
{\tempcount}
\ifnum\pgfcalendarcurrentjulian=\tempcount\relax % If last day of the month
\ifnum\pgfcalendarcurrentweekday<6\relax % If we need to add any dashes
% Iterate from next day to Sunday
\foreach \i in {\the\numexpr\pgfcalendarcurrentweekday+1,...,6}{
\dayshift{\i}%
}
\fi
\fi
}
]
if (weekend) [text=black!25]
[%
execute at end day scope={%
\draw[red]
(cal-\%y0-\%m0-\%d0.north east) --
(cal-\%y0-\%m0-\%d0.south east);
}][%
execute at end day scope={%
\draw[green]
(cal-\%y0-\%m0-\%d0.south east) --
(cal-\%y0-\%m0-\%d0.south west);
}];
\end{tikzpicture}
\end{document}

• The loop idea works great, and I can follow you comments to make my own adjustments. Jan 13 '18 at 16:31