表格中动态计算的行高

表格中动态计算的行高

我正在尝试根据数字动态分配表格中的行高,具体来说是课堂课程中用于特定活动的分钟数。表格表示课程计划被分成几个部分,大行表示较长的活动,短行表示较短的活动等。我知道如何通过在行尾使用 \[2em] 来调整行高,但我宁愿从第 1 项计算此值,因为行高应与活动中的分钟数成比例,我还计算了累计总数,以便教师可以轻松了解课程每个部分的开始时间、开始时间,这样就很好了。在此处输入图片描述

请参阅 \R 的定义,我为此奋斗了几天却没有任何进展,如能得到任何帮助我将不胜感激。

\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 
\newcommand{\newlesson}[1]{ \addtocounter{LessonNumber}{1}\subsubsection{{Lesson \theLessonNumber} #1} }

\newenvironment{nulesson}[4]{       % #1 is the lesson title
      \newpage
      \addtocounter{LessonNumber}{1}
      \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}
            \timelineheader
            \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}

答案1

\rule[\dimexpr9pt-#1\hunits\relax]{0pt}{#1\hunits}我所做的就是在 的第一列定义中添加\R,其中\hunits选择 以满足总体高度(时间)约束。在本例中,\hunits设置为 3.5 pt,这意味着课程的每一分钟都会获得 3.5pt 的垂直空间。

\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}
\def\R #1|#2|#3|#4 {\hline \hourFormat{\theMinsIntoLesson}  \addtocounter{MinsIntoLesson}{#1}%
\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 
\newcommand{\newlesson}[1]{ \addtocounter{LessonNumber}{1}\subsubsection{{Lesson \theLessonNumber} #1} }

\newenvironment{nulesson}[4]{       % #1 is the lesson title
      \newpage
      \addtocounter{LessonNumber}{1}
      \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}
            \timelineheader
            \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}

在此处输入图片描述

请注意,如果多行单元格(如“学习活动”)太长,它可能会(并且确实会)超出规则设置的垂直高度。我通过将规则宽度设为 1pt 来在下面展示此情况:

在此处输入图片描述

相关内容