1

I cannot find a good title to express my question. Therefore, please parse the following code first.

Minimal Code

\documentclass[dvips,dvipsnames,cmyk,table]{book}
\usepackage[a5paper,margin=20mm]{geometry}
\usepackage{longtable,array,calc}

\usepackage{listings}
\lstset{basicstyle=\scriptsize,tabsize=3}

\usepackage{fancyvrb}
\fvset{tabsize=3}
\newcommand\gtemp[1]{&&#1\tabularnewline\hline}
\newcommand{\args}{}
\newenvironment{Row}[1]
    {\renewcommand{\args}{#1}\VerbatimEnvironment\begin{VerbatimOut}{\jobname.tmp}}
    {\end{VerbatimOut}\aftergroup\gtemp{\args}}

\newcolumntype{A}
{
  >{\begin{minipage}{0.3333\linewidth-2\tabcolsep-2\arrayrulewidth}\vspace{\tabcolsep}}%
  c%
  <{\vspace{\tabcolsep}\end{minipage}}%   
}

\newenvironment{ComparisonTable}%
{% 
    \begin{longtable}%
    {%
     |A<{\lstinputlisting{\jobname.tmp}}%
     |A<{\input{\jobname.tmp}}%
     |A%
     |%
    }%
    \hline\ignorespaces%
}%
{\end{longtable}}

\begin{document}
\begin{ComparisonTable}
%
% Row 1
\begin{Row}%
{
 This is a quadratic function.
}
\begin{equation}
 y=ax^2+bx+c
\end{equation}
\end{Row}
%
% Row 2
\begin{Row}{LaTeX in action}
\Huge\LaTeXe
\end{Row}
\end{ComparisonTable}
\end{document}

Objective

I want \Row to accept an argument such that I can change

\begin{Row}
\begin{equation}
 y=ax^2+bx+c
\end{equation}
\end{Row}

to

\begin{Row}{Some description...}
\begin{equation}
 y=ax^2+bx+c
\end{equation}
\end{Row}

How to do this?

1

OK, there are two problems with the code you posted: 1. \aftergroup can only put one token (here \gtemp) after the group, and your \renewcommand doesn't give a global redefinition, so it won't be in effect after the group. This works:

\documentclass[dvips,dvipsnames,cmyk,table]{book}
\usepackage[a5paper,margin=20mm]{geometry}
\usepackage{longtable,array,calc}

\usepackage{listings}
\lstset{basicstyle=\scriptsize,tabsize=3}

\usepackage{fancyvrb}
\fvset{tabsize=3}
\newenvironment{Row}[1]
    {\gdef\gtemp{&&#1\tabularnewline\hline}\VerbatimEnvironment\begin{VerbatimOut}{\jobname.tmp}}
    {\end{VerbatimOut}\aftergroup\gtemp}

\newcolumntype{A}
{
  >{\begin{minipage}{0.3333\linewidth-2\tabcolsep-2\arrayrulewidth}\vspace{\tabcolsep}}%
  c%
  <{\vspace{\tabcolsep}\end{minipage}}%   
}

\newenvironment{ComparisonTable}%
{% 
    \begin{longtable}%
    {%
     |A<{\lstinputlisting{\jobname.tmp}}%
     |A<{\input{\jobname.tmp}}%
     |A%
     |%
    }%
    \hline\ignorespaces%
}%
{\end{longtable}}

\begin{document}
\begin{ComparisonTable}
%
% Row 1
\begin{Row}%
{
 This is a quadratic function.
}
\begin{equation}
 y=ax^2+bx+c
\end{equation}
\end{Row}
%
% Row 2
\begin{Row}{LaTeX in action}
\Huge\LaTeXe
\end{Row}
\end{ComparisonTable}
\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.