可編輯日曆產生器

可編輯日曆產生器

我正在尋找一種在 LaTeX 中生成日曆頁面的簡單方法,如下所示:http://www.latextemplates.com/template/monthly-calendar- 但是,我不必考慮日曆對齊的「正確」工作日。應該可以透過指定日期(例如 2017 年 2 月)自動正確佈局頁面。

此外,還必須是可能會編輯在 LaTeX 中輕鬆地顯示日曆中的文本,所以這不僅僅是用於列印和填充墨水。我想最好的方法是分兩步驟進行,其中一個是產生 LaTeX 文件包含每天的條目,然後可以編輯特定日期的議程。另一種可能性是讓日曆條目採用一些更簡單的文字格式(應該可以在 git 版本控制中使用它)並且解析並插入它們正確地來自乳膠文件。

答案1

服用我的答案來自另一個問題並調整它:

\newcommand*\events{%
  \month-\day / Today,
  2023-04-10 / A very long text with math $e = mc^2$ and so much text that the whole box and its five lines are needed,
  12-31 / New Year's Eve,
  2023-04-11 / A B C D E F G H I J K L M N O P Q R S T U V W X Y Z A B C D E F G H I J K L M N O P Q R S T U V W X Y
}
\tikzset{
  day event/.style={
    node contents={%
      \parshape 5 0pt \dimexpr\textwidth-1.9em 0pt \dimexpr\textwidth-1.9em
      0pt \textwidth 0pt \textwidth 0pt \textwidth #1\par},
    text height=+1em,
    text depth=\pgfkeysvalueof{/pgf/minimum height}-2*(\pgfkeysvalueof{/pgf/inner ysep})-1em,
    text width=\pgfkeysvalueof{/pgf/minimum width}-2*(\pgfkeysvalueof{/pgf/inner xsep}),
    align=left,
  },
  events/.style args={#1/#2}{
    if = {(equals=#1) [every day/.append style={day event={#2}}]}
  }
}

其中\events包含要在給定的節點框中排版的內容的列表,events該列表將文字部分添加到日期節點,我正在使用\parshape解決方案在右側(日期編號所在的位置)剪切一個區域。

現在您所需要做的就是填入\events巨集。

您可以將此與 zjr 採取的方法結合起來在另一個答案中我使用多個巨集並允許不同的樣式,以便您可以使用各種類型的事件新增至日曆。

不過,請盡量確保每天只有一次活動,否則您將需要類似的活動[1]或者[2]

還有一個解決方案,其中日曆延伸以便它始終填滿頁面。


實現\parshape相當初級,因為它只是用作1.9em右側的額外填充,測量角落中日期文字的寬度並使用它會更聰明。

我還調整了主循環並添加了trim lefttrim right來抑制過多的 hbox 警告。

程式碼

\documentclass[a4paper,landscape]{article}
\usepackage[margin={1cm},noheadfoot]{geometry}
\renewcommand*\thepage{}
\usepackage{libertine}
\usepackage{tikz}
\usetikzlibrary{calendar}
\tikzset{
  every weekday/.style={
    anchor=south west, black,
    name=weekday-\pgfcalendarcurrentmonth-\pgfcalendarcurrentweekday,
    node contents=\%wt},
  weekday above/.style={
    if = {(day of month=1) [days={append after command={
          node [at={(\tikzlastnode.north west)},
                alias=@firstweekday,
                every weekday]}}]},
    if = {(day of month=2, day of month=3, day of month=4, day of month=5, day of month=6, day of month=7) [
          days={append after command={
          node [at={(@firstweekday.south west-|\tikzlastnode.south west)}, every weekday]}}]}},
  wall calendar/.style={
    week list, weekday above, day text=,
    day and weekday/.style={
      draw, outer sep=+0pt,
      minimum width=\linewidth/7,
      minimum height=+.125\textheight},
    day xshift=\linewidth/7,
    day yshift=\textheight/8,
    every day label/.style={
      anchor=north east,
      font=\Large\itshape,
      node contents={\%d=},
      inner sep=+.7em},
    every day/.append style={
      day and weekday,
      anchor=center,
      label={[every day label]north east:}},
    every weekday/.append style={
      day and weekday,
      minimum height=+2em}}}
\newcommand*\Year{2023}
\newcommand*\events{%
  \month-\day / Today,
  2023-04-10 / A very long text with math $e = mc^2$ and so much text that the whole box and its five lines are needed,
  12-31 / New Year's Eve,
  2023-04-11 / A B C D E F G H I J K L M N O P Q R S T U V W X Y Z A B C D E F G H I J K L M N O P Q R S T U V W X Y
}
\tikzset{
  day event/.style={
    node contents={%
      \parshape 5 0pt \dimexpr\textwidth-1.9em 0pt \dimexpr\textwidth-1.9em
      0pt \textwidth 0pt \textwidth 0pt \textwidth #1\par},
    text height=+1em,
    text depth=\pgfkeysvalueof{/pgf/minimum height}-2*(\pgfkeysvalueof{/pgf/inner ysep})-1em,
    text width=\pgfkeysvalueof{/pgf/minimum width}-2*(\pgfkeysvalueof{/pgf/inner xsep}),
    align=left,
  },
  events/.style args={#1/#2}{
    if = {(equals=#1) [every day/.append style={day event={#2}}]}
  }
}
\begin{document}\sffamily
\centering
\foreach \mon in {01,0...,09,10,11,12}{% leading zero for trim left/right
  {\Huge \pgfcalendarmonthname{\mon}\par}
  {\huge \Year\par}
  \vspace{2em}
  \tikz[trim left=(weekday-\mon-0.west), trim right=(weekday-\mon-6.east)]
    \calendar[
      dates=\Year-\mon-01 to \Year-\mon-last,
      wall calendar,
      events/.list/.expand once=\events,
    ];

\pagebreak}
\end{document}

輸出

在此輸入影像描述

相關內容