# How to recreate the following table in LaTeX similarly?

The following is the original table

and I have the following code

\begin{table}
\caption{February}
\begin{center}
\begin{tabular}{c|c|c|c|c|c|c}

\hline
M & T & W & Th & F & S & Su\\
\hline
& C & &&C&C&\\
\hline
& C & &C&C&& \\
\hline
& C&&&C&C&C \\
\hline
& C & & &C & C & \\
\hline
\end{tabular}
\end{center}
\end{table}

\begin{table}
\caption{March}
\begin{center}
\begin{tabular}{c|c|c|c|c|c|c}

\hline
M & T & W & Th & F & S & Su\\
\hline
& C & C&C&C&C&\\
\hline
& C & &C&&& \\
\hline
& C&C&&C&C& \\
\hline
& C &C & &C & C & \\
\hline
& C& &\\
\hline
\end{tabular}
\end{center}
\end{table}


which produces the following:

How do you make it so that

1. the tables are side-by-side?
3. and only three cells in the last row of the march is bordered?
-

To color a row you can use \rowcolor and to underline the first 3 cells use \cline{1-3}.

If you do not need the floats, here is how I would do it.

\documentclass{article}
\usepackage{xcolor,colortbl}

\begin{document}
\begin{tabular}{|c|c|c|c|c|c|c|}
\hline
\rowcolor{gray!40}
M & T & W & Th & F & S & Su \\ \hline
& C & & & C & C &          \\ \hline
& C & & C & C & &          \\ \hline
& C & & & C & C & C        \\ \hline
& C & & & C & C &          \\ \hline
\end{tabular}
\hspace{2em} %space between tables
\begin{tabular}{|c|c|c|c|c|c|c|}
\hline
\rowcolor{gray!40}
M & T & W & Th & F & S & Su \\ \hline
& C & C & C & C & C &      \\ \hline
& C & & C & & &            \\ \hline
& C & C & & C & C &        \\ \hline
& C & C & & C & C &        \\ \hline
& C &                      \\ \cline{1-3}
\end{tabular}
\end{document}


Resulting in

-
To align the tables at the top, you may use [t] for both of them like \begin{tabular}[t]{|c|c|c|c|c|c|c|} –  Harish Kumar Feb 22 '13 at 22:12
@HarishKumar While we’re at it: \begin{tabular}[t]{|*7{c|}} I would even use either X from tabularx or p{<wd>} to get columns of same width. –  Qrrbrbirlbel Feb 22 '13 at 22:16

Here's an implementation with LaTeX3 features; you just supply the month, the initial month's day (in abbreviated form) and the list of special days.

\documentclass{article}
\usepackage{xparse}
\usepackage{xcolor,colortbl}

\ExplSyntaxOn
% #1 = month name, #2 = initial day of week, #3 = list of days
\NewDocumentCommand{\monthtable}{ m m m }
{
\alby_monthtable:nnn { #1 } { #2 } { #3 }
}

\cs_new_protected:Npn \alby_monthtable:nnn #1 #2 #3
{
%% compute the number of days from the month name
\int_set:Nn \l_alby_days_int
{
\str_case:nnn { #1 }
{
{January}{31}
{February}{28}
{Februaryleap}{29}
{March}{31}
{April}{30}
{May}{31}
{June}{30}
{July}{31}
{August}{31}
{September}{30}
{October}{31}
{November}{30}
{December}{31}
}
{OOPS}
}
%% compute the initial shift
\int_set:Nn \l_alby_initial_int
{
\str_case:nnn { #2 }
{
{Mo}{0}
{Tu}{1}
{We}{2}
{Th}{3}
{Fr}{4}
{Sa}{5}
{Su}{6}
}
{OOPS}
}
%% the table body is stored in \l_alby_table_tl
%% compose the first table row
\tl_set:Nn \l_alby_table_tl
{
\rowcolor{gray!40}
\makebox[1.5em]{Mo} &
\makebox[1.5em]{Tu} &
\makebox[1.5em]{We} &
\makebox[1.5em]{Th} &
\makebox[1.5em]{Fr} &
\makebox[1.5em]{Sa} &
\makebox[1.5em]{Su} \\ \hline }
%% if the initial shift is non zero, we add a \multicolumn
\int_compare:nT { \l_alby_initial_int > 0 }
{ \tl_put_right:Nn \l_alby_table_tl { \multicolumn{\l_alby_initial_int}{c|}{} & } }
%% store in \l_alby_cdays_seq the list of special days
\seq_set_split:Nnn \l_alby_cdays_seq { , } { #3 }
%% loop through the days to add cells
\int_step_inline:nnnn { 1 } { 1 } { \l_alby_days_int}
{
%% if the day is special, add a C
\seq_if_in:NxT \l_alby_cdays_seq { \int_to_arabic:n { ##1 } }
{ \tl_put_right:Nn \l_alby_table_tl { C } }
%% if the day is not the last, add & or \\\hline, according
%% if we are at the end of a row or not
\int_compare:nF { ##1 == \l_alby_days_int }
{
\int_compare:nTF
{\int_mod:nn { ##1 + \l_alby_initial_int } { 7 } == 0 }
{\tl_put_right:Nn \l_alby_table_tl { \\ \hline } }
{\tl_put_right:Nn \l_alby_table_tl { & } }
}
}
%% finally, add \\\hline if the month ends with Sunday, or add
%% a suitable \\\cline{1-x} command
\int_compare:nTF { \int_mod:nn { \l_alby_initial_int + \l_alby_days_int } { 7 } == 0 }
{
\tl_put_right:Nn \l_alby_table_tl { \\ \hline }
}
{
\tl_put_right:Nx \l_alby_table_tl
{
\exp_not:n { \\ \cline }
{ 1 - \int_to_arabic:n { \int_mod:nn { \l_alby_initial_int + \l_alby_days_int } { 7 } } }
}
}
%% print the table
\begin{tabular}{|c|c|c|c|c|c|c|}
\hline
\l_alby_table_tl
\end{tabular}
}

%% the needed variables
\int_new:N \l_alby_days_int
\int_new:N \l_alby_initial_int
\tl_new:N \l_alby_table_tl
\seq_new:N \l_alby_cdays_seq
\ExplSyntaxOff

\begin{document}
\monthtable{February}{Fr}{1,3,5,7,9,11,13,15,17,19,21,23,25,28}

\bigskip

\monthtable{April}{Mo}{1,30}
\end{document}


For a leap year, use Februaryleap as the month name.

The initial day might be computed from the year, but it's much more work.

-

Some more general remarks:

1. Excel2LaTeX is quite good at creating LaTeX code for tableaux with horizontal and vertical borders, merged cells, etc.. (Disclaimer: I have contributed parts of the relevant code.)

2. There is a dedicated TikZ library, calendar, which helps creating custom calendars -- there are also quite a few questions on that topic on TeX.SX already. I'm not sure about borders, though.

-