\newenvironment 行为与 \begin{landscape}

\newenvironment 行为与 \begin{landscape}

我想使用横向模式,其中有一个表格。但是当我嵌入环境的开始和结束时,\newenvironment{lessonPlanner}会出现错误,但是如果我移动到环境的外部,就不会出现错误。\begin{landscape}\end{landscape}\begin{landscape}

具体来说

Runaway argument?
!File ended whlie scanning use of \TX@get@body,

我以前遇到过这种情况,不得不使用表格命令形式,但我不知道这是否适合景观,我想更好地理解这个问题

任何帮助都将不胜感激,谢谢。

迈克尔

-----------------------示例 lesson.tex 文件。---------------------------------

\documentclass{article}

\usepackage{pdflscape}
\usepackage{lessonPlanner}

\begin{document}

\begin{unitPlan}{Principles of nutrition}

% \begin{landscape}
\begin{lesson}{Hunger and Satiety}{14:00}{70}

  \activity{Introduction}{3}{Electronic White Board}{
     Welcome to the class and overview of nutrition with lead in to hunger and Satiety
   }

  \activity{Ghrelin}{10}{Electronic White Board}{
   Discuss  the role of Ghrelin on  the neurochemistry of the brain, and how ghrelin instigates sleep
  }

  \activity{Student quiz}{5}{Electronic voting system}{
    Students are quized on their understanding of Grhelin and its effects on the brain
  }

  \activity{Lesson Close}{3}{}{
    Review briefly the lesson topics and close the lesson
   }

\end{lesson}
% \end{landscape}

% \begin{lesson}{The Macro nutrients}{10:20}{70}
% \end{lesson}

% \begin{lesson}{Vitamins and Minerals}{11:30}{70}
% \end{lesson}

\end{unitPlan}

\end{document}

--------- lessonPlanner.sty 文件 -------

\NeedsTeXFormat{LaTeX2e}[1994/06/01]
\ProvidesPackage{lessonPlanner}


% \usepackage{pgf}
% \usepackage{paralist}

% \usepackage[export]{adjustbox}

\RequirePackage{pgf}
\RequirePackage{paralist}
\RequirePackage[export]{adjustbox}
\RequirePackage{tabularx}
\RequirePackage{tabulary}
\RequirePackage{pdflscape}

\newcounter{MinsIntoLesson}

\newenvironment{unitPlan}[1]
      {Start Unit: \textbf{#1} \vspace{2em} } % begin unitPlan
      {}  % end unitPlan

% Start Lesson Title: \textbf{#1} Time Alocation: \textbf{#2} Resources: \textbf{#3}

\newenvironment{lesson}[3]{
%          \begin{landscape} % <- Doesnt work, get error \TX@get@body.
%          \begin{tabulary}{\linewidth}{c | L | L | L }
              \tabularx{\linewidth}{ c |  c  | X |  c }
                  Time & \mbox{Activity} & Description &  Resources   \\
           \hline
      } % \begin{lesson} 
  { 
\endtabularx 
% \endtabulary
% \end{landscape} % <- Doesnt work 
}  % \end{lesson}

% 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}
}

\newlength\hunits
\setlength\hunits{3.5pt}

\newcommand{\activity}[4] { %
  \hline \hourFormat{\theMinsIntoLesson}  \addtocounter{MinsIntoLesson}{#2}  
  \rule[\dimexpr9pt-#2\hunits\relax]{0pt}{#2\hunits} &  #1  &  #4  &  #3  \\ \hline % \begin{activity}
}

\newenvironment{activ}[4]{ 
  #1  &  #2  &  #3  &  #4  % \begin{activity}
}{}

\def\hi{Hello, this is my own package}

\let\myDate\date

\newcommand\GoodBye[1][\bfseries]{#1Good Bye}

\endinput

%%
%% End of file `mypackage.sty'.

\newenvironment{lesson}[1]{}The first parameter is  The second parameter is {}

答案1

错误是因为tabularx环境会提前扫描以拾取要排版的内容,并且需要\endtabularx直接查看才能实现此目的。在您的代码中,它隐藏在\end{lesson}命令中。

解决此问题的一个好方法是使用environ包及其\NewEnviron命令。这将设置一个新环境,但在一个代码块中完成,并\BODY使用 used 插入环境的内容。对于您的情况,您可以按如下方式使用它:

\RequirePackage{environ}

\NewEnviron{lesson}[3]{
  \begin{landscape}
    \begin{tabularx}{\linewidth}{ c |  c  | X |  c }
      Time & \mbox{Activity} & Description &  Resources \\
      \hline
      \BODY
    \end{tabularx} 
  \end{landscape}
}  % end lesson

请注意,这与所附代码文档中的正常用法如何匹配,特别是现在您可以使用\begin{tabularx}...\end{tabularx}它来代替\tabularx...\endtabularx

示例输出

以下是完整代码。顺便说一句,我一直写成lessonPlannernot lessonPlaner

主文件:

\documentclass{article}

\usepackage{pdflscape}
\usepackage{lessonPlanner}

\begin{document}

\begin{unitPlan}{Principles of nutrition}

\begin{lesson}{Hunger and Satiety}{14:00}{70}

  \activity{Introduction}{3}{Electronic White Board}{
     Welcome to the class and overview of nutrition with lead in to hunger and Satiety
   }

  \activity{Ghrelin}{10}{Electronic White Board}{
   Discuss  the role of Ghrelin on  the neurochemistry of the brain, and how ghrelin instigates sleep
  }

  \activity{Student quiz}{5}{Electronic voting system}{
    Students are quized on their understanding of Grhelin and its effects on the brain
  }

  \activity{Lesson Close}{3}{}{
    Review briefly the lesson topics and close the lesson
   }

\end{lesson}

\end{unitPlan}

\end{document}

lessonPlanner.sty

\NeedsTeXFormat{LaTeX2e}[1994/06/01]
\ProvidesPackage{lessonPlanner}

\RequirePackage{pgf}
\RequirePackage{paralist}
\RequirePackage[export]{adjustbox}
\RequirePackage{tabularx}
\RequirePackage{tabulary}
\RequirePackage{pdflscape}
\RequirePackage{environ}

\newcounter{MinsIntoLesson}

\newenvironment{unitPlan}[1]
      {Start Unit: \textbf{#1} \vspace{2em} } % begin unitPlan
      {}  % end unitPlan

% Start Lesson Title: \textbf{#1} Time Alocation: \textbf{#2} Resources: \textbf{#3}
\NewEnviron{lesson}[3]{
  \begin{landscape}
    \begin{tabularx}{\linewidth}{ c |  c  | X |  c }
      Time & \mbox{Activity} & Description &  Resources \\
      \hline
      \BODY
    \end{tabularx} 
  \end{landscape}
}  % end lesson

% 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}
}

\newlength\hunits
\setlength\hunits{3.5pt}

\newcommand{\activity}[4] { %
  \hline \hourFormat{\theMinsIntoLesson}  \addtocounter{MinsIntoLesson}{#2}  
  \rule[\dimexpr9pt-#2\hunits\relax]{0pt}{#2\hunits} &  #1  &  #4  &  #3  \\ \hline % \begin{activity}
}

\newenvironment{activ}[4]{ 
  #1  &  #2  &  #3  &  #4  % \begin{activity}
}{}

\def\hi{Hello, this is my own package}

\let\myDate\date

\newcommand\GoodBye[1][\bfseries]{#1Good Bye}

\endinput

%%
%% End of file `lessonPlanner.sty'.

相关内容