我找不到一个好的标题来表达我的问题。因此,请先解析以下代码。
最少代码
\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]{&\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}
客观的
我想\Row
接受一个论点,以便我可以改变
\begin{Row}
\begin{equation}
y=ax^2+bx+c
\end{equation}
\end{Row}
到
\begin{Row}{Some description...}
\begin{equation}
y=ax^2+bx+c
\end{equation}
\end{Row}
这个怎么做?
答案1
好的,你发布的代码有两个问题:1.\aftergroup
只能放一标记(此处\gtemp
)位于组之后,并且您\renewcommand
没有给出全局重新定义,因此它在组之后不会生效。这有效:
\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{&\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}