# Termcal calendar not centered

For some reason, my termcal calendar is not being properly centered by being placed within a center environment. The MWE is:

\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}


but this doesn't center my calendar, as shown here

-
Please make your example start \documentclass and end \end{document} so the problem may be reproduced. (that's what the W in MWE means) that said, try \mbox{}\begin{calendar} –  David Carlisle Sep 6 '13 at 21:56

The termcal package uses a longtable to typeset the calendar and hard codes the calendar to be left justified. You can patch the relevant part of the calendar environment using etoolbox to get what you need:

\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}


Another option would be to redefine the calendar environment to admit one optional argument allowing to specify the desired alignment for the calendar; here's such a possible redefinition, taking c (centered) as the default value for the alignment; the example illustrates the default and also shows the use of l (left justified) and r (right justified):

\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}
}
{
\setcounter{ca@wknum}{0}
\whiledo{\value{ca@wknum}<\value{ca@numwks}}%
{\stepcounter{ca@wknum}%
\ca@boxwidth=\calwidth
\divide\ca@boxwidth by \c@ca@dpw\relax
\setlength\@tempdima\arrayrulewidth\relax
\multiply\@tempdima\c@ca@dpw\relax
\divide\@tempdima\c@ca@dpw\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}


-
Great, that worked even without the center environment. –  Kyle Niemeyer Sep 6 '13 at 22:16
-1 for blaming longtable :-) –  David Carlisle Sep 6 '13 at 22:26
I made an edit adding a redefinition of calendar so as to admit an optional argument to specify the desired alignment. I hope it's OK, but, of course, feel free to roll it back if you don't like it :-) –  Gonzalo Medina Sep 7 '13 at 0:37
@GonzaloMedina Since the calendar is usually the kind of thing you use only once per document, it's not clear there's a great advantage to doing this. It would probably be simpler to make a wrapper for the patch command. –  Alan Munn Sep 7 '13 at 1:15
@AlanMunn well, yes, the idea was to illustrate that, in my opinion, allowing to specify the alignment should have been the original definition. I was just trying to show to beginners how this can be done. Anyway, feel free to roll back the edit. –  Gonzalo Medina Sep 7 '13 at 1:23