Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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?

share|improve this question
    
I think there is a strong hint in this answer: tex.stackexchange.com/questions/7769/… –  Harald Hanche-Olsen Jan 15 '11 at 12:16
    
@Harald: The business with the & is already solved by the \aftergroup; see the previous question of xport. –  Hendrik Vogt Jan 15 '11 at 12:23
    
@Hendrik: Um, okay, then. I admit I didn't read the code that carefully. –  Harald Hanche-Olsen Jan 15 '11 at 13:01
add comment

1 Answer

up vote 1 down vote accepted

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}
share|improve this answer
    
thanks again. Excellent. –  xport Jan 15 '11 at 12:24
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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