TikZ 日历:可以标记半天吗?

TikZ 日历:可以标记半天吗?

使用此代码:

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

% code used: https://tex.stackexchange.com/questions/10186/weekday-captions-with-the-tikz-library-calendar
% with the correction of Torbjørn T.

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

\begin{tikzpicture}

\calendar[dates=2017-07-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}

导致:

在此处输入图片描述

但我希望得到这样的结果:

在此处输入图片描述

无论如何,这可能吗?我不知道……

多谢

答案1

cal-\%y0-\%m0-\%d0如果日历已命名,则可以引用当前节点cal并将其与execute at end day scope(来源:回答TikZ-日历:如何引用当前日期的节点?)。

我创建了tikzstyles triangle nw、、triangle ne和。triangle swtriangle serectangle

我使用tikzset而不是tikzstyle(见应该使用 \tikzset 还是 \tikzstyle 来定义 TikZ 样式?)。

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

\usepackage{ifthen}

\makeatletter
\tikzset{
    % code used: https://tex.stackexchange.com/questions/10186/weekday-captions-with-the-tikz-library-calendar
    % with the correction of Torbjørn T.
    day headings/.style={
        day heading/.style={#1}
    },
    day heading/.style={},
    day letter headings/.style={
        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};%
                }
            }{}%
        }%
    },
    %
    % new border styles
    rectangle/.style={
        nodes={draw,thick}
    },
    triangle nw/.style={
        execute at end day scope={\draw[thick] (cal-\%y0-\%m0-\%d0.south west) |- (cal-\%y0-\%m0-\%d0.north east) -- cycle;}
    },
    triangle ne/.style={
        execute at end day scope={\draw[thick] (cal-\%y0-\%m0-\%d0.north west) -| (cal-\%y0-\%m0-\%d0.south east) -- cycle;}
    },
    triangle sw/.style={
        execute at end day scope={\draw[thick] (cal-\%y0-\%m0-\%d0.north west) |- (cal-\%y0-\%m0-\%d0.south east) -- cycle;}
    },
    triangle se/.style={
        execute at end day scope={\draw[thick] (cal-\%y0-\%m0-\%d0.south west) -| (cal-\%y0-\%m0-\%d0.north east) -- cycle;}
    },
}
\makeatother

\begin{document}
\begin{center}
\begin{tikzpicture}
    \calendar (cal) [
        dates=2017-07-01 to 2017-07-last,
        week list,
        month label above centered,
        day xshift = 0.8cm,
        day headings=blue,
        if={(equals=07-10) [rectangle]},
        if={(equals=07-11) [rectangle]},
        if={(equals=07-12) [triangle nw]},
        if={(equals=07-19) [triangle se]},
        if={(equals=07-20) [rectangle]},
        if={(equals=07-21) [rectangle]},
        day letter headings
    ];
\end{tikzpicture}
\end{center}
\end{document}

在此处输入图片描述

相关内容