tikz 日历月份分隔线

tikz 日历月份分隔线

我正在绘制一行连续 3 到 10 天的任意开始日期。我需要从第一个框(上方)到最后一个框画一条线,但如果发生月份变化,该线必须停止,-last并且必须从该行的最后一天开始一条新线(使用新颜色)yyyy-mm-01。代码还必须考虑月份名称的位置。

这就是我想要的样子: 在此处输入图片描述

这是我的妈妈:

\documentclass{beamer}

\mode<presentation> {\usetheme{metropolis}}

\newlength{\slw}\setlength{\slw}{160mm}
\newlength{\slh}\setlength{\slh}{90mm}
\geometry{verbose,papersize={\slw,\slh},hmargin=5mm}

\usepackage{fontsize,fix-cm,verbatim}
\usepackage{tikz}
\usetikzlibrary{calc,calendar}

\tikzset{
  my calendar/.style={
    day list right,
    day code={
      \node (daybox) [anchor=base, font=\Large,
        text width=18mm-2*(\pgfkeysvalueof{/pgf/inner xsep}),
        align=right, text depth=.25ex, text height = 15mm, rounded corners=3mm, draw,
        very thick] {\tikzdaytext};,
      \node at (daybox) [anchor=center, text depth=.25ex, text height=1.5ex]
        {\textbf{\daytext{\pgfcalendarcurrentweekday}}};
%\draw node[anchor = west, gray]{\pgfcalendarweekdayname{\pgfcalendarcurrentweekday}
    },
    month label above right,
    month xshift=2mm, month yshift=0mm,
    day xshift=18mm+2mm,
    day yshift=15mm+2mm,
  },
  use shortest/.style={
    day text=\number\%d0\relax},
}

\def\pgfcalendarmonthname#1{%
  \ifcase#1\or
  janvier\or février\or mars\or avril\or mai\or juin\or
  juillet\or août\or septembre\or octobre\or décembre\fi}


\def\daytext#1{%
  \ifcase#1
  lundi\or mardi\or mercredi\or jeudi\or
  vendredi\or samedi\or dimanche\fi}

\begin{document}
\begin{frame}{calendrier de la semaine}
  \begin{tikzpicture}
    \calendar 
      [my calendar, use shortest] (moncal) [
   dates=\year-\month-\day+7 to \year-\month-\day+13];
  \end{tikzpicture}

\end{frame}
\end{document}

答案1

让我们给每个 daybox 一个别名:today。日历的第一个 daybox 和/或最近的月份第一天获得别名day1。 (这样,我们就不会依赖于\pgfcalendarsuggestedname。)

在日历的末尾(equals=\pgfcalendarendiso)和/或一个月的末尾( ),在和end of month=1之间画一条线。(对于第二天,名称将被新的日期框覆盖,以便绘制下一条线。)day1todayday1

此线的设置方式是,它会从某个地方画一条线day1.north westtoday.north east同时every month向其添加一个节点。此外,month line \pgfcalendarcurrentmonth还会尝试键。您可以手动定义它们:month line 01/.style={green}或通过month colors键定义它们,该键采用颜色列表并将它们分配给适当的month line XX键。


在下面的代码中,日期数字和星期几名称被实现为矩形节点的标签没有任何文本。这样可以将这些标签放置在角落中,并使用内部分隔符调整框的填充。现在无需摆弄文本高度和深度。

随着node contents钥匙甚至标签的文本也可以通过 PGFKeys 轻松定制。


不幸的是,PGFCalendar 和所选语言之间的翻译界面被破坏beamer,我们将使用您对\pgfcalendarmonthname和的自定义重新定义\pgfcalendarweekdayname。除非您想要不同语言的日历,否则这应该是最简单的方法。

由于您想使用polyglossia,我在这里添加了选项 french,但无论如何,它不再与 PGFCalendar 模块交互。但无论如何,最好还是包含它,因为我们可能会发现与它的不兼容性。babel这里不需要 TikZ 库。

代码

% !TeX TS-program = lualatex
\documentclass[french]{beamer}
\usepackage{polyglossia}
\mode<presentation> {\usetheme{metropolis}}

\newlength{\slw}\setlength{\slw}{160mm}
\newlength{\slh}\setlength{\slh}{90mm}
\geometry{verbose,papersize={\slw,\slh},hmargin=5mm}

\usepackage{fontsize, fix-cm, verbatim}
\usepackage{tikz}
\usetikzlibrary{calendar}

\definecolor{oct}{RGB}{128,128,0}
\definecolor{nov}{RGB}{255,0,255}
\tikzset{
  my calendar/.style={
    day list right,
    % Every day ist just a day box.
    % Its size should be in relation to day xshift or vice versa
    day code={\node[every daybox]{};},
    every daybox/.style={
      minimum width=18mm,
      minimum height=.25ex+15mm+.6666em,
      draw, very thick, rounded corners=3mm,
      name=\pgfcalendarsuggestedname,
      alias=today,
      label={[every day]\tikzdaytext},
      label={[every weekday]north west:\%wt},
    },% the day and the weekday are labels in relation to that daybox
    every day/.style={
      label position=south east, anchor=south east, node font=\Large,
      inner sep=+.5em},
    every weekday/.style={
      label position=north west, anchor=north west, node font=\bfseries,
      inner ysep=+.5em, inner xsep=+.3em},
    every month/.style={at end, above left, inner xsep=+0pt},
    month xshift=2mm,  month yshift=0mm,
    day xshift=18mm+2mm, day yshift=15mm+2mm,
    month line/.style={
      draw, line cap=round, line width=1ex,
      month line \pgfcalendarcurrentmonth/.try,
      to path={([shift={(1ex,1.5ex)}]\tikztostart.north west)
            -- ([shift={(-1ex,1.5ex)}]\tikztotarget.north east) \tikztonodes},
      every to/.append style={edge node={node[every month]{\%mt}}},
    },
    execute at begin day scope={%
      % if it's the first day of the calendar or the first day of the month:
      % remember that daybox as day1
      \ifdate{equals=\pgfcalendarbeginiso}{% first day of calendar?
        \tikzset{every daybox/.append style={alias=day1}}%
      }{%
        \ifdate{day of month=1}{% first day of month?
          \tikzset{every daybox/.append style={alias=day1}}%
        }{}%
      }%
    },
    execute after day scope={%
      % if it's the last day of a month or the last day of the calendar:
      % draw a line to day1
      \ifdate{end of month=1}{% last day of month?
        \draw[month line] (day1) to (today);
      }{%
        \ifdate{equals=\pgfcalendarendiso}{% or even last day of calendar?
          \draw[month line] (day1) to (today);
        }{}%
      }%
    }
  },
  use shortest/.style={day text=\number\%d0\relax},
  %%%
  month colors/.style={
    /utils/exec=\def\pgfmathcounter{0},
    @month colors/.list={#1}},
  @month colors/.code={%
    \edef\pgfmathcounter{\ifnum\pgfinteval{\pgfmathcounter+1}<10 0\fi\pgfinteval{\pgfmathcounter+1}}%
    \tikzset{month line \pgfmathcounter/.append style={color=#1}}},
 }

\renewcommand*\pgfcalendarmonthname[1]{%
  \ifcase#1\or janvier\or février\or mars\or avril\or mai\or juin\or
               juillet\or août\or septembre\or octobre\or novembre\or décembre\fi}
\renewcommand*\pgfcalendarweekdayname[1]{%
  \ifcase#1 lundi\or mardi\or mercredi\or
            jeudi\or vendredi\or samedi\or dimanche\fi}

\begin{document}
\begin{frame}{calendrier de la semaine}
\begin{tikzpicture}[month colors={,,,,,,,,,oct,nov,}]
  \calendar (moncal) [my calendar, use shortest, dates=2023-10-31 to 2023-10-31+6];
\end{tikzpicture}
\end{frame}
\end{document}

输出

在此处输入图片描述

相关内容