生成未来 10 年的日历

生成未来 10 年的日历

我使用以下修改后的代码(来自 pgf 手册)来生成日历。

是否可以修改代码以生成未来 10 年的日历,每个日历都采用单独的十二面体模型。

\documentclass[10pt,a4paper]{article}
\usepackage{geometry}
\geometry{a4paper, left=4mm, right=10mm, top=20mm, bottom=5mm}
\usepackage{tikz}
\usetikzlibrary{calendar,folding}
\usepackage{verbatim}
\begin{document}
\sffamily\scriptsize
\hskip -.4cm
\begin{tikzpicture}[transform shape,
scale=1.25,%to make text fit the 2.5cm-line-length face
every calendar/.style={
at={(-8ex,4ex)},
week list,
month label above centered, 
month text=\bfseries\bf\textcolor{blue}{\%mt} \textcolor{green!50!black}{\%y0},
if={(Sunday) [purple]}
}]
\tikzfoldingdodecahedron[
folding line length=2.5cm,
face 1={ \calendar [dates=\the\year-01-01 to \the\year-01-last];},
face 2={ \calendar [dates=\the\year-02-01 to \the\year-02-last];},
face 3={ \calendar [dates=\the\year-03-01 to \the\year-03-last];},
face 4={ \calendar [dates=\the\year-04-01 to \the\year-04-last];},
face 5={ \calendar [dates=\the\year-05-01 to \the\year-05-last];},
face 6={ \calendar [dates=\the\year-06-01 to \the\year-06-last];},
face 7={ \calendar [dates=\the\year-07-01 to \the\year-07-last];},
face 8={ \calendar [dates=\the\year-08-01 to \the\year-08-last];},
face 9={ \calendar [dates=\the\year-09-01 to \the\year-09-last];},
face 10={\calendar [dates=\the\year-10-01 to \the\year-10-last];},
face 11={\calendar [dates=\the\year-11-01 to \the\year-11-last];},
face 12={\calendar [dates=\the\year-12-01 to \the\year-12-last];}
];
\end{tikzpicture}
\end{document}

在此处输入图片描述

答案1

将您想要重复的所有内容包装在宏中(可选但绝对是一种更简洁的方法)并使用以下方法重复foreach

\documentclass[10pt,a4paper]{article}
\usepackage{tikz}
\usepackage{geometry}
\geometry{a4paper, left=4mm, right=10mm, top=20mm, bottom=5mm}
\usetikzlibrary{calendar,folding}

\NewDocumentCommand{\dodecalendar}{m}{
    \begin{tikzpicture}[transform shape,
        scale=1.25,%to make text fit the 2.5cm-line-length face
        every calendar/.style={
        at={(-8ex,4ex)},
        week list,
        month label above centered, 
        month text=\bfseries\bf\textcolor{blue}{\%mt} \textcolor{green!50!black}{\%y0},
        if={(Sunday) [purple]}
        }]
        \tikzfoldingdodecahedron[
        folding line length=2.5cm,
        face 1={ \calendar [dates=#1-01-01 to #1-01-last];},
        face 2={ \calendar [dates=#1-02-01 to #1-02-last];},
        face 3={ \calendar [dates=#1-03-01 to #1-03-last];},
        face 4={ \calendar [dates=#1-04-01 to #1-04-last];},
        face 5={ \calendar [dates=#1-05-01 to #1-05-last];},
        face 6={ \calendar [dates=#1-06-01 to #1-06-last];},
        face 7={ \calendar [dates=#1-07-01 to #1-07-last];},
        face 8={ \calendar [dates=#1-08-01 to #1-08-last];},
        face 9={ \calendar [dates=#1-09-01 to #1-09-last];},
        face 10={\calendar [dates=#1-10-01 to #1-10-last];},
        face 11={\calendar [dates=#1-11-01 to #1-11-last];},
        face 12={\calendar [dates=#1-12-01 to #1-12-last];}
        ];
    \end{tikzpicture}
}

\begin{document}
\sffamily\scriptsize
\foreach \year in {2021,...,2031}{
    \dodecalendar{\year}
}
\end{document}

相关内容