TikZ-calendar: How to refer to the node of current date?

I am trying to draw a rule under the node of each sundays in my calendar. Therefor I use if (Sunday) {\draw (<current_node>) -- +(0,-4cm);}.
However, I don't know how to access the positionning of current node.

I've tried (\pgfcalendarsuggestedname) or even to emulate the node name (that is calendar_prefix-YYYY-MM-DD) via \def\thisday{\pgfcalendarprefix-\pgfcalendarcurrentyear-\pgfcalendarcurrentmonth-\pgfcalendarcurrentyear} and then using (\thisday) as coordinate... but (of course?!) it doesn't work.

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{calendar}
%\def\thisday{\pgfcalendarprefix-\pgfcalendarcurrentyear-\pgfcalendarcurrentmonth-\pgfcalendarcurrentyear}

\begin{document}
\begin{tikzpicture}
\calendar (cal) [%
day list right,
dates=2016-08-01 to 2016-10-last,
day xshift=1.5em,
month xshift=1pt,
month label above left,
]
if (weekend) [text=black!25];
if (Sunday) {\draw (\pgfcalendarsuggestedname) -- +(0,-4cm);}

\end{tikzpicture}
\end{document}


1 Answer

You cannot use \pgfcalendarsuggestedname here. It is a place holder for use if you want to change the code executed for each day of the calendar when configuring the calendar e.g. in /tikz/day code, as explained on pages 520-521 of the manual.

You can, however, access the name of the current day's node by specifying it explicitly with cal-\%y0-\%m0-\%d0 and you can then use the .south west and .south east anchors to underline it.

However, because the code here is executed before the node for the day is constructed, we need to delay execution of any commands which refer to the current node's name. I've used execute at end day scope which uses the code after the node is created but before the scope for the day is finished, when it is too late.

Because the original examples format made the calendar extremely difficult to work with, I've switched to a week list arrangement for demonstration purposes, but this does not affect the code used to underline Sundays.

Note that if you say

    if (weekend) [text=black!25];


you cannot then add

    if ...


because the semicolon finishes the calendar. It is different if giving code within a scope - then the semicolon is within the scope and does not end the calendar itself.

\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]
if (Sunday) [execute at end day scope={\draw (cal-\%y0-\%m0-\%d0.south west) -- (cal-\%y0-\%m0-\%d0.south east);}]
;
\end{tikzpicture}
\end{document}


• Thank you! For your answer and the detailed explanations! Aug 10 '16 at 8:24