![如何创建每日一页日历模板](https://linux22.com/image/244272/%E5%A6%82%E4%BD%95%E5%88%9B%E5%BB%BA%E6%AF%8F%E6%97%A5%E4%B8%80%E9%A1%B5%E6%97%A5%E5%8E%86%E6%A8%A1%E6%9D%BF.png)
最近我每天都会收到一页数学谜题。我想知道是否有 LaTeX 模板。我正在尝试学习新语言,为此我想创建一页日历。任何有关此事的帮助都将不胜感激。
答案1
以下示例创建一个 Page-a-Day 日历,其中相应的条目从 ASCII 文本文件(实际上是 CSV)中读取。CSV 文件的构造使用标准 Excel 或 OpenOffice 技术,而datatool
包裹提供记录条目的读取和操作。
page-calendar.csv
"DayNum","Date","Year","MonthNum","Month","Mnth","Day","WeekdayNum","Weekday","Wkday","Saying"
1,2012-01-01,2012,1,"January","Jan",1,1,"Sunday","Sun","Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Ut purus elit, vestibulum ut, placerat ac, adipiscing vitae, felis. Curabitur dictum gravida mauris."
2,2012-02-13,2012,2,"February","Feb",13,2,"Monday","Mon","Nam arcu libero, nonummy eget, consectetuer id, vulputate a, magna. Donec vehicula augue eu neque."
3,2012-03-02,2012,3,"March","Mar",2,6,"Friday","Fri","Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Mauris ut leo. Cras viverra metus rhoncus sem."
4,2012-04-19,2012,4,"April","Apr",19,5,"Thursday","Thu","Nulla et lectus vestibulum urna fringilla ultrices. Phasellus eu tellus sit amet tortor gravida placerat. Integer sapien est, iaculis in, pretium quis, viverra ac, nunc."
5,2012-05-23,2012,5,"May","May",23,4,"Wednesday","Wed","Praesent eget sem vel leo ultrices bibendum. Aenean faucibus. Morbi dolor nulla, malesuada eu, pulvinar at, mollis ac, nulla. Curabitur auctor semper nulla."
6,2012-06-07,2012,6,"June","Jun",7,5,"Thursday","Thu","Donec varius orci eget risus. Duis nibh mi, congue eu, accumsan eleifend, sagittis quis, diam. Duis eget orci sit amet orci dignissim rutrum."
7,2012-07-30,2012,7,"July","Jul",30,2,"Monday","Mon","Nam dui ligula, fringilla a, euismod sodales, sollicitudin vel, wisi. Morbi auctor lorem non justo. Nam lacus libero, pretium at, lobortis vitae, ultricies et, tellus."
8,2012-08-22,2012,8,"August","Aug",22,4,"Wednesday","Wed","Donec aliquet, tortor sed accumsan bibendum, erat ligula aliquet magna, vitae ornare odio metus a mi. Morbi ac orci et nisl hendrerit mollis. Suspendisse ut massa."
9,2012-09-18,2012,9,"September","Sep",18,3,"Tuesday","Tue","Cras nec ante. Pellentesque a nulla. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Aliquam tincidunt urna."
10,2012-10-06,2012,10,"October","Oct",6,7,"Saturday","Sat","Nulla ullamcorper vestibulum turpis. Pellentesque cursus luctus mauris. Nulla malesuada porttitor diam. Donec felis erat, congue non, volutpat at, tincidunt tristique, libero."
11,2012-11-20,2012,11,"November","Nov",20,3,"Tuesday","Tue","Vivamus viverra fermentum felis. Donec nonummy pellentesque ante. Phasellus adipiscing semper elit. Proin fermentum massa ac quam."
12,2012-12-31,2012,12,"December","Dec",31,2,"Monday","Mon","Sed diam turpis, molestie vitae, placerat a, molestie nec, leo. Maecenas lacinia. Nam ipsum ligula, eleifend at, accumsan nec, suscipit a, ipsum."
该文件包含全部用于创建每日一页日历的数据。我创建了多个字段:
DayNum
:当前条目的编号Date
: 入境日期Year
:进入年份(Excel/OpenOffice 公式=YEAR(<Date>)
:)MonthNum
:条目的月份(数字)1..12(Excel/OpenOffice 公式=MONTH(<Date>)
:)Month
:条目的月份(名称)(VLOOKUP
使用Excel/OpenOffice<MonthNum>
)Mnth
:条目的缩写月份(名称)(VLOOKUP
使用Excel/OpenOffice<MonthNum>
)Day
:第 1 天至第 31 天(Excel/OpenOffice 公式=DAY(<Date>)
:)WeekdayNum
:输入的星期几 1..7(Excel/OpenOffice 公式=WEEKDAY(<Date>)
:)Weekday
:条目的星期名称(VLOOKUP
使用Excel/OpenOffice<WeekdayNum>
)Wkday
:条目的缩写星期几(名称)(VLOOKUP
使用Excel/OpenOffice<WeekdayNum>
)Saying
:针对该特定条目说
page-calendar.tex
\documentclass[12pt]{article}
\usepackage[margin=2cm,landscape,a5paper]{geometry}% http://ctan.org/pkg/geometry
\usepackage{tikz}% http://ctan.org/pkg/pgf
\usetikzlibrary{calc}%
\usepackage{datatool}% http://ctan.org/pkg/datatool
\DTLloaddb{calendar}{page-calendar.csv}% Load page-calendar.csv into calendar DB
\pagestyle{empty}% Remove page headers/footers
\begin{document}
\sffamily% Default font family
\DTLforeach{calendar}
{\calDayNum=DayNum,
\calDate=Date,
\calYear=Year,
\calMonthNum=MonthNum,
\calMonth=Month,
\calMnth=Mnth,
\calDay=Day,
\calWeekdayNum=WeekdayNum,
\calWeekday=Weekday,
\calWkday=Wkday,
\calSaying=Saying}
{%
\begin{tikzpicture}[remember picture,overlay]
\fill[black!80!green!25]
(current page.north east) rectangle (current page.south west);% Outer frame
\shade [bottom color=black!70!green!25, top color=black!70!green!10]
($(current page.north east)+(-5mm,-5mm)$) rectangle ($(current page.south west)+(5mm,5mm)$); % Inner frame + shading
\draw ($(current page.north west)+(5mm,-5mm)$)
node[anchor=north west] {\scalebox{5}{\bfseries\color{black!65}\calYear}};% Print YEAR
\draw ($(current page.north east)+(-5mm,-5mm)$)
node[anchor=north east] {\scalebox{3}{\bfseries\color{black!80}%
\begin{minipage}{.5\linewidth}\raggedleft%
\calWeekday \par% Print WEEKDAY
\calDay~\calMonth% Print DAY + MONTH
\end{minipage}}};
\draw (current page.center)
node {\scalebox{2}{\color{black!95!green}%
\begin{minipage}{.5\linewidth}
\centering\large\calSaying% Print SAYING
\end{minipage}}};
\end{tikzpicture}%
\newpage%
}
\end{document}
我在这里只是玩了一下tikz
将提取的元素定位到页面上。我只使用了Year
、、和,尽管所有Month
这些都可以通过宏访问。宏被定义为命令的一部分。具体来说,是通过宏引用的,通过宏引用的,...通过宏引用的。当然,您可以重命名这些,并使用不同的布局和颜色方案或其他(包括使用指定的页面尺寸选择Day
Weekday
Saying
\DBLforeach
Year
\calYear
Month
\calMonth
Saying
\calSaying
geometry
)。
输出
为什么这样?也许您不想创建整个年度日历,而只想创建月度日历。现在,您无需在 LaTeX 中修复构造,而是可以在外部逐个操作它,并仅导出您感兴趣的条目。
该方法非常灵活,因为datatool
允许将任何可识别的 LaTeX 内容包含在数据库中。例如,如果您不想包含一句话,您可以用图像替换它,只需使用
\includegraphics[<options>]{<filename>}
并将datatool
图像放置在相应的日历日。
答案2
我不知道有任何预先构建的包或类可以做到这一点,但也许这段代码符合你想要的。
我已经使用该包来获取、、等的nth
正确格式。1st
2nd
3rd
代码的主要部分是一个非常简单的循环,从 1 到 366(因为 2012 年是闰年)。您所要做的就是指定所需的引号,它就会起作用。当然,您可能希望稍微改变一下样式,也许添加一些颜色,但我会把这留给您决定。
\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}