7

I borrowed the following code from here and made changes according to my requirements. I want to show year at each corner of the border and would like to know how to change the year to custom year. Any help will be highly appreciated. Thanks

Output

enter image description here

MWE

\documentclass[border=4.9mm, multi={tikzpicture}]{standalone}
%\usepackage[hmargin=2cm,bmargin=3cm,tmargin=4.5cm,centering,a4paper]{geometry}
\usepackage[utf8]{inputenc}


%%in preamble:
%
\usepackage{tikz}
\usetikzlibrary{positioning,calendar}
\usetikzlibrary{decorations.markings}

\newcommand{\calrow}[1]{\node[anchor=base east](Mon){M};
\node[base right=of Mon](Tue){T}; \node[base right=of Tue](Wed){W};
\node[base right=of Wed](Thu){T}; \node[base right=of Thu](Fri){F};
\node[base right=of Fri](Sat){S}; \node[base right=of Sat](Sun){S};
\node[darkgreen,above=of Thu]{\textbf{#1}};}

\newcommand{\calperiod}[1]{\calendar[dates=\the\year-#1-01 to \the\year-#1-last]
if(Sunday) [black!50] \holidays;}

\newcommand{\holidays}{% holidays in Italy
if (equals=01-01) [black!50]%
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) [black!50]%
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}
%%in document:
%
\begin{tikzpicture}[every calendar/.style={week list}]
\sffamily
\matrix[%
row 1/.style={darkgreen,node distance=.3ex},%
row 3/.style={darkgreen,node distance=.3ex},
row 5/.style={darkgreen,node distance=.3ex},
row 7/.style={darkgreen,node distance=.3ex},
column sep=1ex,%
draw=darkgreen,thick,rounded corners=5pt,%
postaction={decorate,decoration={markings,mark=at position 0.51 with
{\node[fill=white,text=darkgreen,font={\bfseries\Large}] (year) {\the\year};}}}
% year on frame: decorations.markings library
]{%

% first row: week day and month
\calrow{January} & \calrow{February} & \calrow{March} \\
\calperiod{01} & \calperiod{02} & \calperiod{03} \\[1ex]

% second row: calendar
\calrow{April} & \calrow{May} & \calrow{June} \\
\calperiod{04} & \calperiod{05} & \calperiod{06} \\[1ex]

% third row: week day and month
\calrow{July} & \calrow{August} & \calrow{September} \\
\calperiod{07} & \calperiod{08} & \calperiod{09} \\[1ex]


% forth row: calendar
\calrow{October} & \calrow{November} & \calrow{December} \\
\calperiod{10} & \calperiod{11} & \calperiod{12} \\
};

\end{tikzpicture}

\end{document}
  • How can we make each block 7 rows? In that case, printing 2018 and 2019 sizde by side will give same sizes of pages. – bkarpuz Aug 6 '18 at 12:05
10

To get a different year, one could simply use \year=2017. But if this was undesirable then a \currentyear macro could be used (optionally as a default argument to the \calperiod macro).

To get the year typeset at the corners of the matrix, I have used append after command. This requires that \currentyear be set outside the scope of the matrix. Also a bit of extra space is required at the bottom of the matrix to avoid some overlapping with the year labels.

\documentclass[tikz,border=5]{standalone}
\renewcommand\familydefault\sfdefault
\usetikzlibrary{positioning,calendar}

\colorlet{darkgreen}{green!50!black}
\colorlet{holiday}{black!50}
\newcommand{\calrow}[1]{\node[anchor=base east](Mon){M};
\node[base right=of Mon](Tue){T}; \node[base right=of Tue](Wed){W};
\node[base right=of Wed](Thu){T}; \node[base right=of Thu](Fri){F};
\node[base right=of Fri](Sat){S}; \node[base right=of Sat](Sun){S};
\node[darkgreen, above=of Thu]{\textbf{#1}};}

\newcommand{\calperiod}[2][\currentyear]{%
  \calendar[dates=\currentyear-#2-01 to \currentyear-#2-last]
    if (Sunday) [holiday] \holidays;}
\edef\currentyear{\the\year}
\newcommand{\holidays}{% holidays in Italy
if (equals=01-01) [holiday]%
if (equals=01-06) [holiday]%
if (equals=04-04) [holiday]%
if (equals=04-05) [holiday]%
if (equals=04-25) [holiday]%
if (equals=05-01) [holiday]%
if (equals=05-01) [holiday]%
if (equals=06-02) [holiday]%
if (equals=08-15) [holiday]%
if (equals=11-01) [holiday]%
if (equals=12-08) [holiday]%
if (equals=12-25) [holiday]%
if (equals=12-26) [holiday]%
}
\begin{document}
\begin{tikzpicture}[every calendar/.style={week list},
year label/.style={
  fill=white,text=darkgreen,font=\bfseries\Large
}, current year/.store in=\currentyear,
current year=2017]
\matrix[%
row 1/.style={darkgreen,node distance=.3ex},%
row 3/.style={darkgreen,node distance=.3ex},
row 5/.style={darkgreen,node distance=.3ex},
row 7/.style={darkgreen,node distance=.3ex},
column sep=1ex,%
draw=darkgreen,thick,rounded corners=5pt,%
append after command={ 
  \pgfextra{\edef\matrixname{\tikzlastnode}}
  node [year label/.try, right=1ex of \matrixname.south west] {\currentyear}
  node [year label/.try, right=1ex of \matrixname.north west] {\currentyear}
  node [year label/.try, left=1ex of \matrixname.south east] {\currentyear}
  node [year label/.try, left=1ex of \matrixname.north east] {\currentyear}
}
]{%

% first row: week day and month
\calrow{January} & \calrow{February} & \calrow{March} \\
\calperiod{01} & \calperiod{02} & \calperiod{03} \\[1ex]

% second row: calendar
\calrow{April} & \calrow{May} & \calrow{June} \\
\calperiod{04} & \calperiod{05} & \calperiod{06} \\[1ex]

% third row: week day and month
\calrow{July} & \calrow{August} & \calrow{September} \\
\calperiod{07} & \calperiod{08} & \calperiod{09} \\[1ex]

% forth row: calendar
\calrow{October} & \calrow{November} & \calrow{December} \\
\calperiod{10} & \calperiod{11} & \calperiod{12} \\[1ex]\\
};

\end{tikzpicture}
\end{document}

enter image description here

5

The border starts from north east corner in the anti clock wise direction. The horizontal distance is 2 parts and the vertical 3 parts. So the 2 comes at north west, 5 comes at south west, 7 comes at south east. Now you can add more decorations at each corners.

\documentclass[border=4.9mm, multi={tikzpicture}]{standalone}
%\usepackage[hmargin=2cm,bmargin=3cm,tmargin=4.5cm,centering,a4paper]{geometry}
\usepackage[utf8]{inputenc}


%%in preamble:
%
\usepackage{tikz}
\usetikzlibrary{positioning,calendar}
\usetikzlibrary{decorations.markings}

\newcommand{\calrow}[1]{\node[anchor=base east](Mon){M};
\node[base right=of Mon](Tue){T}; \node[base right=of Tue](Wed){W};
\node[base right=of Wed](Thu){T}; \node[base right=of Thu](Fri){F};
\node[base right=of Fri](Sat){S}; \node[base right=of Sat](Sun){S};
\node[darkgreen,above=of Thu]{\textbf{#1}};}

\newcommand{\calperiod}[1]{\calendar[dates=\the\year-#1-01 to \the\year-#1-last]
if(Sunday) [black!50] \holidays;}

\newcommand{\holidays}{% holidays in Italy
if (equals=01-01) [black!50]%
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) [black!50]%
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}
%%in document:
%
\begin{tikzpicture}[every calendar/.style={week list}]
\sffamily
\matrix[%
row 1/.style={darkgreen,node distance=.3ex},%
row 3/.style={darkgreen,node distance=.3ex},
row 5/.style={darkgreen,node distance=.3ex},
row 7/.style={darkgreen,node distance=.3ex},
column sep=1ex,%
draw=darkgreen,thick,rounded corners=5pt,%
postaction={decorate,decoration={markings,mark=at position 0.2 with
{\node[fill=white,text=darkgreen,font={\bfseries\Large}] (year) {\the\year};}
}},
postaction={decorate,decoration={markings,mark=at position 0.51 with
{\node[fill=white,text=darkgreen,font={\bfseries\Large}] (year) {\the\year};}
}},
postaction={decorate,decoration={markings,mark=at position 0.7 with
{\node[fill=white,text=darkgreen,font={\bfseries\Large}] (year) {\the\year};}
}},
postaction={decorate,decoration={markings,mark=at position 0.01 with
{\node[fill=white,text=darkgreen,font={\bfseries\Large}] (year) {\the\year};}
}},
% year on frame: decorations.markings library
]{%

% first row: week day and month
\calrow{January} & \calrow{February} & \calrow{March} \\
\calperiod{01} & \calperiod{02} & \calperiod{03} \\[1ex]

% second row: calendar
\calrow{April} & \calrow{May} & \calrow{June} \\
\calperiod{04} & \calperiod{05} & \calperiod{06} \\[1ex]

% third row: week day and month
\calrow{July} & \calrow{August} & \calrow{September} \\
\calperiod{07} & \calperiod{08} & \calperiod{09} \\[1ex]


% forth row: calendar
\calrow{October} & \calrow{November} & \calrow{December} \\
\calperiod{10} & \calperiod{11} & \calperiod{12} \\
};

\end{tikzpicture}

\end{document}

enter image description here

  • I didn't follow the how to change the year to custom year part properly. – user11232 Oct 24 '15 at 10:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.