# Tikz calendar leads to strange behavior

I need to position the calendar within a tikzpicture (this is a MWE, the original file is much more complex, containing also fading pictures etc, so I really want to do it within the tikzpicture environment). I don't understand why the text disappeares and why I can not center the calendar...

\documentclass[11pt,BCOR8mm,final,a4paper]{scrbook}
\usepackage[germanb]{babel}
\usepackage[latin1]{inputenc}
\usepackage{tikz,geometry}
\usetikzlibrary{positioning}
\usetikzlibrary{calendar}

% code von: https://tex.stackexchange.com/questions/10186/weekday-captions-with-the-tikz-library-calendar

\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/D,2/M,3/D,4/F,5/S,6/S} {
\pgf@xa=\d\pgf@xa%
\pgftransformxshift{\pgf@xa}%
\pgftransformyshift{\pgf@ya}%
}
}{}%
}%
]

\makeatother%

\begin{document}

\begin{tikzpicture}

\node[text=black, font=\fontsize{20}{44}\selectfont] at (13,22.7)  {Einladung zur Feldkampagne};

\node[text=black, font=\fontsize{20}{44}\selectfont] at (13,21)  {Schulprojekt 1 / 2017};

\node[text=black, font=\fontsize{20}{44}\selectfont] at (13.0,15.)  {Zeitraum:};

%\begin{center}
\tikz\calendar[dates=2017-06-01 to 2017-07-last,
week list,
month label above centered,
day xshift = 0.8cm,
if={(equals=07-10) [nodes={draw,thick}]},
if={(equals=07-11) [nodes={draw,thick}]},
if={(equals=07-12) [nodes={draw,thick}]},
if={(equals=07-19) [nodes={draw,thick}]},
if={(equals=07-20) [nodes={draw,thick}]},
if={(equals=07-21) [nodes={draw,thick}]},
];
%\end{center}

\end{tikzpicture}

\end{document}

• \tikzstyle is deprecated, by the way. – cfr Jul 2 '17 at 15:05

\tikz is a shortform of \begin{tikzpicture} .. \end{tikzpicture}, so you shouldn't use the former inside the latter.

It also doesn't make sense to have a center environment inside a tikzpicture environment. As far as (La)TeX is concerned, a tikzpicture is just a (usually) big rectangular box, and it is positioned on the page just like any other big box, e.g. an \includegraphics. You want the center environment outside the tikzpicture.

If you fix those two things your output makes more sense, but the "title" nodes are placed quite badly. Personally I think I would place those few lines as normal text, outside the tikzpicture, as in the code below.

\documentclass[11pt,BCOR8mm,final,a4paper]{scrbook}
\usepackage[germanb]{babel}
\usepackage[latin1]{inputenc}
\usepackage{tikz,geometry}
\usetikzlibrary{positioning}
\usetikzlibrary{calendar}

% code von: https://tex.stackexchange.com/questions/10186/weekday-captions-with-the-tikz-library-calendar

\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/D,2/M,3/D,4/F,5/S,6/S} {
\pgf@xa=\d\pgf@xa%
\pgftransformxshift{\pgf@xa}%
\pgftransformyshift{\pgf@ya}%
}
}{}%
}%
]

\makeatother%

\begin{document}
\begin{center}

Schulprojekt 1 / 2017 \par}

\bigskip

{\Large Zeitraum: \par}

\begin{tikzpicture}

\calendar[dates=2017-06-01 to 2017-07-last,
week list,
month label above centered,
day xshift = 0.8cm,
if={(equals=07-10) [nodes={draw,thick}]},
if={(equals=07-11) [nodes={draw,thick}]},
if={(equals=07-12) [nodes={draw,thick}]},
if={(equals=07-19) [nodes={draw,thick}]},
if={(equals=07-20) [nodes={draw,thick}]},
if={(equals=07-21) [nodes={draw,thick}]},