这个问题是由 Peter Wilson 在压缩.文本.tex`。
彼得写道:TUG 成员制作了 2012 年的日历,如果我没记错的话,他们还制作了前几年的日历。我真的希望 2013 年也能有日历。
仅供参考,日历应使用 LaTeX 和朋友生成,包括 LaTeX 生成的图片。
我的问题是我们如何在 LaTeX 中做到这一点?
以下是2009 年日历。
(来源:texample.net) 。
答案1
好吧,这并不是你想要的,但几周前我曾考虑过要求提供日历,以便将其变成社区 Wiki,但最终我放弃了。不过,我在这里发布了我的解决方案(这远非最佳方案,我鼓励大家改进它 — 但当然,不要改变外观 —)。我再说一遍,这可能不是你想要的。
该文件是这样的:
\documentclass[border=4.9mm, multi={tikzpicture}]{standalone}
\usepackage[utf8]{inputenc}
\usepackage{lmodern}
\usepackage[T1]{fontenc}
% MCAL -------------------------------
\usepackage{mcal}
% MCAL -------------------------------
\begin{document}\estilodetexto% To set up \sffamily, \bfseries…
\thisyear{2013}% The year the calendar is about.
\colordelosfestivos{red}% The color of holidays.
\remaincolor{white}% The color under the top rectangle (where the title and the previous and next calendar are)
\resubcolor{white}% The color under the names of the week
\mooncounter=2% To set the first moon of the year (0,1,2,3)
\enero[7,14,21,28]{7}% The months …
\febrero[7,14,21,28]{1,2,3,7,9,25}
\marzo[7,14,21,28]{1,2,3,7,9,25}
\abril[7,14,21,28]{1,2,3,7,9,25}
\mayo[7,14,21,28]{1,2,3,7,9,25}
\junio[7,14,21,28]{1,2,3,7,9,25}
\julio[7,14,21,28]{1,2,3,7,9,25}
\agosto[7,14,21,28]{1,2,3,7,9,25}
\septiembre[7,14,21,28]{1,2,3,7,9,25}
\octubre[7,14,21,28]{1,2,3,7,9,25}
\noviembre[7,14,21,28]{1,2,3,7,9,25}
\diciembre[4,12,19,27]{6,8,25,31}
\end{document}
它使用了一个mcal.sty
我稍后会介绍的自定义方法。用法很简单,每个月(现在是西班牙语,但你应该明白了)都有一个强制参数,即该月的节假日,以逗号分隔,还有一个可选参数,即该月的月相日期。
你可以看到它的完整样子这里。
除此之外,mcal.sty
还有以下内容:
\RequirePackage{tikz}
\usetikzlibrary{calc,calendar}
\RequirePackage{xcolor}
\def\estilodetexto{\sffamily\bfseries\LARGE}
\pgfmathtruncatemacro{\Year}{2013}%
\pgfmathtruncatemacro{\monthcounter}{12}% Diciembre
\pgfmathtruncatemacro{\oldYear}{\Year-1}%
\pgfmathtruncatemacro{\newYear}{\Year+1}%
\def\colorfestivos{red}
\def\maincolor{white}
\def\subcolor{white}
\def\remaincolor#1{%
\let\maincolor\relax%
\def\maincolor{#1}%
}
\def\resubcolor#1{%
\let\subcolor\relax%
\def\subcolor{#1}%
}
\def\colordelosfestivos#1{%
\let\colorfestivos\relax%
\def\colorfestivos{#1}%
}
\def\thisyear#1{%
\let\Year\relax%
\pgfmathtruncatemacro{\Year}{#1}%
}
\RequirePackage{etoolbox}
\RequirePackage{mathabx}
\newcommand*{\listadefestivos}[1]{%
\def\festivos{}%
\foreach \f in {#1} {%
\xappto\festivos{if (day of month = \f) [\colorfestivos]}}%
}
\newcount\mooncounter
\def\moonreset{\global\mooncounter=-1\relax}
\moonreset
\def\moon{%
\global\advance\mooncounter by 1\relax%
\ifcase\mooncounter $\newmoon$%
\or $\rightmoon$%
\or $\fullmoon$%
\or $\leftmoon$\global\mooncounter=-1\relax%
\fi%
}
\newcommand*{\listadelunas}[1]{%
\def\lunas{}%
\foreach \l in {#1} {%
\xappto\lunas{if (day of month = \l) [day text=\noexpand\moon\%d-]}
}%
}
\makeatletter%
\tikzoption{day headings}{\tikzstyle{day heading}=[#1]}
\tikzstyle{day heading}=[]
\tikzstyle{day letter headings}=[
execute before day scope={ \ifdate{day of month=1}{%
\pgfmathsetlength{\pgf@ya}{\tikz@lib@cal@yshift}%
\pgfmathsetlength\pgf@xa{\tikz@lib@cal@xshift}%
\pgftransformyshift{-\pgf@ya}
\foreach \d/\l in {0/L,1/M,2/X,3/J,4/V,5/S,6/D}{
\pgf@xa=\d\pgf@xa%
\pgftransformxshift{\pgf@xa}%
\pgftransformyshift{\pgf@ya}%
\node[every day,day heading]{\estilodetexto\Large\l};%
}
}{}%
}%
]
\makeatother
\pagestyle{empty}
\def\Month{%
\ifnum\monthcounter=1%
Enero\else
\ifnum\monthcounter=2%
Febrero\else
\ifnum\monthcounter=3%
Marzo\else
\ifnum\monthcounter=4%
Abril\else
\ifnum\monthcounter=5%
Mayo\else
\ifnum\monthcounter=6%
Junio\else
\ifnum\monthcounter=7%
Julio\else
\ifnum\monthcounter=8%
Agosto\else
\ifnum\monthcounter=9%
Septiembre\else
\ifnum\monthcounter=10%
Octubre\else
\ifnum\monthcounter=11%
Noviembre\else
\ifnum\monthcounter=12%
Diciembre%
\fi%
\fi%
\fi%
\fi%
\fi%
\fi%
\fi%
\fi%
\fi%
\fi%
\fi%
\fi%
}
\def\findemes{\ifnum\monthcounter=12%
\pgfmathtruncatemacro{\monthcounter}{1} \else%
\pgfmathtruncatemacro{\monthcounter}{\monthcounter+1}%
\fi%
}
\def\nuevapagina{\findemes%
%\newpage%
}
\newcommand\mes[2][]{
\begin{tikzpicture}%
% Cuadrícula
\draw[fill opacity=1,fill=\maincolor] (0,20) rectangle (28,16);%
\draw[fill opacity=1,fill=\subcolor] (0,15) rectangle (28,16);%
\draw[xstep=4cm, ystep=2.5cm] (0,0) grid (28,15);%
\draw[xstep=4cm, ystep=1cm] (0,15) grid (28,16);%
\draw (0,20) rectangle (28,16);%
\foreach \dia/\posicion in {Lunes/2,Martes/6,Miércoles/10,Jueves/14,Viernes/18,Sábado/22,Domingo/26}{%
\node (\dia) at (\posicion,15.5) {\dia};%
}%
% Calendario mes anterior
\node (titulocalanterior) at (2.75,19.5) {\Month};%
\calendar (calanterior) [dates=\Year-12-01 to \Year-12-last,%
day xshift=1em,%
day yshift = 1em-1ex,%
day text=\normalsize \%d-,%
week list,%
day letter headings] at (1.2,18.7);%
\findemes%
% CALENDARIO PRINCIPAL
\listadelunas{#1}%
\listadefestivos{#2}%
\calendar[dates=\Year-\monthcounter-1 to \Year-\monthcounter-last,%
week list,%
day xshift = 4cm,%
day yshift = 2.5cm,%
if = {(Sunday) [\colorfestivos]},%
] at (4,14.3) \festivos \lunas;%
\node[scale=2] (Mtitle) at (14,18) {\Huge \Month{} de \Year};%
\findemes%
% Calendario mes siguiente
\node (titulocalsiguiente) at (25.05,19.5) {\Month};%
\calendar (calsiguiente) [dates=\Year-\monthcounter-1 to \Year-\monthcounter-last,%
day xshift=1em,%
day yshift = 1em-1ex,%
day text=\normalsize \%d-,%
week list,%
day letter headings] at (23.5,18.7);%
\end{tikzpicture}
\nuevapagina
}
\newcommand\enero[2][]{
\begin{tikzpicture}%
% Cuadrícula
\draw[fill opacity=1,fill=\maincolor] (0,20) rectangle (28,16);%
\draw[fill opacity=1,fill=\subcolor] (0,15) rectangle (28,16);%
\draw[xstep=4cm, ystep=2.5cm] (0,0) grid (28,15);%
\draw[xstep=4cm, ystep=1cm] (0,15) grid (28,16);%
\draw (0,20) rectangle (28,16);%
\foreach \dia/\posicion in {Lunes/2,Martes/6,Miércoles/10,Jueves/14,Viernes/18,Sábado/22,Domingo/26}{%
\node (\dia) at (\posicion,15.5) {\dia};%
}%
% Calendario mes anterior
\node (titulocalanterior) at (2.75,19.5) {\Month};%
\calendar (calanterior) [dates=\oldYear-12-01 to \oldYear-12-last,%
day xshift=1em,%
day yshift = 1em-1ex,%
day text=\normalsize \%d-,%
week list,%
day letter headings] at (1.2,18.7);%
\findemes%
% CALENDARIO PRINCIPAL
\listadelunas{#1}%
\listadefestivos{#2}%
\calendar[dates=\Year-\monthcounter-1 to \Year-\monthcounter-last,%
week list,%
day xshift = 4cm,%
day yshift = 2.5cm,%
if = {(Sunday) [\colorfestivos]},%
] at (4,14.3) \festivos \lunas;%
\node[scale=2] (Mtitle) at (14,18) {\Huge \Month{} de \Year};%
\findemes%
% Calendario mes siguiente
\node (titulocalsiguiente) at (25.05,19.5) {\Month};%
\calendar (calsiguiente) [dates=\Year-\monthcounter-1 to \Year-\monthcounter-last,%
day xshift=1em,%
day yshift = 1em-1ex,%
day text=\normalsize \%d-,%
week list,%
day letter headings] at (23.5,18.7);%
\end{tikzpicture}
\nuevapagina
}
\let\febrero\mes%
\let\marzo\mes%
\let\abril\mes%
\let\mayo\mes%
\let\junio\mes%
\let\julio\mes%
\let\agosto\mes%
\let\septiembre\mes%
\let\octubre\mes%
\let\noviembre\mes%
\newcommand\diciembre[2][]{
\begin{tikzpicture}%
% Cuadrícula
\draw[fill opacity=1,fill=\maincolor] (0,20) rectangle (28,16);%
\draw[fill opacity=1,fill=\subcolor] (0,15) rectangle (28,16);%
\draw[xstep=4cm, ystep=2.5cm] (0,0) grid (28,15);%
\draw[xstep=4cm, ystep=1cm] (0,15) grid (28,16);%
\draw (0,20) rectangle (28,16);%
\foreach \dia/\posicion in {Lunes/2,Martes/6,Miércoles/10,Jueves/14,Viernes/18,Sábado/22,Domingo/26}{%
\node (\dia) at (\posicion,15.5) {\dia};%
}%
% Calendario mes anterior
\node (titulocalanterior) at (2.75,19.5) {\Month};%
\calendar (calanterior) [dates=\Year-12-01 to \Year-12-last,%
day xshift=1em,%
day yshift = 1em-1ex,%
day text=\normalsize \%d-,%
week list,%
day letter headings] at (1.2,18.7);%
\findemes%
% CALENDARIO PRINCIPAL
\listadelunas{#1}%
\listadefestivos{#2}%
\calendar[dates=\Year-\monthcounter-1 to \Year-\monthcounter-last,%
week list,%
day xshift = 4cm,%
day yshift = 2.5cm,%
if = {(Sunday) [\colorfestivos]},%
] at (4,14.3) \festivos \lunas;%
\node[scale=2] (Mtitle) at (14,18) {\Huge \Month{} de \Year};%
\findemes%
% Calendario mes siguiente
\node (titulocalsiguiente) at (25.05,19.5) {\Month};%
\calendar (calsiguiente) [dates=\newYear-\monthcounter-1 to \newYear-\monthcounter-last,%
day xshift=1em,%
day yshift = 1em-1ex,%
day text=\normalsize \%d-,%
week list,%
day letter headings] at (23.5,18.7);%
\end{tikzpicture}
\nuevapagina
}
正如您所见,它非常基础并且使用了tikz
的calendar
库。
编辑:它是西班牙语的(+ 一点英语,写得很快,不用想太多,你会看到里面有很多随机性 :P)。我将来会尝试将其翻译成英语。
答案2
我为 2012 年写了一篇......但由于过去几个月我一直在写论文,所以缺少 2013 年的材料。http://www.disk0s1.de/posts/latex/texianischer-kalender/
我基本上使用了以下宏:
\newcommand{\mymo}[3]{%
\begin{minipage}{\textwidth}%
\centering%
\noindent\Huge\pgfcalendarmonthname{\value{tgmymo}}\normalsize\stepcounter{tgmymo}\\[1cm]%
#3
\end{minipage}\vfill\begin{minipage}{\textwidth}\centering
%
\begin{tikzpicture} \pgfcalendar{cal}{#1}{#2}{%
\ifdate{workday}%
{\tikzset{filling/.style={fill=black!05}}}%
{\tikzset{filling/.style={fill=orange!20}}}
%%
\def\normal{\node (\pgfcalendarsuggestedname) at (\pgfcalendarcurrentweekday*2.5,0) [filling, rectangle,rounded corners, text width=.1\textwidth,text height=.8cm ,align=right] {\\$\pgfcalendarcurrentday$};}%
%%
\ifdate{equals=2013-01-10}{\node (\pgfcalendarsuggestedname) at (\pgfcalendarcurrentweekday*2.5,0) [filling, rectangle,rounded corners, text width=.1\textwidth ,text height=.8cm ,align=right,] {{\small D. E. Knuth}\\$\pgfcalendarcurrentday$};}{\normal}%
\ifdate{equals=2013-02-07}{\node (\pgfcalendarsuggestedname) at (\pgfcalendarcurrentweekday*2.5,0) [filling, rectangle,rounded corners, text width=.1\textwidth ,text height=.8cm ,align=right,] {{\small L. Lamport}\\$\pgfcalendarcurrentday$};}{}%
\ifdate{equals=2013-05-05}{\node (\pgfcalendarsuggestedname) at (\pgfcalendarcurrentweekday*2.5,0) [filling, rectangle,rounded corners, text width=.1\textwidth ,text height=.8cm ,align=right,] {{\small Julia}\\$\pgfcalendarcurrentday$};}{}%
%
\ifdate{equals=2013-08-01}{\node (\pgfcalendarsuggestedname) at (\pgfcalendarcurrentweekday*2.5,0) [filling, rectangle,rounded corners, text width=.1\textwidth ,text height=.8cm ,align=right,] {{\small Tobias}\\$\pgfcalendarcurrentday$};}{}%
%
\ifdate{Sunday}{\pgftransformyshift{-4.2em}}{}%
};
\end{tikzpicture}\end{minipage}\clearpage}
这将设置带有日历的页面,内容(图片等)将作为参数 #3 调用。像这样:\mymo{2013-01-01}{2013-01-last}{\input{jan.tex}}
。
它是用高分辨率激光打印机打印在 100g/m^2 DIN A4 纸上并寄给我的一些朋友。