Termcal 日历未居中

Termcal 日历未居中

由于某种原因,我的 termcal 日历未正确置于中心环境中。MWE 是:

\documentclass{article}
\usepackage{termcal}
\begin{document}
\begin{center}
\begin{calendar}{9/30/2013}{11}
\setlength{\calboxdepth}{.3in}
\setlength{\calwidth}{0.8\textwidth} 
% week description
\skipday
\calday[Tuesday]{\classday}
\skipday
\calday[Thursday]{\classday}
\skipday\skipday\skipday
\end{calendar}
\end{center}
\end{document}

但这并没有让我的日历居中,如下所示screenshot

答案1

termcal包使用longtable 来排版日历,并将日历硬编码为左对齐。您可以calendar使用以下方式修补环境的相关部分etoolbox以获得所需的内容:

\documentclass{article}
\usepackage{termcal}
\usepackage{etoolbox}
\patchcmd{\endcalendar}{[l]}{[c]}{}{}
\begin{document}

\begin{calendar}{9/30/2013}{11}

\setlength{\calboxdepth}{.3in}
\setlength{\calwidth}{0.8\textwidth} 
% week description
\skipday
\calday[Tuesday]{\classday}
\skipday
\calday[Thursday]{\classday}
\skipday\skipday\skipday
\end{calendar}
\end{document}

另一个选择是重新定义calendar环境以接受一个可选参数,允许指定日历所需的对齐方式;这是一种可能的重新定义,将(居中)作为对齐的默认值;该示例说明了默认值,并展示了(左对齐)和(右对齐)c的用法:lr

\documentclass{article}
\usepackage{termcal}
\usepackage{lipsum}

\makeatletter
\renewenvironment{calendar}[3][c]%
 {%
   \setcounter{ca@numwks}{#3}
   \setdate{#2}
   \setcounter{ca@dpw}{0}
   \setcounter{classnum}{1}
   \gdef\calalign{#1}
 }
  {
   \ifca@chead\ca@doweeks{\the\ca@colhead\endhead\hline\hline}\fi
   \setcounter{ca@wknum}{0}
   \whiledo{\value{ca@wknum}<\value{ca@numwks}}%
            {\stepcounter{ca@wknum}%
             \addtotoks{\ca@doweeks}{\the\ca@doaweek\\\hline}}
   \ca@boxwidth=\calwidth
   \divide\ca@boxwidth by \c@ca@dpw\relax
   \advance\ca@boxwidth by -2\tabcolsep\relax
   \setlength\@tempdima\arrayrulewidth\relax
   \multiply\@tempdima\c@ca@dpw\relax
   \advance\@tempdima\arrayrulewidth\relax
   \divide\@tempdima\c@ca@dpw\relax
   \advance\ca@boxwidth by -\@tempdima\relax
   \begin{longtable}[\calalign]
   {|*{\theca@dpw}{p{\ca@boxwidth}|}@{}}%
      \hline
      \the\ca@doweeks
    \end{longtable}
   }
\makeatother

\begin{document}

\lipsum[4]
\begin{calendar}{9/30/2013}{2}
\setlength{\calboxdepth}{.3in}
\setlength{\calwidth}{0.5\textwidth} 
% week description
\skipday
\calday[Tuesday]{\classday}
\end{calendar}

\begin{calendar}[l]{9/30/2013}{2}
\setlength{\calboxdepth}{.3in}
\setlength{\calwidth}{0.5\textwidth} 
% week description
\skipday
\calday[Tuesday]{\classday}
\end{calendar}

\begin{calendar}[r]{9/30/2013}{2}
\setlength{\calboxdepth}{.3in}
\setlength{\calwidth}{0.5\textwidth} 
% week description
\skipday
\calday[Tuesday]{\classday}
\end{calendar}
\lipsum[4]

\end{document}

enter image description here

相关内容