Tikz 日历导致奇怪的行为

Tikz 日历导致奇怪的行为

我需要将日历定位在 tikzpicture 中(这是一个 MWE,原始文件要复杂得多,还包含褪色图片等,所以我真的想在 tikzpicture 环境中执行此操作)。我不明白为什么文本会消失,为什么我不能将日历居中...

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

答案1

\tikz是 的缩写\begin{tikzpicture} .. \end{tikzpicture},因此不应在后者内使用前者。

center在环境中再放置一个环境也是没有意义的tikzpicture。就 (La)TeX 而言, atikzpicture只是一个(通常)大的矩形框,它在页面上的位置与任何其他大框(例如 )一样\includegraphics。您需要center环境外部tikzpicture

如果您修复了这两个问题,您的输出会更有意义,但“title”节点的位置相当糟糕。我个人认为我会将这几行作为普通文本放置在 之外,tikzpicture如下面的代码所示。

在此处输入图片描述

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

相关内容