Graphics, Figures & Tablesrow heights and alignment for multirow

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
CoolnessItself
Posts: 47
Joined: Wed Nov 11, 2009 9:30 pm

row heights and alignment for multirow

Post by CoolnessItself »

Two problems with the below code:
1) Long text falls into the next row
2) alignments from \begin{tabular}{|alignments|} not trickling down into multirow

How would I fix this?

Code: Select all

\documentclass[12pt]{article}
\usepackage[utf8]{inputenc}
\usepackage{multirow}


\begin{document}
\begin{tabular}{|c|c|c|c|c|c|}
\hline
\multicolumn{6}{|c|}{Schedule Example} \\
\hline
Time & M & T & W & R & F \\\hline
11:00am & &&&&\\\hline
12:00pm & &&&&\\\hline
1:00pm & &&&&\\\hline
2:00pm & \multirow{2}{2cm}{A longgggg team meeting} & & \multirow{2}{2cm}{Team Meeting} & & \multirow{2}{2cm}{Team Meeting} \\
3:00pm & & &&& \\\hline
4:00pm & & &&& \\\hline
5:00pm & & &&& \\\hline
6:00pm & & \multirow{2}{1cm}{Dinner \& Movie}  & &\multirow{2}{1cm}{Dinner}   &\\
7:00pm& & &&& \\
\hline
\end{tabular}
\end{document}

Recommended reading 2024:

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

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

gmedina
Posts: 2313
Joined: Wed Jul 11, 2007 11:45 pm

row heights and alignment for multirow

Post by gmedina »

Hi,

a first approach:

Code: Select all

\documentclass[12pt]{article}
\usepackage[utf8]{inputenc}
\usepackage{array}
\usepackage{multirow}

\newcommand\mcc[1]{\multicolumn{1}{c|}{#1}}

\begin{document}

{% to keep some settings local
\footnotesize
\setlength\tabcolsep{1.2pt}
\renewcommand\extrarowheight{1.5pt}
\begin{tabular}{|c|p{2.3cm}|p{2cm}|p{2cm}|p{2cm}|p{2cm}|}
  \hline
  \multicolumn{6}{|c|}{Schedule Example} \\
  \hline
  Time & \mcc{M} & \mcc{T} & \mcc{W} & \mcc{R} & \mcc{F} \\\hline
  11:00am & & & & & \\\hline
  12:00pm & & & & & \\\hline
  1:00pm & & & & & \\\hline
  2:00pm & \multirow{2}{*}{\parbox{2.3cm}{\centering A longgg team meeting}} & & 
    \multirow{2}{2cm}{\centering Team Meeting} & & 
    \multirow{2}{2cm}{\centering Team Meeting} \\
  3:00pm & & & & & \\\hline
  4:00pm & & & & & \\\hline
  5:00pm & & & & & \\\hline
  6:00pm & & \multirow{2}{*}{\parbox{2cm}{\centering Dinner \&\\ Movie}}  & &
    \multirow{2}{*}{\parbox{2cm}{\centering Dinner}} & \\
  7:00pm & & & & & \\
  \hline
\end{tabular}
}

\end{document}
Edit: I did some changes to center the contents of the cells.
1,1,2,3,5,8,13,21,34,55,89,144,233,...
CoolnessItself
Posts: 47
Joined: Wed Nov 11, 2009 9:30 pm

Re: row heights and alignment for multirow

Post by CoolnessItself »

Looks good, but what if "loong team meeting" becomes "longgg team meeting that keeps going and going and going"
I can't keep increasing the width of the cells to hold the text. How would I change the row height?
User avatar
gmedina
Posts: 2313
Joined: Wed Jul 11, 2007 11:45 pm

row heights and alignment for multirow

Post by gmedina »

In that case, I would suggest you to declare your columns using either the p{<length>} or the m{<length>} construct, without using \multirow. A little example:

Code: Select all

\documentclass[12pt]{article}
\usepackage[utf8]{inputenc}
\usepackage{array}

\newcolumntype{A}[1]{>{\centering\arraybackslash}p{#1}}

\begin{document}

{% to keep some settings local
\footnotesize
\setlength\tabcolsep{1.2pt}
\renewcommand\extrarowheight{1.5pt}
\begin{tabular}{|A{1.4cm}|A{2cm}|A{2cm}|A{2cm}|A{2cm}|A{2cm}|}
  \hline
  \multicolumn{6}{|c|}{Schedule Example} \\
  \hline
  Time & M & T & W & R & F \\\hline
  11:00am & & & & & \\\hline
  12:00pm & & & & & \\\hline
  1:00pm & & & & & \\\hline
  2:00pm 3:00pm & A long team meeting and some additional text & & 
    Team Meeting & & Team Meeting \\\hline
  4:00pm & & & & & \\\hline
  5:00pm & & & & & \\\hline
  6:00pm 7:00pm & & Dinner \& Movie & &
    Dinner & \\
  \hline
\end{tabular}
}

\end{document}
Change p{#1} to m{#1} in the above code to obtain cells with centered vertical alignment.
1,1,2,3,5,8,13,21,34,55,89,144,233,...
CoolnessItself
Posts: 47
Joined: Wed Nov 11, 2009 9:30 pm

Re: row heights and alignment for multirow

Post by CoolnessItself »

But what if I have a Monday 6-7:00pm appointment as well? ie something that last half of "Dinner & Movie." I would have to make 6 and 7 different rows to accommodate different days of the week, but auto-row-height-adjustment doesn't work for the first solution of this thread involving multirow...
User avatar
gmedina
Posts: 2313
Joined: Wed Jul 11, 2007 11:45 pm

row heights and alignment for multirow

Post by gmedina »

Something like this?

Code: Select all

\documentclass[12pt]{article}
\usepackage[utf8]{inputenc}
\usepackage{array,multirow}

\newcolumntype{A}[1]{>{\centering\arraybackslash}p{#1}}

\begin{document}

{% to keep some settings local
\footnotesize
\setlength\tabcolsep{1.2pt}
\renewcommand\extrarowheight{1.5pt}
\begin{tabular}{|A{1.4cm}|A{2cm}|A{2cm}|A{2cm}|A{2cm}|A{2cm}|}
  \hline
  \multicolumn{6}{|c|}{Schedule Example} \\
  \hline
  Time & M & T & W & R & F \\\hline
  11:00am & & & & & \\\hline
  12:00pm & & & & & \\\hline
  1:00pm & & & & & \\\hline
  2:00pm 3:00pm & A long team meeting and some additional text & & 
    Team Meeting & & Team Meeting \\\hline
  4:00pm & & & & & \\\hline
  5:00pm & & & & & \\\hline
  6:00pm & Some important appointment & \multirow{4}{*}{\parbox{2cm}{%
    \centering Dinner \& Movie}} & & \multirow{4}{*}{\parbox{2cm}{\centering Dinner}} & 
    \\\cline{1-2}
  7:00pm & & & & & \\
  \hline
\end{tabular}
}

\end{document}
1,1,2,3,5,8,13,21,34,55,89,144,233,...
CoolnessItself
Posts: 47
Joined: Wed Nov 11, 2009 9:30 pm

Re: row heights and alignment for multirow

Post by CoolnessItself »

But \cline has no support for something like \cline{1-2,4,6}, which would be needed.
The first solution would allow this, but didn't auto-stretch the multirow's containing cell. The second solution doesn't allow this, but auto-stretches. Is there a happy medium?
It would be nice if you could design a table with blank entries, then go back and say \filltable{col=3,row=1-2}{Content for col 3, rows 1 and 2}
and it would auto-stretch rows and columns, unless you specify a height and width or something. Nothing like this exists already? Or at least something that achieves the same effect?
Post Reply