Graphics, Figures & TablesCustomizing Tables

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
SDavid
Posts: 3
Joined: Thu Jul 21, 2011 8:27 pm

Customizing Tables

Post by SDavid »

Hi,

I am trying to do a time table as in the following code:

Code: Select all

\documentclass[a4paper]{report}
\usepackage{lscape}
\usepackage{multirow}
\usepackage{bigstrut}
\usepackage{array}

\begin{document}
\thispagestyle{empty}
\pagestyle{empty}  
\begin{landscape}
\begin{tabular}{*{11}{| m{1.5cm} |}}
\cline{3-11}
& & \multicolumn{9}{|c|}{Week}\\\cline{3-11}
  &            & Week 1 & Week 2 & Week 3 & Week 4 & Week 5 &Week 6& Week 7 & Week 8 & Week 9 \\\cline{1-11}
              \multicolumn{1}{|c|}{\multirow{4}{*}{Course}} & \multicolumn{1}{|c|}{Course 1} &  &  &  & & &  & & &\\\cline{2-11}
              
              & \multicolumn{1}{|c|}{Course 2} & &  & &  & &  &  &  &\\\cline{2-11}
              & \multicolumn{1}{|c|}{Course 3} &  &  &  &  &  &  &  &  &\\\cline{2-11}
               & \multicolumn{1}{|c|}{Course 4} &  & &  &  &  &  &  & &\\\cline{1-11}
\end{tabular}
\end{landscape}
\end{document}
and I have some questions:
  1. How to make the area over the first two columns (in the first two rows) completely blank?
  2. How to align the writing in each cell to the center of the cell and maintaining the tabular argument above? I need the effect of |c| and |m{}| together.
  3. Why is there double lines between columns?!
Thanks in advance

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

Stefan Kottwitz
Site Admin
Posts: 10345
Joined: Mon Mar 10, 2008 9:44 pm

Customizing Tables

Post by Stefan Kottwitz »

Hi SDavid,

welcome to the board!

It's great that you posted a compilable minimal example. So of course I test your code and make suggestions.

Regarding your questions:
  1. Use for example

    Code: Select all

    \multicolumn{2}{c}{}
    without |. This overrides the |...| setting in the tabular options.
  2. You can define your own column type which is centered both vertically and horizontally, such as

    Code: Select all

    \newcolumntype{M}[1]{>{\centering\arraybackslash}m{#1}}
  3. That's because of your column definition. *{11}{| m{1.5cm} | expands to | m{1.5cm} || m{1.5cm} || m{1.5cm} |... Simply write

    Code: Select all

    \begin{tabular}{|*{11}{M{1.5cm}|}}
Complete example:

Code: Select all

\documentclass[a4paper]{report}
\usepackage{lscape}
\usepackage{multirow}
\usepackage{bigstrut}
\usepackage{array}
\newcolumntype{M}[1]{>{\centering\arraybackslash}m{#1}}
\begin{document}
\thispagestyle{empty}
\pagestyle{empty} 
\begin{landscape}
\begin{tabular}{|*{11}{M{1.5cm}|}}
\cline{3-11}
\multicolumn{2}{c|}{} & \multicolumn{9}{c|}{Week}\\\cline{3-11}
\multicolumn{2}{c|}{}             & Week 1 & Week 2 & Week 3 & Week 4 & Week 5 &Week 6& Week 7 & Week 8 & Week 9 \\\cline{1-11}
              \multicolumn{1}{|c|}{\multirow{4}{*}{Course}} & \multicolumn{1}{|c|}{Course 1} &  &  &  & & &  & & &\\\cline{2-11}
             
              & \multicolumn{1}{|c|}{Course 2} & &  & &  & &  &  &  &\\\cline{2-11}
              & \multicolumn{1}{|c|}{Course 3} &  &  &  &  &  &  &  &  &\\\cline{2-11}
               & \multicolumn{1}{|c|}{Course 4} &  & &  &  &  &  &  & &\\\cline{1-11}
\end{tabular}
\end{landscape}
\end{document}
Btw. in general I recommend to avoid vertical lines in tables, they make reading lines harder.

Stefan
LaTeX.org admin
SDavid
Posts: 3
Joined: Thu Jul 21, 2011 8:27 pm

Re: Customizing Tables

Post by SDavid »

Thank you Stefan, that is perfect.

Regards
Post Reply