防止在表格前分页

防止在表格前分页

我在用着这个简单但有用的日历模板

在日历(基本上是tabularx)上方,我放了一个非常基本的标题,如下所示:

\begin{center}
    \textsc{\LARGE August}
\end{center}
\begin{calendar}{\linewidth}
    ...
\end{calendar}

如何防止 Latex 在页眉和日历之间执行分页符?我尝试放置一个\nopagebreak,但没有成功。如果我有多个日历,分页符总是在页眉之后发生。因此,在每一页上,我都有日历,后面跟着下一页的月份名称。

答案1

您可以修补calendar环境,使其接受显示为标题的可选参数。这将是环境的一部分tabularx,因此不会与环境分离。

\documentclass[landscape,a4paper]{article}

\usepackage{calendar} % Use the calendar.sty style
\usepackage[landscape,margin=0.5in]{geometry}

\usepackage{xpatch}

\makeatletter
% patch \calendar to insert a header
\xpatchcmd{\calendar}
  {\hline\ifnum}
  {\month@header\hline\ifnum}
  {}{}
% fix an error in the macros
\xpatchcmd{\calendar}
  {\newdimen\@calendarwidth}
  {}
  {}{}
% the dimen register should be allocated outside the environment
\newdimen\@calendarwidth
% get an alias for the original macro
\let\originalcalendar\calendar

% add definitions for the header
\newcommand{\month@header}{} % default is doing nothing
% if an optional argument is passed, print it as a header
\newcommand{\month@header@print}[1]{%
  \multicolumn{7}{c}{\parbox{.5\@calendarwidth}{\centering#1}}\\[2\topsep]
}

% redefine \calendar to look for an optional argument and
% then call the original macro
\renewcommand\calendar[1][]{%
  \if\relax\detokenize{#1}\relax
  \else
    \def\month@header{\month@header@print{#1}}%
  \fi
  \originalcalendar
}
\makeatother


\begin{document}

\pagestyle{empty} % Removes the page number from the bottom of the page

\StartingDayNumber=1 % Calendar starting day, default of 1 means Sunday, 2 for Monday, etc

\begin{center}
\end{center}

\begin{calendar}[
  \textsc{\LARGE Month}\\ % Month
  \textsc{\large Year} % Year
]{\textwidth}

\BlankDay
\BlankDay

\setcounter{calendardate}{1} % Start the date counter at 1

\day{Work}{10am Meeting with Boss \\[6pt] 12pm Meeting with Group} % 1 - Example of content
\day{}{\vspace{2.5cm}} % 2 
\day{}{\vspace{2.5cm}} % 3
\day{}{\vspace{2.5cm}} % 4
\day{}{\vspace{2.5cm}} % 5
\day{}{\vspace{2.5cm}} % 6
\day{}{\vspace{2.5cm}} % 7
\day{}{\vspace{2.5cm}} % 8
\day{}{\vspace{2.5cm}} % 9
\day{}{\vspace{2.5cm}} % 10
\day{}{\vspace{2.5cm}} % 11
\day{}{\vspace{2.5cm}} % 12
\day{}{\vspace{2.5cm}} % 13
\day{}{\vspace{2.5cm}} % 14
\day{}{\vspace{2.5cm}} % 15
\day{}{\vspace{2.5cm}} % 16
\day{}{\vspace{2.5cm}} % 17
\day{}{\vspace{2.5cm}} % 18
\day{}{\vspace{2.5cm}} % 19
\day{}{\vspace{2.5cm}} % 20 
\day{}{\vspace{2.5cm}} % 21
\day{}{\vspace{2.5cm}} % 22
\day{}{\vspace{2.5cm}} % 23
\day{}{\vspace{2.5cm}} % 24
\day{}{\vspace{2.5cm}} % 25
\day{}{\vspace{2.5cm}} % 26
\day{}{\vspace{2.5cm}} % 27
\day{}{\vspace{2.5cm}} % 28
\day{}{\vspace{2.5cm}} % 29 
\day{}{\vspace{2.5cm}} % 30 
\day{}{\vspace{2.5cm}} % 31

\finishCalendar
\end{calendar}
\end{document}

在此处输入图片描述

相关内容