如何迭代一年中的几天和几周

如何迭代一年中的几天和几周

感谢这个社区的帮助,我成功创建了一个数字规划器模板页面。

\documentclass{article}
\usepackage[landscape, margin=0.5cm]{geometry}
\usepackage{tabularx}
\usepackage[table, svgnames]{xcolor}
\usepackage{advdate}
\usepackage[dayofweek]{datetime}
\usepackage{pgffor}
\newcommand{\grayline}{\arrayrulecolor{lightgray}\cline{1-5}\arrayrulecolor{white}}
\newcommand{\Hsquare}{%
  \text{\fboxsep=0pt\fbox{\rule{0pt}{2ex}\rule{2ex}{0pt}}}%
}
\newcount\dayscnt
\dayscnt=1

\pagecolor{black}
\color{white}
\setlength{\extrarowheight}{10pt}
\ThisYear{2021}
\ThisMonth{1} % Start in January
\ThisDay{1} % Set the day number to zero
\newcounter{mycntr}
\mycntr=1
\newcounter{rownumber}
\begin{document}
\loop
    \begin{minipage}[b]{0.475\linewidth}
    \setcounter{rownumber}{0}
    \def\fillfirsttable{}%
    {
        \loop\ifnum\therownumber<12
        \addtocounter{rownumber}{1}
        \expandafter\def\expandafter\fillfirsttable\expandafter{%
            \fillfirsttable
            & & & & \\
            \hline
            & & & & \\
            \grayline
        }%
        \repeat
    }
    \noindent
    \begin{tabularx}{\linewidth}{wc{0.5cm}|X|X|X|X|}
        \cline{1-5}
        \multicolumn{5} {r|} {Date: \AdvanceDate[\value{mycntr}]\today\stepcounter{mycntr}}\\
        \hline
        \fillfirsttable
    \end{tabularx}
    \end{minipage}
    \hfill
    \begin{minipage}[b]{0.475\linewidth}
    \par\noindent\rule{\textwidth}{0.4pt}\\
    \par\noindent\rule{\textwidth}{0.4pt}\\
    \par\noindent\rule{\textwidth}{0.4pt}\\
    \par\noindent\rule{\textwidth}{0.4pt}\\
    \par\noindent\rule{\textwidth}{0.4pt}\\
    \par\noindent\rule{\textwidth}{0.4pt}\\
    Shutdown complete: 

    \setcounter{rownumber}{0}
    \def\fillsecondtable{}%
    {
        \loop\ifnum\therownumber<10
        \addtocounter{rownumber}{1}
        \expandafter\def\expandafter\fillsecondtable\expandafter{%
            \fillsecondtable
            & \\ \hline
        }%
        \repeat
    }
    \noindent
    \begin{tabularx}{\linewidth}{X|X}
    TASKS: & IDEAS:  \\ \hline
    \fillsecondtable
    \end{tabularx}
    \end{minipage}

\advance \dayscnt 1
\ifnum \dayscnt<10
\repeat

\end{document}

现在我想创建一个文档,其中每一页代表特定的日期,并且已经填写了日期和周数。

我不确定 Latex 是否有计算日期和星期的功能。也许我可以在构建时以某种方式将它们作为参数传递?

EDIT1:我认为唯一的问题是嵌套循环......

答案1

我使用pgffor循环并定义了一个新命令来排版整个日历页面(主要是为了便于阅读),然后使用\foreach和您的提示来\AdvanceDate生成这个。

\documentclass{article}
\usepackage[landscape, margin=0.5cm]{geometry}
\usepackage{tabularx}
\usepackage[table, svgnames]{xcolor}
\usepackage{amsmath}
\newcommand{\grayline}{\arrayrulecolor{lightgray}\cline{1-5}\arrayrulecolor{white}}
\newcommand{\Hsquare}{%
    \text{\fboxsep=0pt\fbox{\rule{0pt}{2ex}\rule{2ex}{0pt}}}%
}
\def\tabularxcolumn#1{m{#1}}

%% use pgffor package for the loop
\usepackage{pgffor}
\usepackage{advdate}

%% typeset a whole calendar page
\newcounter{rownumber}
\def\calendarpage#1{
    \begin{minipage}[b]{0.475\linewidth}
        \setcounter{rownumber}{0}
        \def\fillfirsttable{}%
        \loop\ifnum\therownumber<12
        \addtocounter{rownumber}{1}
        \expandafter\def\expandafter\fillfirsttable\expandafter{%
            \fillfirsttable
            & & & & \\
            \hline
            & & & & \\
            \grayline
        }%
        \repeat
        \noindent
        \begin{tabularx}{\linewidth}{wc{0.5cm}|X|X|X|X|}
            \cline{1-5}
            \multicolumn{5} {r|} {Date: \AdvanceDate[#1]\today}\\
            \hline
            \fillfirsttable
        \end{tabularx}
    \end{minipage}
    \hfill
    \begin{minipage}[b]{0.475\linewidth}
        Reflections:
        \par\noindent\rule{\textwidth}{0.4pt}\\
        \par\noindent\rule{\textwidth}{0.4pt}\\
        \par\noindent\rule{\textwidth}{0.4pt}\\
        \par\noindent\rule{\textwidth}{0.4pt}\\
        \par\noindent\rule{\textwidth}{0.4pt}\\
        \par\noindent\rule{\textwidth}{0.4pt}\\
        Shutdown complete: \Hsquare 
        
        \setcounter{rownumber}{0}
        \def\fillsecondtable{}%
        \loop\ifnum\therownumber<10
        \addtocounter{rownumber}{1}
        \expandafter\def\expandafter\fillsecondtable\expandafter{%
            \fillsecondtable
            \Hsquare & \\ \hline
        }%
        \repeat
        \noindent
        \begin{tabularx}{\linewidth}{X|X}
            TASKS: & IDEAS:  \\ \hline
            \fillsecondtable
        \end{tabularx}
    \end{minipage}
}

\begin{document}
    
    \pagecolor{black}
    \color{white}
    \setlength{\extrarowheight}{10pt}

    \foreach \i in {1,...,31}{
        \calendarpage{\i}
    }
\end{document}

相关内容