3

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%
\tikzoption{day headings}{\tikzstyle{day heading}=[#1]}
\tikzstyle{day heading}=[]
\tikzstyle{day letter headings}=[
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}%
    \node[every day,day heading]{\l};%
  } 
}{}%
}%
]

\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,
    day headings=blue,
    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}]},
    day letter headings
];
%\end{center}

\end{tikzpicture}

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

\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.

enter image description here

\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%
\tikzoption{day headings}{\tikzstyle{day heading}=[#1]}
\tikzstyle{day heading}=[]
\tikzstyle{day letter headings}=[
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}%
    \node[every day,day heading]{\l};%
  } 
}{}%
}%
]

\makeatother%


\begin{document}
\begin{center}
{\Huge Einladung zur Feldkampagne

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,
    day headings=blue,
    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}]},
    day letter headings
];

\end{tikzpicture}
\end{center}
\end{document}
  • thanks a lot for your very very valuable hint. And sorry for the delay of my answer, I took part on an excavation in the Kaukasus the last three weeks... – Harald Jul 19 '17 at 7:26

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.