# Dynamically calculated Row height in Tables

I am trying to dynamically allocate the height of rows in a table based upon a number, specifically the number of minutes that are devoted to a specific activity in a class lesson. The table represents the lesson plan which is broken up into parts, a large row indicates a longer activity, and a short row a short activity etc. I can see how to adjust the row height by using \[2em] at the end of the row, but I would rather calculate this value from item 1, since the row height should be proportional to the number of minutes in the activity, I also calculate a running total so that the teacher can easily when each part of the lesson starts, durring the hour, and that works fine.

See the definitions for \R, I have been strugleing with this for a few days and not getting anywhere, any help would be greatly appreciated.

\documentclass[11pt]{article} % use larger type; default would be 10pt

% ----------------- my lesson customisations -------------------------------------------------------

\usepackage{pgf}
\usepackage{tabulary}
\usepackage{pdflscape}

\newcounter{LessonNumber}
\setcounter{LessonNumber}{0}

% The following command takes an integer minute value and returns it in hour:min format
\newcommand{\hourFormat}[1]{  0:{\pgfmathparse{int(#1/10)}\pgfmathresult}{\pgfmathparse{int(mod(#1,10))}\pgfmathresult} }

% \hline % works before the \hourFormat

\newcommand{\rowHeight}[1]{  {\pgfmathparse{int(#1*0.4 + 0.5)}\pgfmathresult}  }

\def\R #1|#2|#3|#4 {\hline \hourFormat{\theMinsIntoLesson}  \addtocounter{MinsIntoLesson}{#1}   & #2 & #3 & #4  }%  <-- Works but not calculating the row height.
% \def\R #1|#2|#3|#4 {\hline \hourFormat{\theMinsIntoLesson}  \addtocounter{MinsIntoLesson}{#1}   & #2 & #3 &  #4[\rowHeight{#1}em] } <-- Calculates Row height, but does not effect the heigh, param not passed to tabular.
% \def\R #1|#2|#3|#4 {\hline \hourFormat{\theMinsIntoLesson}  \addtocounter{MinsIntoLesson}{#1}   & #2 & #3 &  #4\\[\rowHeight{#1}em] }%  <--- DOESNT WORK

% Keep track of the time/minutes in the lesson.
\newcounter{MinsIntoLesson}

\newcommand{\timelineheader}{ \textbf{Time} & \textbf{\mbox{Content}} & \textbf{Learning Activities} & \textbf{Resources} \\  \hline}
\newcommand{\timelinecolors}{ } % \rowcolors{2}{white}{cyan!25} }

%%%% Begining of the lesson

\newenvironment{nulesson}[4]{       % #1 is the lesson title
\newpage
\setcounter{MinsIntoLesson}{-60}

\subsubsection{{Lesson \theLessonNumber} #1, #3} % \begin{flushright}#3\end{flushright}

At the end of this lesson students should be able to ... }{\newpage} % End of newenvironment

% ---------------------------- Start of Document -----------------------------
\begin{document}

\begin{landscape}
\renewcommand{\arraystretch}{0.5}
\begin{nulesson}{Unit overview and Review of Statistics}{Ch 4. Sec 4.}{SM1,SM2}{Unit overview and Review of Statistics}

% Lesson Time line planning
\begin{table}[h]
\timelinecolors
\begin{tabulary}{\linewidth}{c | L | L | L}
\R 5  | \mbox{Introduction} | Students enter class, roll call and lesson goal displayed on projector  | Roll  \\[2em]
\R 5  | Ted Talk | The teacher presents a short  Ted talk by Arthur Benjamin  |  www.ted.com \\[2em]
\R 20 | Unit Overview  |Teacher led discussion reviewing the unit material | Overhead projector \\[10em]
\R 25  | Review of statistical Measures | Formative assessment to assess the students abilities | Formative Assessment  \\[10em]
\R 5  | Lesson Close | Lesson review and students tidy desks and leave class  |  \\[2em]
\end{tabulary}
\end{table}
\end{nulesson}

\end{landscape}

\end{document}


All that I did was to add a \rule[\dimexpr9pt-#1\hunits\relax]{0pt}{#1\hunits} to the 1st column definition of \R, where \hunits was chosen to meet the overall height (time) constraints. In this case, \hunits is set to 3.5 pt, meaning each minute of your lesson gets 3.5pt of vertical space.

\documentclass[11pt]{article} % use larger type; default would be 10pt

% ----------------- my lesson customisations -------------------------------------------------------

\usepackage{pgf}
\usepackage{tabulary}
\usepackage{pdflscape}

\newcounter{LessonNumber}
\setcounter{LessonNumber}{0}

% The following command takes an integer minute value and returns it in hour:min format
\newcommand{\hourFormat}[1]{  0:{\pgfmathparse{int(#1/10)}\pgfmathresult}{\pgfmathparse{int(mod(#1,10))}\pgfmathresult} }

% \hline % works before the \hourFormat

\newcommand{\rowHeight}[1]{  {\pgfmathparse{int(#1*0.4 + 0.5)}\pgfmathresult}  }

\newlength\hunits
\setlength\hunits{3.5pt}
\rule[\dimexpr9pt-#1\hunits\relax]{0pt}{#1\hunits}   & #2 & #3 & #4  }%  <-- Works but not calculating the row height.
% \def\R #1|#2|#3|#4 {\hline \hourFormat{\theMinsIntoLesson}  \addtocounter{MinsIntoLesson}{#1}   & #2 & #3 &  #4[\rowHeight{#1}em] } <-- Calculates Row height, but does not effect the heigh, param not passed to tabular.
% \def\R #1|#2|#3|#4 {\hline \hourFormat{\theMinsIntoLesson}  \addtocounter{MinsIntoLesson}{#1}   & #2 & #3 &  #4\\[\rowHeight{#1}em] }%  <--- DOESNT WORK

% Keep track of the time/minutes in the lesson.
\newcounter{MinsIntoLesson}

\newcommand{\timelineheader}{ \textbf{Time} & \textbf{\mbox{Content}} & \textbf{Learning Activities} & \textbf{Resources} \\  \hline}
\newcommand{\timelinecolors}{ } % \rowcolors{2}{white}{cyan!25} }

%%%% Begining of the lesson

\newenvironment{nulesson}[4]{       % #1 is the lesson title
\newpage
\setcounter{MinsIntoLesson}{-60}

\subsubsection{{Lesson \theLessonNumber} #1, #3} % \begin{flushright}#3\end{flushright}

At the end of this lesson students should be able to ... }{\newpage} % End of newenvironment

% ---------------------------- Start of Document -----------------------------
\begin{document}

\begin{landscape}
\renewcommand{\arraystretch}{0.5}
\begin{nulesson}{Unit overview and Review of Statistics}{Ch 4. Sec 4.}{SM1,SM2}{Unit overview and Review of Statistics}

% Lesson Time line planning
\begin{table}[h]
\timelinecolors
\begin{tabulary}{\linewidth}{c | L | L | L}
\R 5  | \mbox{Introduction} | Students enter class, roll call and lesson goal displayed on projector  | Roll  \\
\R 5  | Ted Talk | The teacher presents a short  Ted talk by Arthur Benjamin  |  www.ted.com \\
\R 20 | Unit Overview  |Teacher led discussion reviewing the unit material | Overhead projector \\
\R 25  | Review of statistical Measures | Formative assessment to assess the students abilities | Formative Assessment  \\
\R 5  | Lesson Close | Lesson review and students tidy desks and leave class  |  \\
\end{tabulary}
\end{table}
\end{nulesson}

\end{landscape}

\end{document}


Note that if a multiline cell like "Learning Activities" is too long, it could (and does) overwhelm the vertical height set by the rule. I show this below by making the rule 1pt in width:

• Thakns very much for that answer Steven, I have been struggleing with this problem all day, and my solution is very messy. I was also using rule once I figures out exactly what a rule was. I think it is probably fine or even better to have an overrun. Aug 29 '14 at 10:35
• @MichaelTMckeon Glad to help. Welcome to the site! Aug 29 '14 at 10:36