标记 Tikz 日历列表中包含的所有日期

标记 Tikz 日历列表中包含的所有日期

我正在尝试使用 tikz 日历中的 if 语句标记(以绿色文本颜色)列表 ( \myDates) 中包含的日期。我不知道如何遍历列表,以便标记其中包含的所有日期。我目前的做法只是标记了中的第一个日期\myDates。这是 MWE。我正在使用 XeLaTeX 进行编译。任何帮助都将不胜感激。

\def\year{2024}
\def\month{02}
\newcommand*\myDates{%
    2024-02-15,%
    2024-02-19,%
    2024-03-17,%
    2024-04-13
}

\documentclass[12pt]{article}
\usepackage{fontspec}
    \setmainfont{CMU Bright}
\usepackage[greek]{babel}
\usepackage{tikz}
    \usetikzlibrary{calc,calendar}

\begin{document}

% MINI CALENDAR
\begin{tikzpicture}
  \calendar
    [
    dates=\year-\month-01 to \year-04-last,
    week list,
    month label above centered,
    month text=\textcolor{black}{\bfseries\%mt \%y-},
    day xshift = 8mm
    ]
    if (Sunday) [red!50]
    if (equals=\myDates) [green]
    ;    
\end{tikzpicture}

\end{document}

答案1

我能做的最好的就是使用日历定义的节点,通过迭代日期并用来(mycal-\date)绘制圆圈。

    % MINI CALENDAR
    \begin{tikzpicture}
        \calendar (mycal)
        [
            dates=\year-\month-01 to \year-04-last,
            week list,
            month label above centered,
            month text=\textcolor{black}{\bfseries\%mt \%y-},
            day xshift = 8mm
        ]
        if (Sunday) [red!50]
%       if (equals={2024-04-16,2024-02-15}) [green] 
        ;   
        \foreach \date in {2024-04-13,2024-02-15, 2024-02-15, 2024-03-17}{
            \draw [green,fill,opacity=0.2] (mycal-\date) circle[radius=7pt];    
        }
    \end{tikzpicture}

在此处输入图片描述

答案2

由于\myDates已经是 PGFFor 格式,因此可以.list通过处理程序进行一次扩展后使用该处理程序.expand once

equals/.list/.expand once=\myDates

这被翻译成

equals=2024-02-15, equals=2024-02-19, equals=2024-03-17, equals=2024-04-13

它将通过所有条件之间的逻辑或来解释。

代码

\documentclass[12pt]{article}
%\usepackage{fontspec}
%    \setmainfont{CMU Bright}
%\usepackage[greek]{babel}
\usepackage{tikz}
\usetikzlibrary{calc,calendar}

\newcommand*\myYear{2024}
\newcommand*\myMonth{02}
\newcommand*\myDates{%
    2024-02-15,%
    2024-02-19,%
    2024-03-17,%
    2024-04-13
}
\begin{document}
\begin{tikzpicture}
  \calendar[
    dates=\myYear-\myMonth-01 to \myYear-04-last,
    week list,
    month label above centered,
    month text=\textcolor{black}{\bfseries\%mt \%y-},
    day xshift = 8mm
    ] if (Sunday) [red!50]
      if (equals/.list/.expand once=\myDates) [green]
  ;
\end{tikzpicture}
\end{document}

输出

在此处输入图片描述

答案3

类似以下内容——我的详细回答,包括语法和原文引用——如何使用背景颜色突出显示 TikZ 日历中的日期或星期?

在此处输入图片描述

平均能量损失

\documentclass[12pt]{article}
\usepackage{hyperref}
\hypersetup{colorlinks=true, citecolor=blue}
\usepackage{tikz}
\usetikzlibrary{calc,calendar}

%%% Shorthand w- for Weekday
\expandafter\def\csname pgfcalendar@shorthand@w-\endcsname{\ifcase\pgfcalendarcurrentweekday M\or T\or W \or T\or F\else S\fi}

%%% equal key that strips /<text>
\pgfqkeys{/pgf/calendar}{equals-strip/.style args={#1/#2}{equals={#1}}}

%%% A simple parser for <year>-<month>-<day> so we can use shorthands outside of a calendar
\def\pgfcalendarsimpleparse#1-#2-#3\relax{%
    \def\pgfcalendarcurrentyear{#1}%
    \def\pgfcalendarcurrentmonth{#2}%
    \def\pgfcalendarcurrentday{#3}}

%%% hyperling node
\tikzset{
    hyperlink node/.style={
        alias=@hyper,
        append after command={
            let \p1 = (@hyper.north west),
            \p2 = (@hyper.south east),
            \n1 = {\x2-\x1}, \n2 = {\y1-\y2} in
            node [inner sep=+0pt, outer sep=+0pt, anchor=center, at=(@hyper)] {\hyperlink{ref-#1}{\XeTeXLinkBox{\phantom{\rule{\n1}{\n2}}}}}}}}

\newcommand*{\calrow}[1]{\node[draw,black, minimum width=7*\csname tikz@lib@cal@xshift\endcsname]{\textbf{#1}};}

\newcommand{\calperiod}[1]{%
    \calendar [
    dates=2024-#1-01 to 2024-#1-last,
    day text={\%d=},
    %
    % we name every weekday node (even though we only need the Thursday)
    weekday node/.style={
        black, name=weekday-\pgfcalendarcurrentmonth-\pgfcalendarcurrentweekday},
    %
    % teaching day, include hyperlink node based on the date
    teaching day/.style={
        days={text=blue, fill=green, hyperlink node=\pgfcalendarcurrentyear-\pgfcalendarcurrentmonth-\pgfcalendarcurrentday}}]
    %
    % standard stuff
    %
    if (Saturday) [blue!50]
    if (Sunday)   [red]
    %
    % the first day of the month is in the upmost row,
    % let's place the weekday above it and align it properly
    % the name @firstweekday can be referenced later
    %
    if (day of month=1) [days={append after command={
            node [anchor=base east, at={(\tikzlastnode.base east)}, alias=@firstweekday,
            yshift=\csname tikz@lib@cal@yshift\endcsname, weekday node/.try] {\%w-}}}]
    %
    % for all other days 2 to 7 we place the weekday text similar but we use the
    % the first placed weekday text to make sure we align it at the same height
    %
    if (day of month=2, day of month=3, day of month=4, day of month=5, day of month=6, day of month=7) [days={append after command={
            node [anchor=base east, at={(@firstweekday.base east-|\tikzlastnode.base east)}, weekday node/.try] {\%w-}}}]
    %
    % and go
    %
    if (equals-strip/.list/.expand once=\myDates) [teaching day]
    ;
}
\newcommand*\myDates{%
    2024-04-8/Intro,
    2024-04-9/Basics I,
    2024-04-10/Basics II,
    2024-04-11/And}

\linespread{1.3}
\begin{document}\noindent
    \begin{tikzpicture}[every calendar/.style={week list}],
        \matrix[column sep=1.5ex]{%
            \calperiod{04} &  &  \\
        };
        \foreach \mon/\t in {04/April}
        \node[anchor=south, yshift=2ex, at=(weekday-\mon-3)] {\textbf{\t}};
    \end{tikzpicture}
    
    %   \pagebreak
    %   \setlength{\labelwidth}{4em}
    %   \begin{itemize}
        %       \foreach \target/\name[/utils/exec=\let\%\pgfcalendarshorthand] in \myDates{
            %           \expandafter\pgfcalendarsimpleparse\target\relax
            %           \item[\%m. \%d= \%y-] \hypertarget{ref-\target}{\name}}
        %   \end{itemize}
\end{document}

相关内容