将星期几添加到日历

将星期几添加到日历

有没有办法在这个日历中创建周数计数?我有兴趣添加文本来考虑周数,这是否可以使用 for 循环?我尝试为该周创建一个新的计数器,然后在星期一一到就更新它,以便周计数器加 1,但我无法用这种方法让它工作。

有什么建议么?

\documentclass{article}
\usepackage[paperheight=4in,paperwidth=4in]{geometry}
\usepackage{ifthen}
\usepackage{forloop}
\usepackage{nth}    % for 1st, 2nd, 3rd automagically!

% set counters for day and month
\newcounter{daycount}
\newcounter{monthcount}
\setcounter{daycount}{0}
\setcounter{monthcount}{1}
\newcounter{yearcount}
\setcounter{yearcount}{2012}
\newcounter{dispdaycount}    % for Mon, Tue, etc
\setcounter{dispdaycount}{6} % 2012 started on Sunday, the loop increments this by 1
\newcounter{masterDayCount}  % used in the main loop from 1 to 365 (or 366 in a leap year!)

% setup words for the days of the week
\newcommand{\displayday}[1]{%
    \ifthenelse{\equal{#1}{1}}{Mon}{}%
    \ifthenelse{\equal{#1}{2}}{Tue}{}%
    \ifthenelse{\equal{#1}{3}}{Wed}{}%
    \ifthenelse{\equal{#1}{4}}{Thu}{}%
    \ifthenelse{\equal{#1}{5}}{Fri}{}%
    \ifthenelse{\equal{#1}{6}}{Sat}{}%
    \ifthenelse{\equal{#1}{7}}{Sun}{}%
}

% setup words for the months of the year
\newcommand{\displaymonth}[1]{%
    \ifthenelse{\equal{#1}{1}}{Jan}{}%
    \ifthenelse{\equal{#1}{2}}{Feb}{}% 
    \ifthenelse{\equal{#1}{3}}{Mar}{}%
    \ifthenelse{\equal{#1}{4}}{Apr}{}%
    \ifthenelse{\equal{#1}{5}}{May}{}%
    \ifthenelse{\equal{#1}{6}}{Jun}{}%
    \ifthenelse{\equal{#1}{7}}{Jul}{}%
    \ifthenelse{\equal{#1}{8}}{Aug}{}%
    \ifthenelse{\equal{#1}{9}}{Sep}{}%
    \ifthenelse{\equal{#1}{10}}{Oct}{}% 
    \ifthenelse{\equal{#1}{11}}{Nov}{}%
    \ifthenelse{\equal{#1}{12}}{Dec}{}%
}

% check the date to make sure the day is not above the allowed range e.g, there are only 31 days in Jan, not more
% to be used as \checkdate{daycount}{monthcount}
\newcommand{\checkdate}[2]{% 
\ifthenelse{#2=2}
    {%
        % February only has 28 days (or 29 in a leap year like 2012)
        \ifthenelse{#1>29}
            {%
                \addtocounter{daycount}{-29}% 
                \addtocounter{monthcount}{1}%
            }%
            {}%
    }%
    {}%
\ifthenelse{#2=4 \or #2=6 \or #2=9 \or #2=11}
    {%
        % 30 day months, April, May, September, November
        \ifthenelse{#1>30}
            {%
                \addtocounter{daycount}{-30}% 
                \addtocounter{monthcount}{1}%
            }%
            {}%
    }%
    {}%
\ifthenelse{#2=1 \or #2=3 \or #2=5 \or #2=7 \or #2=8 \or #2=10 \or #2=12}
    {%
        % 31 day months
        \ifthenelse{#1>31}
            {%
                \ifthenelse{#2=12}
                {%
                    % if we're in December and the count is above 31, we need to set the month back to Jan
                    \addtocounter{monthcount}{-12}
                }%
                {}%
                \addtocounter{daycount}{-31}%
                \addtocounter{monthcount}{1}%
            }
            {}
    }%
    {}%
}

% worthy quotes
\newcommand{\worthyQuote}[1]{%
\ifthenelse{\equal{#1}{1}}{All we are\ldots}{}% 
\ifthenelse{\equal{#1}{2}}{\dots is dust in the wind dude \ldots}{}% 
\ifthenelse{\equal{#1}{3}}{dust}{}%
\ifthenelse{\equal{#1}{4}}{wind}{}%
\ifthenelse{\equal{#1}{5}}{dude!}{}%
\ifthenelse{\equal{#1}{6}}{Quote 6}{}%
\ifthenelse{\equal{#1}{7}}{Quote 7}{}%
\ifthenelse{\equal{#1}{8}}{Quote 8}{}%
\ifthenelse{\equal{#1}{9}}{Quote 9}{}%
\ifthenelse{\equal{#1}{10}}{Quote 10}{}%
\ifthenelse{\equal{#1}{11}}{Quote 11}{}%     
\ifthenelse{\equal{#1}{12}}{Quote 12}{}%
\ifthenelse{\equal{#1}{13}}{Quote 13}{}%
\ifthenelse{\equal{#1}{14}}{Quote 14}{}%
\ifthenelse{\equal{#1}{15}}{Quote 15}{}%
\ifthenelse{\equal{#1}{16}}{Quote 16}{}%
\ifthenelse{\equal{#1}{17}}{Quote 17}{}%
\ifthenelse{\equal{#1}{18}}{Quote 18}{}%
\ifthenelse{\equal{#1}{19}}{Quote 19}{}%
\ifthenelse{\equal{#1}{20}}{Quote 20}{}%
\ifthenelse{\equal{#1}{21}}{Quote 21}{}%
\ifthenelse{\equal{#1}{22}}{Quote 22}{}% finish these yourself!
}

\begin{document}

\pagestyle{empty}

\forloop{masterDayCount}{1}{\value{masterDayCount} < 367}
    {%
        % new page for a new day
        \clearpage%
        % up the day counters
        \addtocounter{daycount}{1}%
        \addtocounter{dispdaycount}{1}%
        % check that the displayed day counter doesn't go above 7
        \ifthenelse{\thedispdaycount>7}{\setcounter{dispdaycount}{1}}{}%
        % check the daycount for the relevant month
        \checkdate{\thedaycount}{\themonthcount}%
        % change this to suit your own style
        \begin{flushright}
        {\huge\displayday{\thedispdaycount} \nth{\thedaycount}  \displaymonth{\themonthcount} \theyearcount}\\
        {\textit{\worthyQuote{\themasterDayCount}}}
        \end{flushright}
    }

\end{document}

尝试添加周计数器

\newcounter{weekcount}
\setcounter{weekcount}{1}

\forloop{masterDayCount}{1}{\value{masterDayCount} < 367}
    {%
        % new page for a new day
        \clearpage%
        % up the day counters
        \addtocounter{daycount}{1}%
        \addtocounter{dispdaycount}{1}%

        % Here is where I tried to update the week counter
        \ifthenelse{\equal{\displayday{\thedispdaycount}}}{\string Mon}    {% if True
        \addtocounter{weekcount}{1}}

        % check that the displayed day counter doesn't go above 7
        \ifthenelse{\thedispdaycount>7}{\setcounter{dispdaycount}{1}}{}%
        % check the daycount for the relevant month
        \checkdate{\thedaycount}{\themonthcount}%
        % change this to suit your own style
        \begin{flushright}
        {\LARGE \displayday{\thedispdaycount} {\thedaycount}  \displaymonth{\themonthcount} \theyearcount}\\
        {\textit{Semana {\theweekcount}}}\\
        {\textit{\worthyQuote{\themasterDayCount}}}
        \end{flushright}
    }

原始帖子:如何创建每日一页日历模板

答案1

日历模块中没有内置星期日期数字函数。

但我们可以添加一个!

该解决方案使用ISO 8601。 这意味着:

  1. 新的一周从周一开始。
  2. 一年的第一周是 1 月 4 日(= 一年从星期一、星期二、星期三或星期四开始)。
  3. 第 53 周位于平年当闰年在星期四开始/结束时,闰年有第 53 周,即在星期四开始或结束。
  4. 没有第 0 周。

我的解决方案将计算结果存储在一个名为的宏中,\pgfcalendar@weeknumber@<year>这样它就不需要在一年内计算 366 次。(不过,它\pgfcalendar也不只是增加天数/月份/年份/星期几,而且每次都进行大量计算。)

由于我们需要找出前一年的周数或检查 3,因此一年的最后一天和第一天涉及一些条件。

代码是我的一部分tikz-ext包。它提供了 LaTeX 包pgfcalendar-ext和 TikZ 库ext.calendar-plus

如果您确实想向上计数,我建议在一年的第一天并且计数达到 53 时使用我的解决方案(因为有时 52 之后会出现 1)。


宏:

\pgfcalendarjulianyeartoweek{<julian count>}{<year>}{<week number count>}

参数为

  1. 使用儒略日期进行计数(pgfcalendar这里面是\pgfcalendarcurrentjulian
  2. 年份 (是的,我们可以从 1 开始计算。同样,这可行,在里面pgfcalendar我们可以使用\pgfcalendarcurrentyear)
  3. 将周数计数

这是一个如何在简单程序中访问它的示例\pgfcalendar

下面,我通过周数展示了我的库的完整用法(包括适当的样式和新的速记)。

代码

\documentclass{article}
\usepackage{pgfcalendar-ext}
\newcount\myCount
\begin{document}
\pgfcalendar{}{2022-01-01}{2022-12-31}{
  Julian day \the\pgfcalendarcurrentjulian\space is
  \pgfcalendarcurrentday.\,\pgfcalendarcurrentmonth.\,\pgfcalendarcurrentyear\space has week number
  \pgfcalendarjulianyeartoweek{\pgfcalendarcurrentjulian}{\pgfcalendarcurrentyear}{\myCount}%
  \the\myCount\par}
\end{document}

输出

在此处输入图片描述

代码

\documentclass[tikz]{standalone}
\usetikzlibrary{ext.calendar-plus}
\begin{document}
\small\sffamily
\colorlet{darkgreen}{green!50!black}%
\colorlet{darkblue}{blue!50!black}%
\foreach \y in {2019,...,2025}{%
\begin{tikzpicture}
  \calendar[
     dates/.expanded=\y-01-01 to \the\numexpr\y+1\relax-12-31, week list,
     month label left, month yshift=0pt, every month/.append style={xshift=+-4ex},
     month text=\textcolor{darkgreen}{\%mt},
     every week/.style={xshift=+-4ex,anchor=base east},
     week text={\textcolor{darkblue}{\%n-}},
     execute before day scope={
       \ifdate{equals=\pgfcalendarbeginiso}{
         \node[anchor=south, xshift={\pgfkeysvalueof{/tikz/day xshift}*2},
           yshift={1.1*\pgfkeysvalueof{/tikz/day yshift}}]{\bfseries\Large\y};}{}%
       \ifdate{Monday, equals=\pgfcalendarbeginiso}{%
         \pgfkeysvalueof{/tikz/weeknumber code}%
       }{}%enter image description here
     },
%     days={label={[inner sep=+0pt,font=\tiny,gray]above:\%n-}}% shows weeknumber
   ]
   if (Sunday) [black!50] if (Saturday) [black!75]
   if (
     and={
       day of month=1,
       not={equals=\pgfcalendarbeginiso},
       not=Monday
     }) [days={append after command={edge[fill, darkgreen, to path={
       (\tikztostart.north) -| (\tikztostart.west) .. controls
       ([shift=(-45:.5mm)]\tikztostart.north west) .. cycle}] ()}}];
\end{tikzpicture}}
\end{document}

输出

在此处输入图片描述

还有一张(这些图片很大)!

相关内容