# Calendar with TIKZ-PGF: How to highlight current date?

I am trying to generate a 365-day notebook that contains the current date and a small calendar of the current month. I wwould like to highlight the current day in the small calendar, for example by adding a circle around it or by making it in boldface. For example, if the date listed on the left is January 10, I would like to have a mark on the calendar on the right highlighting the date January 10. After spending hours of reading the pgf/tikz manuals and calendar-related topics on this forum, I did not reach any solution.

Below is my code:

\documentclass[b5paper,  fontsize=12pt, parskip=half, DIV=12,BCOR=2cm]{scrartcl}
%pagesize,
\usepackage[T1]{fontenc}
\usepackage[romanian]{babel}
\usepackage{translator, tikz, pgfcalendar, array, libertine}
\usepackage{ucs}
\usepackage[utf8x]{inputenc}
\usepackage{xcolor}
\usepackage{tabu}
\usepackage{epstopdf}
\usepackage{color}
\usepackage{pgf}

%=========================================================
%== Page characteristics (Page Setup) ====================
\setlength{\textwidth}{126mm}
\setlength{\textheight}{230.0mm}
\setlength{\topmargin}{-30mm}
\setlength{\hoffset}{-20mm}
\setlength{\marginparwidth}{-20mm}
\setlength{\footskip}{12mm}
\setlength{\parindent}{0cm}

\usetikzlibrary{calendar,shapes.geometric}
%== Define colors =================================
\definecolor{rozmam}{RGB}{242,172,184}
\newcommand{\troz}{\textcolor{rozmam}}

\makeatletter%
execute before day scope={ \ifdate{day of month=1}{%
\pgfmathsetlength{\pgf@ya}{\tikz@lib@cal@yshift}%
\pgfmathsetlength\pgf@xa{\tikz@lib@cal@xshift}%
\pgftransformyshift{-\pgf@ya}
\foreach \d/\l in {0/M,1/T,2/W,3/T,4/F,5/S,6/S} {
\pgf@xa=\d\pgf@xa%
\pgftransformxshift{\pgf@xa}%
\pgftransformyshift{\pgf@ya}%
}
}{}%
}%
]
\makeatother

\newcommand{\PaginaMea}{
\minisec{\textcolor{gray}{Notes}}
\begin{tabu}{@{}p{0.12\textwidth}p{0.32\textwidth}p{0.32\textwidth}p{0.20\textwidth}c}\taburulecolor{gray}\hline
$\diamond$ \textbf{ } &  &   &  & \\\hline
$\diamond$ & & & & \\\hline
$\diamond$ & & & & \\\hline
$\diamond$ & & & & \\\hline
$\diamond$ & & & & \\\hline
$\diamond$ & & & & \\\hline
$\diamond$ & & & & \\\hline
$\diamond$ & & & & \\\hline
$\diamond$ & & & & \\\hline
$\diamond$ & & & & \\\hline
$\diamond$ & & & & \\\hline
$\diamond$ & & & & \\\hline
$\diamond$ & & & & \\\hline
$\diamond$ & & & & \\\hline
$\diamond$ & & & & \\\hline
$\diamond$ & & & & \\\hline
$\diamond$ & & & & \\\hline
$\diamond$ & & & & \\\hline
$\diamond$ & & & & \\\hline
$\diamond$ & & & & \\\hline
$\diamond$ & & & & \\\hline
$\diamond$ & & & & \\\hline
$\diamond$ & & & & \\\hline
$\diamond$ & & & & \\\hline
$\diamond$ & & & & \\\hline
$\diamond$ & & & & \\\hline
$\diamond$ & & & & \\\hline
$\diamond$ & & & & \\\hline

\end{tabu}
}

\begin{document}
\foreach \n in {1,...,1}{

\pgfcalendar{cal}{2018-\n-01}{2018-\n-last}
{
\thispagestyle{empty}
\noindent{\Huge \bfseries
\pgfcalendarcurrentday{}\\[20pt]
\Huge \pgfcalendarweekdayname{\pgfcalendarcurrentweekday}
}

\begin{tikzpicture}[remember picture, overlay, transform shape]
\node [anchor=north east, inner sep=8pt, xshift = 30pt]
at (current page.north east)
{
\begin{tikzpicture}[every node/.append style = {anchor=center}]
\calendar[dates=2018-\n-01 to 2018-\n-last,
week list,
day text=\%d0,
month label above centered,
month text={\%mt} \%y-,
day xshift = 0.8cm,
]
if (Saturday) [rozmam]
if (Sunday)   [rozmam];
\end{tikzpicture}
};
\end{tikzpicture}
\\[30pt]
\PaginaMea
\pagebreak
{}
}
}
\end{document}

There are two ways to mark the current day. For both, day and month of the outer calendar must be known. this can be achieved with

\edef\pagedayofmonth{\pgfcalendarcurrentday}%
\edef\pagemonth{\pgfcalendarcurrentmonth}%

in the definition of the outer calendar. The \edef is necessary, because in the small calendar the two \pgfcalendarcurrent... macros will deliver the values for the latter.

Then if (day of month=\pagedayofmonth) [cyan] can be added to the small calendar to change the color of the number. nodes={draw} could be added, but this would draw a rectangle, which is too large.

Or the nodes defined for each day can be used to draw around or over the number. This is done after the small calendar. To make it work, the calendar must be named. Then the nodes for the days will be named in the form calendarname-year-month-day, e.g. mycal-2018-02-07.

\draw[green,thick,rounded corners]
($(mycal-2018-\pagemonth-\pagedayofmonth.south east) + (-1.5mm,1.5mm)$) rectangle
($(mycal-2018-\pagemonth-\pagedayofmonth.north west) + (1.5mm,-1.5mm)$);

The calculation is done to achieve a reasonable size of the rectangle, because just using the anchors would result in a too large rectangle.

The result (showing both methods):

And the code:

Here I also changed the outdated \tikzstyle to \tikzset, see comments in the code.

\documentclass[b5paper,  fontsize=12pt, parskip=half, DIV=12,BCOR=2cm]{scrartcl}
%pagesize,
\usepackage[T1]{fontenc}
\usepackage[romanian]{babel}
%\usepackage{libertine} % fonts not installed here
\usepackage{translator, tikz, array} % pgfcalendar loaded later with \usetikzlibrary{calendar}
\usepackage{ucs}
\usepackage[utf8x]{inputenc}
\usepackage{tabu}
\usepackage{epstopdf}

%=========================================================
%== Page characteristics (Page Setup) ====================
% using geometry would be better
\setlength{\textwidth}{126mm}
\setlength{\textheight}{230.0mm}
\setlength{\topmargin}{-30mm}
\setlength{\hoffset}{-20mm}
\setlength{\marginparwidth}{-20mm}
\setlength{\footskip}{12mm}
\setlength{\parindent}{0cm}

\usetikzlibrary{calendar,shapes.geometric}
\usetikzlibrary{calc}
%== Define colors =================================
\definecolor{rozmam}{RGB}{242,172,184}
\newcommand{\troz}{\textcolor{rozmam}}

\makeatletter%
% these days, \tikzset is used
\tikzset{%
execute before day scope={ \ifdate{day of month=1}{%
\pgfmathsetlength{\pgf@ya}{\tikz@lib@cal@yshift}%
\pgfmathsetlength\pgf@xa{\tikz@lib@cal@xshift}%
\pgftransformyshift{-\pgf@ya}
\foreach \d/\l in {0/M,1/T,2/W,3/T,4/F,5/S,6/S} {
\pgf@xa=\d\pgf@xa%
\pgftransformxshift{\pgf@xa}%
\pgftransformyshift{\pgf@ya}%
}
}{}%
}
}
}
\makeatother

\newcommand{\PaginaMea}{
\minisec{\textcolor{gray}{Notes}}
\begin{tabu}{@{}p{0.12\textwidth}p{0.32\textwidth}p{0.32\textwidth}p{0.20\textwidth}c}\taburulecolor{gray}\hline
$\diamond$ \textbf{ } &  &   &  & \\\hline
$\diamond$ & & & & \\\hline
$\diamond$ & & & & \\\hline
$\diamond$ & & & & \\\hline
$\diamond$ & & & & \\\hline
$\diamond$ & & & & \\\hline
$\diamond$ & & & & \\\hline
$\diamond$ & & & & \\\hline
$\diamond$ & & & & \\\hline
$\diamond$ & & & & \\\hline
$\diamond$ & & & & \\\hline
$\diamond$ & & & & \\\hline
$\diamond$ & & & & \\\hline
$\diamond$ & & & & \\\hline
$\diamond$ & & & & \\\hline
$\diamond$ & & & & \\\hline
$\diamond$ & & & & \\\hline
$\diamond$ & & & & \\\hline
$\diamond$ & & & & \\\hline
$\diamond$ & & & & \\\hline
$\diamond$ & & & & \\\hline
$\diamond$ & & & & \\\hline
$\diamond$ & & & & \\\hline
$\diamond$ & & & & \\\hline
$\diamond$ & & & & \\\hline
$\diamond$ & & & & \\\hline
$\diamond$ & & & & \\\hline
$\diamond$ & & & & \\\hline

\end{tabu}
}

\begin{document}
\foreach \n in {2,...,2}{

\pgfcalendar{cal}{2018-\n-01}{2018-\n-last}
{
% added to ensure every day starts on a new page
\newpage
\thispagestyle{empty}
% remember day and month
\edef\pagedayofmonth{\pgfcalendarcurrentday}%
\edef\pagemonth{\pgfcalendarcurrentmonth}%
\noindent{\Huge \bfseries
\pgfcalendarcurrentday{}\\[20pt]
\Huge \pgfcalendarweekdayname{\pgfcalendarcurrentweekday}
}

\begin{tikzpicture}[remember picture, overlay, transform shape]
\node [anchor=north east, inner sep=8pt, xshift = 30pt]
at (current page.north east)
{
\begin{tikzpicture}[every node/.append style = {anchor=center}]
\calendar (mycal) [dates=2018-\n-01 to 2018-\n-last,
week list,
day text=\%d0,
month label above centered,
month text={\%mt} \%y-,
day xshift = 0.8cm,
]
if (Saturday) [rozmam]
if (Sunday)   [rozmam]
% just set another text color; nodes={draw} could be added, but the rectangle is too large
if (day of month=\pagedayofmonth) [cyan]
;
% draw a frame around the day
\draw[green,thick,rounded corners]
($(mycal-2018-\pagemonth-\pagedayofmonth.south east) + (-1.5mm,1.5mm)$) rectangle
($(mycal-2018-\pagemonth-\pagedayofmonth.north west) + (1.5mm,-1.5mm)$);
\end{tikzpicture}
};
\end{tikzpicture}
\\[30pt]
\PaginaMea
\pagebreak
{}
}
}
\end{document}
• Many thanks, @Mike. Completely solved my problem. Also thanks for your patience and pedagogical approach. – Vladimir Martinusi Aug 20 '17 at 9:00