If you modify the placement of the days slightly, you can easily add shapes without having to place the shapes using trial and error to find the right coordinates.
By adding
every day/.style={anchor=base},
day text={\%d=},rounded corners=0,anchor=base,text height=1ex,text depth=-0.5ex
to the calendar options
you align the days in such a way that you can then just add \node
s to the days you want to highlight, without any fiddling around. day text={\%d=}
takes care of making single digit days as wide as two digit ones.
By using \node[anchor=base,xshift=0.5ex](seg){S};
to print the first weekday letter, all the weekdays will align nicely with the days.
After these adjustments, you can highlight individual days using things like
if (equals=01-10) {\node [fill=yellow,draw,star] {};}
in the \holidays
macro.
Here's the full adjusted code:
\documentclass[12pt]{article}
\usepackage{lscape,tikz}
\usepackage[brazil]{babel}
\usepackage[latin1]{inputenc}
\usepackage[margin=1in, paperwidth=15.8in, paperheight=8.5in]{geometry}
\usepackage{geometry}
\usepackage{amsmath,color,graphicx}
\usepackage{amsfonts}
\usepackage{amssymb}
\definecolor{Red}{cmyk}{0,1,1,0}
\def\red{\color{Red}}
\definecolor{Blue}{cmyk}{1,1,0,0}
\def\blue{\color{Blue}}
%%in preamble:
%
\Huge
\usetikzlibrary{arrows,shapes}
\usetikzlibrary{positioning,calendar,er}
\usetikzlibrary{decorations.markings}
\usetikzlibrary{shapes.geometric}
\newcommand{\calrow}[1]{\node[anchor=base,xshift=0.5ex](seg){S}; % Shift first weekday
\node[base right=of seg](ter){T}; \node[base right=of ter](qua){Q};
\node[base right=of qua](qui){Q}; \node[base right=of qui](sex){\ \!S};
\node[base right=of sex](sab){\ \!S}; \node[base right=of sab](dom){D};
\node[black,above=of qui]{\textbf{#1}};}
\newcommand{\calperiod}[1]{\calendar[dates=\the\year-#1-01 to \the\year-#1-last,
every day/.style={anchor=base}, % Center days
day text={\%d=},rounded corners=0,anchor=base,text height=1ex,text depth=-0.5ex] % Make node placement easier
if(Sunday) [red] \holidays;}
\newcommand{\holidays}{
if (equals=01-15) {\node [draw,regular polygon,regular polygon sides=3] {};}
if (equals=01-20) {\node [draw,cloud] {};}
if (equals=01-10) {\node [fill=yellow,draw,star] {};}
if (equals=01-06) [black!50]%
if (equals=04-04) [black!50]%
if (equals=04-05) [black!50]%
if (equals=04-25) [black!50]%
if (equals=05-01) [black!50]%
if (equals=05-01) [black!50]%
if (equals=06-02) {\draw (-0.25,0.135) circle (9.0pt);}%
if (equals=08-15) [black!50]%
if (equals=11-01) [black!50]%
if (equals=12-08) [black!50]%
if (equals=12-25) [black!50]%
if (equals=12-26) [black!50]%
}
\colorlet{darkgreen}{green!50!black}
\begin{document}
\begin{tikzpicture}
[every calendar/.style={week list}]
%\node[star,draw,minimum size=.4cm,star point ratio=1.0,thick] at (calendar-\the\year-08-29){};
\sffamily
\matrix[%
row 1/.style={black,node distance=.3ex},%
row 3/.style={black,node distance=.3ex},
column sep=1ex,%
draw=black,thick,rounded corners=30pt,%
postaction={decorate,decoration={markings,mark=at position 0.51 with
{\node[fill=white,text=black,font={\bfseries\Large}] (year) {\the\year};}}}
% year on frame: decorations.markings library
]{%
% first row: week day and month
\calrow{Janeiro} & \calrow{Fevereiro} & \calrow{Março} &
\calrow{Abril} & \calrow{Maio} & \calrow{Junho} \\
% second row: calendar
\calperiod{01} & \calperiod{02} & \calperiod{03} &
\calperiod{04} & \calperiod{05} & \calperiod{06} \\[0.4cm]
% third row: week day and month
\calrow{Julho} & \calrow{Agosto} & \calrow{Setembro} &
\calrow{Outubro} & \calrow{Novembro} & \calrow{Dezembro} \\
% forth row: calendar
\calperiod{07} & \calperiod{08} & \calperiod{09} &
\calperiod{10} & \calperiod{11} & \calperiod{12} \\
};
\end{tikzpicture}
\end{document}
![calendar with shapes](https://i.stack.imgur.com/dUYuv.png)
You could specify an if
condition, such as
\calendar[dates=2012-01-01 to 2012-01-last] if (Monday,Wednesday,Friday,Sunday) [red];
![calendar](https://i.stack.imgur.com/SHKsB.png)
Your calendar is appearing on page 2 because it's too high for the text area. You will get an Overfull \vbox
warning and the tikzpicture
is moved to the next page. Make it a bit smaller or adjust the text area.
Best Answer
A simple
and
functionIf you simply want an
and
function for PGF’s calendar you can use the following code. It checks the first argument and only if it is true it does check the other one. (If the first one's already false, why bother checking the second?)This can be used as
Maybe it is better to write
This works, too. Obviously, you'll need
{}
if you use it like this:Code
Output
Second Sunday in May?
This library
qrr.calendar
introduces the conditionalsleap year
This can also be used for other years:
week of month=<arg>
tests whether we are in the<arg>
th week of the month. This does not correspond with the Monday-to-Sunday (or the Sunday-to-Saturday) week. The first week goes from day 1 to day 7, the second week from day 8 to 14, and so on.week of month'=<arg>
is the same asweek of month
but from the last day on.week of month'=1
would (currently: October) test whether we are between day 25 and day 31 of the month. This uses the\pgfcalendar@getlastYMX
macro to get the last day of a month which uses theleap year
key when the month falls on February.first=[<i>:]<conditonal>
andlast=[<i>:]<conditional>
combinesweek of month
andweek of month'
with<conditional>
. You can check for the second Monday in a month withIf no
<i>:
is given, the first/last (i.e.1:
) is used.The
<conditional>
can actually be anything but naturally you want to specify a day of the week here.between days=<first> and <last>
checks wheter the day is betweenfirst
and<last>
.not=<cond>
negates the outcome of<cond>
Load it with
Code
Output