升级我的每周日历

升级我的每周日历

大家好,我根据这个制定了一个每周计划邮政我想使它变得更好,更易于使用。

以下是代码:

\documentclass[a5paper]{article}
\usepackage[utf8]{inputenc}
\usepackage{lmodern}
\usepackage{tikz}
\usetikzlibrary{positioning, calendar, shapes.misc, fit, shapes}
\usepackage[margin=0.5cm]{geometry}
\usepackage[spanish]{babel}
\usepackage[spanish]{translator}
\usepackage{palatino} 
\newcommand{\markday}[3]{if (equals=#1-#2-#3) {\draw (0.04,0.109) circle (3pt);}}
\newcommand{\calendar}[3]{\begin{tikzpicture}
  \calendar
  [
    dates=#1-#2-01 to #1-#2-last,
    week list,inner sep=2pt,month label above centered,
    month text=\%mt \%y0
  ]
  if (at most=#1-#2-#3) [nodes={strike out,draw}]
  if (weekend)            [black!50,nodes={draw=none}]
  ;
\end{tikzpicture}}
\newenvironment{yeramonth}[4]{%
\begin{tikzpicture}[%
        inner sep=1 pt,
        dayname/.style={%
            node font=\footnotesize, 
        },
        daynumber/.style={%
            anchor=north east,
            node font=\normalsize\bfseries, 
        },
        time/.style={%
            node font=\tiny, 
        },
        activitie/.style={%
            anchor=north east,
            node font=\scriptsize,
            text width=8 cm,
        },
        xscale = 10,
        yscale=-3
    ]
    
    \node (year_number) at (-0.15,1) [anchor = south east, minimum height = 2em] {#1};
    \node [base right = 1em of year_number, anchor=base west, node font=\large] {#2};
    \draw (-0.25,1) -- (0.6,1);
    \node (calendar) at (0.6,1.7) [daynumber] {};
    \node [base right = 2em of calendar, anchor=base west] [dayname] {\calendar{#1}{#3}{#4}}; 
\end{tikzpicture}
}



\begin{document}
\itshape
\begin{tikzpicture}[%
        inner sep=1 pt,
        dayname/.style={%
            node font=\footnotesize, 
        },
        daynumber/.style={%
            anchor=north east,
            node font=\normalsize\bfseries, 
        },
        time/.style={%
            node font=\tiny, 
        },
        activitie/.style={%
            anchor=north east,
            node font=\scriptsize,
            text width=8 cm,
        },
        xscale = 10,
        yscale=-3
    ]

    \node (saturday_number) at (-0.1,5.1) [daynumber] {14};
    \node [base right = 1em of saturday_number, anchor=base west] [dayname] {Sábado};
    \node (saturday) at (0.67,5.23) [activitie] {hola};
    \node (saturday) at (-0.2,5.25) [time] {11:00};
    \node [draw,ellipse,fit={(saturday)}] {};
    \node (saturday) at (0.67,5.38) [activitie] {hola};
    \node (saturday) at (-0.2,5.4) [time] {12:10};
    \node [draw,ellipse,fit={(saturday)}] {};
    \node (saturday) at (0.67,5.53) [activitie] {hola};
    \node (saturday) at (-0.2,5.55) [time] {13:20};
    \node [draw,ellipse,fit={(saturday)}] {};
    \node (saturday) at (0.67,5.68) [activitie] {hola};
    \node (saturday) at (-0.2,5.7) [time] {17:00};
    \node [draw,ellipse,fit={(saturday)}] {};
    \node (saturday) at (0.67,5.83) [activitie] {hola};
    \node (saturday) at (-0.2,5.85) [time] {18:10};
    \node [draw,ellipse,fit={(saturday)}] {};
    \node (saturday) at (0.67,5.98) [activitie] {hola};
    \node (saturday) at (-0.2,6) [time] {19:20};
    \node [draw,ellipse,fit={(saturday)}] {};
    \node (saturday) at (0.67,6.13) [activitie] {hola};
    \node (saturday) at (-0.2,6.15) [time] {20:30};
    \node [draw,ellipse,fit={(saturday)}] {};

    \node (sunday_number) at (0.45,5.1) [daynumber] {15};
    \node [base right = 1em of sunday_number, anchor=base west] [dayname] {Domingo};
    \node (sunday) at (1.22,5.23) [activitie] {hola};
    \node (sunday) at (0.35,5.25) [time] {11:00};
    \node [draw,ellipse,fit={(sunday)}] {};
    \node (sunday) at (1.22,5.38) [activitie] {hola};
    \node (sunday) at (0.35,5.4) [time] {12:10};
    \node [draw,ellipse,fit={(sunday)}] {};
    \node (sunday) at (1.22,5.53) [activitie] {hola};
    \node (sunday) at (0.35,5.55) [time] {13:20};
    \node [draw,ellipse,fit={(sunday)}] {};
    \node (sunday) at (1.22,5.68) [activitie] {hola};
    \node (sunday) at (0.35,5.7) [time] {17:00};
    \node [draw,ellipse,fit={(sunday)}] {};
    \node (sunday) at (1.22,5.83) [activitie] {hola};
    \node (sunday) at (0.35,5.85) [time] {18:10};
    \node [draw,ellipse,fit={(sunday)}] {};
    \node (sunday) at (1.22,5.98) [activitie] {hola};
    \node (sunday) at (0.35,6) [time] {19:20};
    \node [draw,ellipse,fit={(sunday)}] {};
    \node (sunday) at (1.22,6.13) [activitie] {hola};
    \node (sunday) at (0.35,6.15) [time] {20:30};
    \node [draw,ellipse,fit={(sunday)}] {};



    \node (friday_number) at (-0.1,4.3) [daynumber] {13};
    \node [base right = 1em of friday_number, anchor=base west] [dayname] {Viernes};
    \node (friday) at (0.67,4.43) [activitie] {hola};
    \node (friday) at (-0.2,4.45) [time] {17:00};
    \node [draw,ellipse,fit={(friday)}] {};
    \node (friday) at (0.67,4.58) [activitie] {hola};
    \node (friday) at (-0.2,4.6) [time] {18:10};
    \node [draw,ellipse,fit={(friday)}] {};
    \node (friday) at (0.67,4.73) [activitie] {hola};
    \node (friday) at (-0.2,4.75) [time] {19:20};
    \node [draw,ellipse,fit={(friday)}] {};
    \node (friday) at (0.67,4.88) [activitie] {hola};
    \node (friday) at (-0.2,4.9) [time] {20:30};
    \node [draw,ellipse,fit={(friday)}] {};
    \draw (-0.25,5.05) -- (0.99,5.05);

    \node (thursday_number) at (-0.1,3.5) [daynumber] {12};
    \node [base right = 1em of thursday_number, anchor=base west] [dayname] {Jueves};
    \node (thursday) at (0.67,3.63) [activitie] {hola};
    \node (thursday) at (-0.2,3.65) [time] {17:00};
    \node [draw,ellipse,fit={(thursday)}] {};
    \node (thursday) at (0.67,3.78) [activitie] {hola};
    \node (thursday) at (-0.2,3.8) [time] {18:10};
    \node [draw,ellipse,fit={(thursday)}] {};
    \node (thursday) at (0.67,3.93) [activitie] {hola};
    \node (thursday) at (-0.2,3.95) [time] {19:20};
    \node [draw,ellipse,fit={(thursday)}] {};
    \node (thursday) at (0.67,4.08) [activitie] {hola};
    \node (thursday) at (-0.2,4.1) [time] {20:30};
    \node [draw,ellipse,fit={(thursday)}] {};
    \draw (-0.25,4.25) -- (0.99,4.25);

    \node (wednesday_number) at (-0.1,2.7) [daynumber] {11};
    \node [base right = 1em of wednesday_number, anchor=base west] [dayname] {Miércoles};
    \node (wedneday) at (0.67,2.83) [activitie] {hola};
    \node (wednesday) at (-0.2,2.85) [time] {17:00};
    \node [draw,ellipse,fit={(wednesday)}] {};
    \node (wedneday) at (0.67,2.98) [activitie] {hola};
    \node (wednesday) at (-0.2,3) [time] {18:10};
    \node [draw,ellipse,fit={(wednesday)}] {};
    \node (wedneday) at (0.67,3.13) [activitie] {hola};
    \node (wednesday) at (-0.2,3.15) [time] {19:20};
    \node [draw,ellipse,fit={(wednesday)}] {};
    \node (wedneday) at (0.67,3.28) [activitie] {hola};
    \node (wednesday) at (-0.2,3.3) [time] {20:30};
    \node [draw,ellipse,fit={(wednesday)}] {};
    \draw (-0.25,3.45) -- (0.99,3.45);

    \node (tuesday_number) at (-0.1,1.85) [daynumber] {10};
    \node [base right = 1em of tuesday_number, anchor=base west] [dayname] {Martes};
    \node (tuesday) at (0.67,2.03) [activitie] {hola};
    \node (tuesday) at (-0.2,2.05) [time] {17:00};
    \node [draw,ellipse,fit={(tuesday)}] {};
    \node (tuesday) at (0.67,2.18) [activitie] {hola};
    \node (tuesday) at (-0.2,2.2) [time] {18:10};
    \node [draw,ellipse,fit={(tuesday)}] {};
    \node (tuesday) at (0.67,2.33) [activitie] {hola};
    \node (tuesday) at (-0.2,2.35) [time] {19:20};
    \node [draw,ellipse,fit={(tuesday)}] {};
    \node (tuesday) at (0.67,2.48) [activitie] {hola};
    \node (tuesday) at (-0.2,2.5) [time] {20:30};
    \node [draw,ellipse,fit={(tuesday)}] {};
    \draw (-0.25,2.65) -- (0.99,2.65);
    
    \node (monday_number) at (-0.1,1.05) [daynumber] {9};
    \node [base right = 1em of monday_number, anchor=base west] [dayname] {Lunes};
    \node (monday) at (0.67,1.18) [activitie] {hola};
    \node (monday) at (-0.2,1.2) [time] {17:00};
    \node [draw,ellipse,fit={(monday)}] {};
    \node (monday) at (0.67,1.33) [activitie] {hola};
    \node (monday) at (-0.2,1.35) [time] {18:10};
    \node [draw,ellipse,fit={(monday)}] {};
    \node (monday) at (0.67,1.48) [activitie] {hola};
    \node (monday) at (-0.2,1.5) [time] {19:20};
    \node [draw,ellipse,fit={(monday)}] {};
    \node (monday) at (0.67,1.63) [activitie] {hola};
    \node (monday) at (-0.2,1.65) [time] {20:30};
    \node [draw,ellipse,fit={(monday)}] {};
    \draw (-0.25,1.8) -- (0.99,1.8);
    
    \node (year_number) at (-0.15,1) [anchor = south east, minimum height = 2em] {2022};
    \node [base right = 1em of year_number, anchor=base west, node font=\large] {Diciembre};
    \draw (-0.25,1) -- (0.6,1);
    \node (calendar) at (0.6,1.7) [daynumber] {};
    \node [base right = 2em of calendar, anchor=base west] [dayname] {\calendar{2022}{12}{5}};

\end{tikzpicture}

\end{document}

输出如下:

在此处输入图片描述 在这张图片中,我使用 定义了一个星期tikz-calendar,但问题是,每次我必须写一个新的星期时,使用它的代码太多了(这个日历的想法是在乳胶中使用,而不是打印它),这就是为什么我想要定义一个newenviroment(你可以在上面的代码中看到我是如何定义这个环境的):

\begin{yeramonth}{2022}{Diciembre}{12}{9}

\end{yeramonth}

这个环境产生了这个:

在此处输入图片描述

它只是类似于标题的东西,因为我无法创建一整周的环境,这是我正在寻找的,以使它更加有用

然后是总日历,您可以使用以下命令标记某一天\markday 这是代码:

\begin{tikzpicture}[xscale=1, yscale=1.8, rotate= 90]
\tiny
\calendar [dates=2023-01-01 to 2023-12-31,
             month list, month label left, month yshift=6em]
            if (weekend)            [black!50,nodes={draw=none}]
            \markday{2023}{3}{5}
            \markday{2023}{3}{8};
\end{tikzpicture}

输出结果如下:

在此处输入图片描述

在这里,如果能够在月份标签下面标明圆环所指的日期是什么事件,那就太棒了,也许可以用一个multicol和说服力来表达。itemize

继续这篇帖子,我请求帮助创建一个周布局环境(并且能够书写,因为我想在电脑上使用它),能够用日期列表指示圆圈中的事件是什么,以及原始帖子中要求的制作一些帮助行(在这种情况下可以放在周末下面,也可以在上面书写)

提前谢谢您,很抱歉,时间太长了。

答案1

从简单开始。

让我们创建包含七天的页面。

为了为我们的键和样式拥有自己的自定义命名空间,我正在使用

\amcalset

这很像\tikzset,但是/tikz我们的命名空间不是/tikz/amcal

在这个命名空间中,我声明了以下键:

  • every matrix
  • weekday
  • weekend

每天我们使用一个 PGF/TikZ 矩阵。(我们也可以使用,tabularx但省略号会更麻烦。)

weekdayweekend设置相应的day code(通常,这将是某种形式,\node … {\daytext};但我们将忽略所有这些)。

工作日在底部获得了额外的垂直空间。列获得的宽度minimum width可能比我们实际需要的要多一点,但我们知道它们的确切宽度,并且可以简单地计算出最后一列的剩余宽度。


由于 PGF/TikZ 考虑了边界框的线宽,因此我们将overlay椭圆节点设置为outer sep = 0更好的边界框

append after command=(\tikzlastnode.west)(\tikzlastnode.east)(\tikzlastnode.south)(\tikzlastnode.north)

因此第一列实际上很minimum width宽。

整个图片也需要做类似的事情,这里我使用了 和 键 trim lefttrim right这样我们就不会得到大约 0.4 pt(默认线宽)的满满的水平盒。这 0.4 pt 是因为矩阵顶部的水平线而添加的。

对于周末,我们将\linewidth第三列的宽度计算减半,对于星期日(\pgfcalendarcurrentweekday = 6),我们也改变矩阵的位置。

说到放置。如您所见,我没有使用任何day list downward或类似的样式将日期放在彼此下方/旁边。
它们只是将西北锚点放置在前一个矩阵的东南锚点处。对于星期一矩阵,这个前一个矩阵不存在,这就是为什么我只是用初始化一个坐标amcal-day-1。这基本上是一个穷人对库功能的实现chains


我把translatorbabel包放在了加载之前,tikz这样当calendar加载库时,翻译钩子就已经安装了。


amcal-week环境中,我首先采用强制参数,计算当天的星期几并减去密钥,dates以便我们始终有一个完整的星期。 (如您所见,我要求的2022-12-11是星期天,但页面上充满了整个星期,而不是从开始2022-12-11

标题

只需用节点替换辅助坐标,我们就有一个带有年份和月份的标题(给定环境的日期,而不是从页面上出现的第一天开始)。

迷你日历

我没有将日历放在 tikzpicture 内的节点内的 tikzpicture 内,而是将迷你日历放在同一个 tikzpicture 中。

因为这/tikz/amcal/mini/day xshift充当转发到迷你日历的顶级值键。(该值存储在一个@难以访问的宏中。)

该值还用于减少星期一矩阵的宽度(从而缩短顶部的线)。

使用了一些奇怪的值,以便迷你日历可以正确地放在角落中。第一周的基线与标题相同。(天数的默认锚点是base east。)

当然,您可以将迷你日历day yshift向下移动一位,这样星期一矩阵的行就不需要缩短了。

代码

\documentclass[a5paper, spanish]{article}
\usepackage[margin=0.5cm]{geometry}
\usepackage{palatino}
\usepackage{babel, translator}
\usepackage{tikz}
\usetikzlibrary{
  calendar,         % Duh!
  shapes.geometric, % → ellipse
  shapes.misc,      % → strike out
  matrix,           % → matrix of nodes
  ext.misc}         % → .ifnum handler
\newcommand*\amcalset{\pgfqkeys{/tikz/amcal}}
\amcalset{
  .code=\amcalset{#1},
  every matrix/.style={
    every outer matrix/.append style={% tight matrix
      inner xsep=+0pt, outer sep=+0pt},
    name=amcal-day\pgfcalendarcurrentweekday,
    matrix anchor=north west,
    at/.ifnum={\pgfcalendarcurrentweekday=6}% Sunday?
              {(amcal-day5.north east)}
              {(amcal-day\pgfinteval{\pgfcalendarcurrentweekday-1}.south west)},
    % alternatively: at={(amcal-day\ifnum\pgfcalendarcurrentweekday=6
    %                              5.north east\else
    %         \pgfinteval{\pgfcalendarcurrentweekday-1}.south west\fi)}
    matrix of nodes,
    append after command={
      (\tikzlastnode.north west) edge (\tikzlastnode.north east)},
    ampersand replacement = \&,
    column sep=\tabcolsep,
    row sep=+.3ex, % carefully selected
    column 1/.append style={% ellipses
      minimum width=1.5cm,
      shape=ellipse,
      nodes={
        draw,
        overlay,
        outer sep=+0pt,
        inner ysep=+.2em,
        append after command=(\tikzlastnode.west)(\tikzlastnode.east)
                             (\tikzlastnode.south)(\tikzlastnode.north),
      },
    },
    column 2/.append style={minimum width=1cm},
    column 3/.append style={% math!
      minimum width={% basically the X column
        % if weekday then only half the linewidth
        ifthenelse(%
          \pgfcalendarcurrentweekday==5,
          .5,
          ifthenelse(
            \pgfcalendarcurrentweekday==6,
            .5,
            1
          )
        )*
        \linewidth
        -2.5cm                % the minimum widths of the other columns
        -2\pgfmatrixcolumnsep % 3 columns → 2 column seps
        -(\pgfcalendarcurrentweekday==0) 
          *(7.7*(\pgfkeysvalueof{/tikz/amcal/mini/day xshift}))% 7.7‽
      },
      % minimum width minus the inner xseps on both sides
      text width={(\pgfkeysvalueof{/pgf/minimum width})
                  -2*(\pgfkeysvalueof{/pgf/inner xsep})},
    },
    row 1 column 2/.append style={font=\bfseries\large},
    /utils/exec=\small\itshape,
    inner ysep=+.29em, % carefully selected
    text depth=+0pt,
  },
  weekday/.style={
    day code={
      \matrix[amcal/every matrix] {
              \& \%d= \& \%wt \\
        17:00 \& hola \\
        18:10 \& hola \\
        19:20 \& hola \\
        20:30 \& hola \\[.9ex]\\ % carefully selected
      };
    }
  },
  weekend/.style={
    day code={
      \matrix[amcal/every matrix] {
              \& \%d= \& \%wt \\
        11:00 \& hola \\
        12:10 \& hola \\
        13:20 \& hola \\
        17:00 \& hola \\
        18:10 \& hola \\
        19:20 \& hola \\
        20:30 \& hola \\
      };
    }
  },
  heading/.style={
    node font=\itshape\large,
    inner xsep=+1.7em,
    name=amcal-day-1,
  },
  strike out/.style={
    shape=strike out,
    draw,
  },
  mini/.style={
    day xshift=\pgfkeysvalueof{/tikz/amcal/mini/day xshift},
    shift={([xshift={1.1*(\pgfkeysvalueof{/tikz/amcal/mini/day xshift})}]% 1.1‽
      amcal-day-1.base-|amcal-day0.east)},
    dates=\amcalYear-\amcalMonth-01 to \amcalYear-\amcalMonth-last,
    week list,
    day text={\%d=},
    if={(weekend) [amcal/mini/weekend]},
    if={(at most=\amcalYear-\amcalMonth-\amcalDay) [amcal/mini/day over]},
  },
  mini/weekend/.style={
    days={
      gray,
      amcal/strike out/.code=
    },
  },
  mini/day over/.style={
    days=amcal/strike out,
  },
  mini/day xshift/.initial=3.6ex, % default is 3.5ex
}
\makeatletter
\newenvironment*{amcal-week}[2][]{%
  \noindent
  \begin{tikzpicture}[trim left=(amcal-day0.west), trim right=(amcal-day0.east)]
  \pgfcalendardatetojulian{#2}{\count@}%
  \edef\amcalJulian{\the\count@}%
  \pgfcalendarjuliantoweekday{\count@}{\count@}%
  \edef\amcalWeekday{\the\count@}%
  \pgfcalendarjuliantodate{\amcalJulian}{\amcalYear}{\amcalMonth}{\amcalDay}%
  \node[amcal/heading] {\amcalYear\hspace{1em}\Large\pgfcalendarmonthname{\amcalMonth}};
  \calendar[
    dates=#2+-\amcalWeekday to #2+\pgfinteval{6-\amcalWeekday},
    if={(workday) [amcal/weekday]},
    if={(weekend) [amcal/weekend]},
  ]
}{%
  ;
  \calendar[amcal/mini];
  \end{tikzpicture}\par
}
\makeatother
\begin{document}
\begin{amcal-week}{2022-12-11}
\end{amcal-week}
\end{document}

输出

在此处输入图片描述

相关内容