如何向 tikz-calendar 添加带有周引用的列

如何向 tikz-calendar 添加带有周引用的列

我想创建一个像这样的日历: 在此处输入图片描述 我发现了一个代码这对我来说没问题(一旦修改)但我不知道如何添加左列字母 ABCD 来限定这个 4 周周期中的周数。

\documentclass[french]{standalone}% 
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{tikz}
    \usetikzlibrary{calendar}
\usepackage[active,tightpage]{preview}
\usepackage{babel}
\PreviewEnvironment{tikzpicture}
\setlength\PreviewBorder{5pt}%

\usetikzlibrary{positioning,calendar}
\usetikzlibrary{decorations.markings}

\newcommand{\calrow}[1]{%\node[anchor=base left=of lun](lun){A};
\node[anchor=base east](lun){l};
\node[base right=of lun](mar){m}; \node[base right=of mar](mer){m};
\node[base right=of mer](jeu){j}; \node[base right=of jeu](ven){v};
\node[base right=of ven](sam){s}; \node[base right=of sam](dim){d};
\node[darkgreen,above=of jeu]{\textbf{#1}};}

\newcommand{\calperiod}[1]{\calendar[dates=\the\year-#1-01 to \the\year-#1-last]
    if(Sunday) [black!50] \holidays;}

\newcommand{\holidays}{% holidays
if (equals=01-01) [black!50]%
if (equals=04-13) [black!50]%
if (equals=05-01) [black!50]%
if (equals=05-08) [black!50]%
if (equals=05-21) [black!50]%
if (equals=06-01) [black!50]%
if (equals=08-15) [black!50]%
if (equals=11-01) [black!50]%
if (equals=11-11) [black!50]%
if (equals=12-25) [black!50]%
}

\colorlet{darkgreen}{green!50!black}

\begin{document}
\begin{tikzpicture}[every calendar/.style={week list}]
\sffamily

\matrix[%
row 1/.style={darkgreen,node distance=.3ex},%
row 3/.style={darkgreen,node distance=.3ex},
row 5/.style={darkgreen,node distance=.3ex},
row 7/.style={darkgreen,node distance=.3ex},
column sep=3ex,%
draw=darkgreen,thick,rounded corners=5pt,%
postaction={decorate,decoration={markings,mark=at position 0.51 with
{\node[fill=white,text=darkgreen,font={\bfseries\Large}] (year) 
{2020};}}}
]{%
\calrow{Janvier} & \calrow{Février} & \calrow{Mars}\\
\calperiod{01} & \calperiod{02} & \calperiod{03}\\
\calrow{Avril} & \calrow{Mai} & \calrow{Juin}\\ 
\calperiod{04} & \calperiod{05} & \calperiod{06}\\
\calrow{Juillet} & \calrow{Août} & \calrow{Septembre}\\
\calperiod{07} & \calperiod{08} & \calperiod{09}\\[1ex]
\calrow{Octobre} & \calrow{Novembre} & \calrow{Décembre}\\
\calperiod{10} & \calperiod{11} & \calperiod{12}\\
};
\end{tikzpicture}
\end{document}

我想知道如何添加左列,如果可能的话,从我改编的代码开始。

答案1

一个计数器(以及一个可以移除的作弊计数器)、一些模数算法、一些 if 和密钥execute at begin day scope似乎可以让你得到你想要的东西。

\documentclass[french]{standalone}% 
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{tikz}
\usepackage[active,tightpage]{preview}
\usepackage{babel}
\PreviewEnvironment{tikzpicture}
\setlength\PreviewBorder{5pt}%
\usetikzlibrary{calendar,babel}

\usetikzlibrary{positioning,calendar}
\usetikzlibrary{decorations.markings}

\newcommand{\calrow}[1]{%\node[anchor=base left=of lun](lun){A};
\node[anchor=base east,xshift=-0.15em](lun){l};
\node[base right=0.3em of lun](mar){m}; \node[base right=0.3em of mar](mer){m};
\node[base right=0.3em of mer](jeu){j}; \node[base right=0.3em of jeu](ven){v};
\node[base right=0.3em of ven](sam){s}; \node[base right=0.3em of sam](dim){d};
\node[darkgreen,above=of jeu]{\textbf{#1}};}

\newcounter{ABCD}
\newcounter{spur}
\newcommand{\calperiod}[2][\currentyear]{\calendar[dates=\currentyear-#2-01 to \currentyear-#2-last,
execute at begin day scope={\ifdate{Monday}{
\pgfmathtruncatemacro{\itest}{\pgfcalendarcurrentday}
\pgfmathtruncatemacro{\iABCD}{Mod(\value{spur},4)+1} 
\setcounter{ABCD}{\iABCD}
\ifnum\itest<8
\ifnum\itest>1
\node at (-2em,1.3em) [anchor=base east,text=darkgreen] {\Alph{ABCD}};
\fi
\fi
\stepcounter{spur}
\pgfmathtruncatemacro{\iABCD}{Mod(\value{spur},4)+1} 
\setcounter{ABCD}{\iABCD}
\node at (-2em,0em) [anchor=base east,text=darkgreen] {\Alph{ABCD}};}}]
    if(Sunday) [black!50] \holidays;}

\newcommand{\holidays}{% holidays
if (equals=01-01) [black!50]%
if (equals=04-13) [black!50]%
if (equals=05-01) [black!50]%
if (equals=05-08) [black!50]%
if (equals=05-21) [black!50]%
if (equals=06-01) [black!50]%
if (equals=08-15) [black!50]%
if (equals=11-01) [black!50]%
if (equals=11-11) [black!50]%
if (equals=12-25) [black!50]%
}

\colorlet{darkgreen}{green!50!black}

\begin{document}
\begin{tikzpicture}[every calendar/.style={week list},current year/.store in=\currentyear,
current year=2020]
\sffamily

\matrix[%
row 1/.style={darkgreen,node distance=.3ex},%
row 3/.style={darkgreen,node distance=.3ex},
row 5/.style={darkgreen,node distance=.3ex},
row 7/.style={darkgreen,node distance=.3ex},
column sep=3ex,%
draw=darkgreen,thick,rounded corners=5pt,%
postaction={decorate,decoration={markings,mark=at position 0.51 with
{\node[fill=white,text=darkgreen,font={\bfseries\Large}] (year) 
{\currentyear};}}}
]{%
\calrow{Janvier} & \calrow{F\'evrier} & \calrow{Mars}\\
\calperiod{01} & \calperiod{02} & \calperiod{03}\\
\calrow{Avril} & \calrow{Mai} & \calrow{Juin}\\ 
\calperiod{04} & \calperiod{05} & \calperiod{06}\\
\calrow{Juillet} & \calrow{Ao\^ut} & \calrow{Septembre}\\
\calperiod{07} & \calperiod{08} & \calperiod{09}\\[1ex]
\calrow{Octobre} & \calrow{Novembre} & \calrow{D\'ecembre}\\
\calperiod{10} & \calperiod{11} & \calperiod{12}\\
};
\end{tikzpicture}
\end{document}

在此处输入图片描述

附录. 钛Zling 日历。

\documentclass[tikz,border=3mm]{standalone}
\usepackage{tikzlings}
\newcounter{Sunday}
\usetikzlibrary{positioning,calendar,backgrounds}
\renewcommand\familydefault\sfdefault
\colorlet{darkgreen}{green!50!black}
\colorlet{holiday}{black!50}
\newcommand{\calrow}[1]{\node[anchor=base east](Mon){M};
\node[base right=of Mon](Tue){T}; \node[base right=of Tue](Wed){W};
\node[base right=of Wed](Thu){T}; \node[base right=of Thu](Fri){F};
\node[base right=of Fri](Sat){S}; \node[base right=of Sat](Sun){S};
\node[darkgreen, above=of Thu]{\textbf{#1}};}

\newcommand{\calperiod}[2][\currentyear]{%
  \calendar[dates=\currentyear-#2-01 to \currentyear-#2-last,
  execute at begin day scope={\ifdate{Sunday}{\stepcounter{Sunday}
   \node[anchor=base east] (SD-\number\value{Sunday}){};}}]
    if (Sunday) [holiday] \holidays;}
\edef\currentyear{\the\year}
\newcommand{\holidays}{% 
if (equals=01-01) [holiday]%
if (equals=01-06) [holiday]%
if (equals=05-01) [holiday]%
if (equals=08-15) [holiday]%
if (equals=11-01) [holiday]%
if (equals=12-06) [holiday]%
if (equals=12-25) [holiday]%
if (equals=12-26) [holiday]%
}
\tikzset{tikzling/.style={execute at begin day scope={\typeout{X}}}}
\begin{document}
\begin{tikzpicture}[every calendar/.style={week list},
year label/.style={
  fill=white,text=darkgreen,font=\bfseries\Large
}, current year/.store in=\currentyear,
current year=2019]
\matrix[%
row 1/.style={darkgreen,node distance=.3ex},%
row 3/.style={darkgreen,node distance=.3ex},
row 5/.style={darkgreen,node distance=.3ex},
row 7/.style={darkgreen,node distance=.3ex},
column sep=1ex,%
draw=darkgreen,thick,rounded corners=5pt,%
append after command={ 
  \pgfextra{\edef\matrixname{\tikzlastnode}}
  node [year label/.try, right=1ex of \matrixname.south west] {\currentyear}
  node [year label/.try, right=1ex of \matrixname.north west] {\currentyear}
  node [year label/.try, left=1ex of \matrixname.south east] {\currentyear}
  node [year label/.try, left=1ex of \matrixname.north east] {\currentyear}
}
]{%

% first row: week day and month
\calrow{January} & \calrow{February} & \calrow{March} \\
\calperiod{01} & \calperiod{02} & \calperiod{03} \\[1ex]

% second row: calendar
\calrow{April} & \calrow{May} & \calrow{June} \\
\calperiod{04} & \calperiod{05} & \calperiod{06} \\[1ex]

% third row: week day and month
\calrow{July} & \calrow{August} & \calrow{September} \\
\calperiod{07} & \calperiod{08} & \calperiod{09} \\[1ex]

% forth row: calendar
\calrow{October} & \calrow{November} & \calrow{December} \\
\calperiod{10} & \calperiod{11} & \calperiod{12} \\[1ex]\\
};
\begin{scope}[on background layer]
\foreach \X in {1,...,\number\value{Sunday}}
{\tikzling[shift={(SD-\X.south west)},scale=0.2]}
\end{scope}
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容