使用 LaTeX 的组织者补充/嵌体

使用 LaTeX 的组织者补充/嵌体

每年我都需要为我心爱的记事本重新填纸。但简单的 A5 纸笔芯售价却高达 20 美元左右,真是令人难以置信。

有没有办法使用 LaTeX 创建组织者插页(例如在两页 A5 纸上记录一周的内容)?

答案1

今天是你的幸运日,老兄!

日历

看一下这个:

\documentclass[%
    BCOR=2cm,%  Space for hole puncher
    DIV=25,%    Size of textbody
    12pt%       Fontsize
]{scrbook}
%
%%%%%%%%%% PACKAGES %%%%%%%%%%
%
\usepackage{tabularx,booktabs,multirow}
%
%%%%%%%%%% COUNTER %%%%%%%%%%
%
\newcount\counter
\newcount\startdate
\newcount\starttime
\newcount\stoptime
\newcount\sundaybegin
\newcount\week
%
%%%%%%%%%% CUSTOMISATIONS %%%%%%%%%%
%
%% Month
\renewcommand{\month}{January}
%% Date to start the week with
\startdate=11
%% Morning starttime
\starttime=8
%% Evening time
\stoptime=21
%% Starttime sunday
% Min \starttime+1
% Max \stoptime-2
\sundaybegin=14
%% Weeknumber
\week=1
%% Rule width thick
\newcommand{\rulew}{.15em}
%% Extra space
%\setlength{\extrarowheight}{1pt}
%
%%%%%%%%%% DEFINITIONS %%%%%%%%%%
%
\newcommand{\lendt}{\cmidrule[\rulew](l){1-2}\cmidrule[\rulew](l){3-4}\cmidrule[\rulew](l){5-6}}
\newcommand{\lend}{\cmidrule(l){1-2}\cmidrule(l){3-4}\cmidrule(l){5-6}}
\newcommand{\lsun}{\cmidrule(l){1-2}\cmidrule(l){3-4}}
\newcommand{\lsunt}{\cmidrule(l){1-2}\cmidrule(l){3-4}\cmidrule[\rulew](l){5-6}}
\newcommand{\printday}[2]{{\LARGE \textbf{#1}}\,\, \large \textbf{#2}}
\newcommand{\neutralline}{& & & & &}
\newcommand{\footer}{\centering\rule{7cm}{\cmidrulewidth} \raisebox{-0.5ex}{\LaTeX{}} \rule{7cm}{\cmidrulewidth}}
\newcommand{\printmonth}{{\LARGE \textbf{\month}}}
%
%%%%%%%%%% TABLE CONTENT LEFT SIDE %%%%%%%%%%
%
% Correction due to \global\advance
\advance\startdate-6
%
\advance\stoptime1
\long\def\addto#1#2{\expandafter\def\expandafter#1\expandafter{#1#2}}
%
\def\tabledataleft{} \counter=\the\starttime
\loop
    \edef\tabline{\the\counter &  & \the\counter & & \the\counter & }
    \expandafter\addto\expandafter\tabledataleft\expandafter{\neutralline \\\lend}
    \expandafter\addto\expandafter\tabledataleft\expandafter{\tabline \\\lend}
    \advance \counter 1
    \ifnum \counter<\the\stoptime
\repeat 
%
%%%%%%%%%% TABLE CONTENT RIGHT SIDE %%%%%%%%%%
%
\def\tabledatarightupper{} \counter=\the\starttime
\loop
    \edef\tabline{\the\counter &  & \the\counter & & & }
    \expandafter\addto\expandafter\tabledatarightupper\expandafter{\neutralline \\\lend}
    \expandafter\addto\expandafter\tabledatarightupper\expandafter{\tabline \\\lend}
    \advance \counter 1
    \ifnum \counter<\the\sundaybegin
\repeat 
%
\advance\sundaybegin1
\def\tabledatarightinter{} \counter=\the\sundaybegin
\newcount\sundaystop
\sundaystop=\the\sundaybegin
\advance\sundaystop1
\loop
    \edef\tabline{\the\counter &  & \the\counter & & & }
    \expandafter\addto\expandafter\tabledatarightinter\expandafter{\neutralline \\\lsun}
    \expandafter\addto\expandafter\tabledatarightinter\expandafter{\tabline \\\lsun}
    \advance \counter 1
    \ifnum \counter<\the\sundaystop
\repeat 
\advance\sundaybegin-1
\advance\sundaystop1
%
\def\tabledatarightlower{} \counter=\the\sundaystop
\loop
    \edef\tabline{\the\counter &  & \the\counter & & & }
    \expandafter\addto\expandafter\tabledatarightlower\expandafter{\neutralline \\\lend}
    \expandafter\addto\expandafter\tabledatarightlower\expandafter{\tabline \\\lend}
    \advance \counter 1
    \ifnum \counter<\the\stoptime
\repeat 
\advance\sundaystop-1
%
\begin{document}
%
%% Empty page to start left
\thispagestyle{empty}
\mbox{}
\clearpage
%
\pagestyle{empty}
\enlargethispage{1cm}
%
%%%%%%%%%% LEFT TABLE %%%%%%%%%%
%
\noindent
\begin{tabularx}{\linewidth}{lXlXlX}
    \multicolumn{6}{l}{\printmonth \hfill Week \the\week}\\[.2em]\midrule[\rulew]
    \addlinespace[.5em]
    \multicolumn{2}{l}{\printday{\the\startdate}{Monday}} \global\advance\startdate 1\relax &%
    \multicolumn{2}{l}{\printday{\the\startdate}{Tuesday}} \global\advance\startdate 1\relax &%
    \multicolumn{2}{l}{\printday{\the\startdate}{Wednesday}}\global\advance\startdate 1\relax \\[2cm]
     & & & & & \\\lendt
    \tabledataleft
     & & & & & \\\lendt
\end{tabularx}
%
\vfill
\footer
%
\clearpage
\enlargethispage{1cm}
% Correction due to \global\advance
\advance\startdate-6
%
%%%%%%%%%% RIGHT TABLE %%%%%%%%%%
%
\noindent
\begin{tabularx}{\linewidth}{lXlXlX}
    \multicolumn{6}{l}{Week \the\week \hfill \printmonth}\\[.2em]\midrule[\rulew]
    \addlinespace[.5em]
    \multicolumn{2}{l}{\printday{\the\startdate}{Thursday}} \global\advance\startdate 1\relax &%
    \multicolumn{2}{l}{\printday{\the\startdate}{Friday}}   \global\advance\startdate 1\relax &%
    \multicolumn{2}{l}{\printday{\the\startdate}{Saturday}} \global\advance\startdate 1\relax \\[2cm]
    & & & & & \\\lendt
    \tabledatarightupper
    & & & & & \\\lsunt
    \addlinespace[-.15em]
    \the\sundaybegin & & \the\sundaybegin & & \multicolumn{2}{l}{\multirow{4}{*}[1.5em]{\printday{\the\startdate}{Sunday}}}\\\lsun
    \tabledatarightinter
    & & & & & \\\lsun
    \the\sundaystop & & \the\sundaystop & & & \\\lsunt
    \tabledatarightlower
    & & & & & \\\lendt
\end{tabularx}
%
\vfill
\footer
\end{document}

你只需要给它

  • 月份名称
  • 星期一日期
  • 星期数

它会给你一周的时间来补充能量!现在,编写一个贯穿 52 周的脚本变得很容易。

此外,女士们,您可以根据自己的需要使用以下方法进行定制:

  • 开始时间(此处:8
  • 末日(此处:21
  • 星期日的高度 - 或多或少是星期六/星期日(此处:14
  • 粗规则的宽度(此处:.15em
  • 行高

其他例子使用:

  • 开始时间:5
  • 时间结束:20
  • 星期日的高度:8

日历2

如果你没有 A5 纸,就打印两张 A4 纸然后裁剪——在一张纸上打印两页会很乱(需要的页面顺序:{2,3}、{4,1}、{6,7}、{8,5},...)。特殊安排的孔可以很容易地完成,如图所示这里

干杯!


编辑

我更改了一些设置,添加了一个月的营业额(例如 31-->1)并对其进行了包装。代码当然不是尽可能优雅,但效果很好。(编辑 2)python2 python3

import calendar

########## CUSTOMIZATIONS ##########

## Year
year=2021

# Labels
months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']
#months = [calendar.LocaleTextCalendar().formatmonthname(year,i,1).split(' ')[0] for i in range(1,13)]

labels = {
    'label_week':       'Week',
    'label_monday':     'Monday',
    'label_tuesday':    'Tuesday',
    'label_wednesday':  'Wednesday',
    'label_thursday':   'Thursday',
    'label_friday':     'Friday',
    'label_saturday':   'Saturday',
    'label_sunday':     'Sunday',
}

## Morning starttime
starttime="8"

## Evening time
stoptime="21"

## Starttime sunday
# Min \starttime+1
# Max \stoptime-2

sundaybegin="14"

## Rule width thick
thickrulewidth="2pt"

## Midrule width
midrulewidth="1pt"

## Thinrule width
thinrulewidth=".5pt"

## Extra space
extrarowheight="1pt"

#
####################################
#

days = {
    0: 'pymond',
    1: 'pytue',
    2: 'pywed',
    3: 'pythur',
    4: 'pyfr',
    5: 'pysat',
    6: 'pysun'
}

#Collect all mondays in a list
mondays = []

for month in range( 1, 13 ):

   for week in calendar.monthcalendar(year,month):

      if not week[0] == 0:
         mondays.append( [week[0], 0] )

# If year doesn't end with a friday, append January to months
if calendar.monthcalendar(year, 12)[-1][-1] == 0:
    months.append( months[0] )

Nweeks = len(mondays)

# Add length of corresponding month to each monday
month = 1
for week in range( Nweeks ):

   Ndaysinmonth = calendar.monthrange( year, month )[1]

   # First week
   if week == 0:
      mondays[week][1] = Ndaysinmonth

   # Increasing day in month => same month
   elif mondays[week][0] > mondays[week-1][0]:
      mondays[week][1] = Ndaysinmonth

   # Next month
   else:
      mondays[week][1] = calendar.monthrange( year, month+1 )[1]
      month+=1

head = r'''
   \documentclass[%
      BCOR=2cm,%  Space for hole puncher
      DIV=30,%   Size of textbody
      paper=a4,%  A4 paper
      fontsize=12pt%    Fontsize
   ]{scrbook}
   %
   %%%%%%%%%% PACKAGES %%%%%%%%%%
   %
   \usepackage{tabularx,booktabs,multirow}
   %\usepackage{pgfpages}
   %\pgfpagesuselayout{2 on 1}[odd numbered pages right,a4paper,landscape,border shrink=0mm]
   %%%%%%%%%% COUNTER %%%%%%%%%%
   %
   \newcount\counter
   \newcount\startdate
   \newcount\starttime
   \newcount\stoptime
   \newcount\sundaybegin
   \newcount\week
   \newcount\datemonday
   \newcount\datetuesday
   \newcount\datewednesday
   \newcount\datethursday
   \newcount\datefriday
   \newcount\datesaturday
   \newcount\datesunday
   %
   %%%%%%%%%% CUSTOMISATIONS %%%%%%%%%%
   %
   %% Morning starttime
   \starttime=pystarttime
   %% Evening time
   \stoptime=pystoptime
   %% Starttime sunday
   % Min \starttime+1
   % Max \stoptime-2
   \sundaybegin=pysundaybegin
   %% Rule width thick
   \newcommand{\rulew}{pyrulewidth}
   %% Midrule width
   \newcommand{\mrulew}{pymidrulewidth}
   %% thinrule width
   \newcommand{\trulew}{pythinrulewidth}
   %% Extra space
   \setlength{\extrarowheight}{pyextrarowheight}
   %
   %%%%%%%%%% DEFINITIONS %%%%%%%%%%
   %
   \newcommand{\lendt}{\cmidrule[\rulew](l){1-2}\cmidrule[\rulew](l){3-4}\cmidrule[\rulew](l){5-6}}
   \newcommand{\lend}[1]{\cmidrule[#1](l){1-2}\cmidrule[#1](l){3-4}\cmidrule[#1](l){5-6}}
   \newcommand{\lsun}[1]{\cmidrule[#1](l){1-2}\cmidrule[#1](l){3-4}}
   \newcommand{\lsunt}[1]{\cmidrule[#1](l){1-2}\cmidrule[#1](l){3-4}\cmidrule[\rulew](l){5-6}}
   \newcommand{\printday}[2]{{\LARGE \textbf{#1}}\,\, \large \textbf{#2}}
   \newcommand{\neutralline}{& & & & &}
   \newcommand{\footer}{\centering\rule{7cm}{\cmidrulewidth} \raisebox{-0.5ex}{pyyear} \rule{7cm}{\cmidrulewidth}}
   \newcommand{\printmonthleft}{{\LARGE \textbf{pymonthleft}}}
   \newcommand{\printmonthright}{{\LARGE \textbf{pymonthright}}}
   %
   \advance\stoptime1
   \begin{document}
   \thispagestyle{empty}
   \mbox{}
   \clearpage
   '''

table = r'''
   %% Weeknumber
   \week=pyweek
   \renewcommand{\printmonthleft}{{\LARGE \textbf{pymonthleft}}}
   \renewcommand{\printmonthright}{{\LARGE \textbf{pymonthright}}}
    %% Dates
   \datemonday=pymond
   \datetuesday=pytue
   \datewednesday=pywed
   \datethursday=pythur
   \datefriday=pyfr
   \datesaturday=pysat
   \datesunday=pysun
   %
   %
   %%%%%%%%%% TABLE CONTENT LEFT SIDE %%%%%%%%%%
   %
   \long\def\addto#1#2{\expandafter\def\expandafter#1\expandafter{#1#2}}
   %
   \def\tabledataleft{} \counter=\the\starttime
   \loop
      \edef\tabline{\the\counter &  & \the\counter & & \the\counter & }
      \expandafter\addto\expandafter\tabledataleft\expandafter{\neutralline \\\lend{\mrulew}}
      \expandafter\addto\expandafter\tabledataleft\expandafter{\tabline \\\lend{\trulew}}
      \advance \counter 1
      \ifnum \counter<\the\stoptime
   \repeat
   %
   %%%%%%%%%% TABLE CONTENT RIGHT SIDE %%%%%%%%%%
   %
   \def\tabledatarightupper{} \counter=\the\starttime
   \loop
      \edef\tabline{\the\counter &  & \the\counter & & & }
      \expandafter\addto\expandafter\tabledatarightupper\expandafter{\neutralline \\\lend{\mrulew}}
      \expandafter\addto\expandafter\tabledatarightupper\expandafter{\tabline \\\lend{\trulew}}
      \advance \counter 1
      \ifnum \counter<\the\sundaybegin
   \repeat
   %
   \advance\sundaybegin1
   \def\tabledatarightinter{} \counter=\the\sundaybegin
   \newcount\sundaystop
   \sundaystop=\the\sundaybegin
   \advance\sundaystop1
   \loop
      \edef\tabline{\the\counter &  & \the\counter & & & }
      \expandafter\addto\expandafter\tabledatarightinter\expandafter{\neutralline \\\lsun{\mrulew}}
      \expandafter\addto\expandafter\tabledatarightinter\expandafter{\tabline \\\lsun{\trulew}}
      \advance \counter 1
      \ifnum \counter<\the\sundaystop
   \repeat
   \advance\sundaybegin-1
   \advance\sundaystop1
   %
   \def\tabledatarightlower{} \counter=\the\sundaystop
   \loop
      \edef\tabline{\the\counter &  & \the\counter & & & }
      \expandafter\addto\expandafter\tabledatarightlower\expandafter{\neutralline \\\lend{\mrulew}}
      \expandafter\addto\expandafter\tabledatarightlower\expandafter{\tabline \\\lend{\trulew}}
      \advance \counter 1
      \ifnum \counter<\the\stoptime
   \repeat
   \advance\sundaystop-1
   %
   \pagestyle{empty}
   \enlargethispage{1cm}
   %
   %%%%%%%%%% LEFT TABLE %%%%%%%%%%
   %
   \noindent
   \begin{tabularx}{\linewidth}{lXlXlX}
      \multicolumn{6}{l}{\printmonthleft \hfill {label_week} \the\week}\\[.2em]\midrule[\rulew]
      \addlinespace[.5em]
      \multicolumn{2}{l}{\printday{\the\datemonday}{label_monday}}     &%
      \multicolumn{2}{l}{\printday{\the\datetuesday}{label_tuesday}}   &%
      \multicolumn{2}{l}{\printday{\the\datewednesday}{label_wednesday}}\\[2cm]
       & & & & & \\\lendt
      \tabledataleft
       & & & & & \\\lendt
   \end{tabularx}
   %
   \vfill
   \footer
   %
   \clearpage
   \enlargethispage{1cm}
   %
   %%%%%%%%%% RIGHT TABLE %%%%%%%%%%
   %
   \noindent
   \begin{tabularx}{\linewidth}{lXlXlX}
      \multicolumn{6}{l}{Week \the\week \hfill \printmonthright}\\[.2em]\midrule[\rulew]
      \addlinespace[.5em]
      \multicolumn{2}{l}{\printday{\the\datethursday}{label_thursday}}  &%
      \multicolumn{2}{l}{\printday{\the\datefriday}{label_friday}}     &%
      \multicolumn{2}{l}{\printday{\the\datesaturday}{label_saturday}}  \\[2cm]
      & & & & & \\\lendt
      \tabledatarightupper
      & & & & & \\\lsunt{\mrulew}
      \addlinespace[-.15em]
      \the\sundaybegin & & \the\sundaybegin & & \multicolumn{2}{l}{\multirow{4}{*}[1.5em]{\printday{\the\datesunday}{label_sunday}}}\\\lsun{\trulew}
      \tabledatarightinter
      & & & & & \\\lsun{\mrulew}
      \the\sundaystop & & \the\sundaystop & & & \\\lsunt{\trulew}
      \tabledatarightlower
      & & & & & \\\lendt
   \end{tabularx}
   %
   \vfill
   \footer
   \clearpage'''

for key in labels:
    table = table.replace(key, labels[key])

foot = r'''\end{document}'''

head = head.replace("pyyear",         str(year)      )
head = head.replace("pystarttime",     starttime      )
head = head.replace("pystoptime",      stoptime      )
head = head.replace("pysundaybegin",   sundaybegin    )
head = head.replace("pyextrarowheight", extrarowheight  )
head = head.replace("pyrulewidth",     thickrulewidth  )
head = head.replace("pymidrulewidth",   midrulewidth   )
head = head.replace("pythinrulewidth", thinrulewidth   )

print(head)

week_label = 1

if mondays[0][0] != 1:
   week_label += 1

currentmonth = 0
for week in range(Nweeks):

   table_temp = table
   trigger = 0

   for weekday in range(7):

      date = mondays[week][0] + weekday

      # If it's monday 1 st, increase currentmonth unless it's January 1 st.
      if date == 1 and not (mondays[0][0] == 1 and currentmonth == 0):
         currentmonth += 1
         trigger = 1

      # If next month
      if date > mondays[week][1]:

         date = date - mondays[week][1]

         if trigger == 0:
            currentmonth += 1
            trigger = 1

         # Print right page
         if weekday > 2:
            table_temp = table_temp.replace('pymonthright', months[currentmonth])

         # Print left page
         else:
            table_temp = table_temp.replace('pymonthleft', months[currentmonth])

      else:

         # Print left page
         if weekday == 2:
            table_temp = table_temp.replace('pymonthleft', months[currentmonth])

         # Print right page
         elif weekday == 6:
            table_temp = table_temp.replace('pymonthright', months[currentmonth])

      table_temp = table_temp.replace(days[weekday], str(date))

   table_temp = table_temp.replace("pyweek", str(week_label))
   print(table_temp)
   week_label += 1

print(foot)

它将 LaTeX 源打印到标准输出,因此可以通过以下方式使用它:

python script.py > filename.tex && pdflatex filename.tex

此外,我还添加了参数(比较下面):

  • thickrulewidth
  • midrulewidth
  • thinrulewidth

现在,所有标签都可以在 CUSTOMIZATIONS 块中轻松更改。

最终的

编辑2

截至 2018 年,代码已损坏。再次仔细查看细节时,我注意到我上传的代码是多么糟糕。对此我感到很抱歉,现在已重写了大部分代码。

上述更新后的代码现在python3符合规范、注释清晰、可读性强,在定制方面更加灵活,而且——最重要的是——在未来几年内也能使用。新年快乐!


编辑3

又过了几年。这里是 2021 年至 2029 年的简易汇编。

相关内容