如果我“硬连线”环境的行,longtable
它几乎可以按我想要的方式工作。但是,如果我尝试使用命令,LaTeX 会提示缺失}
并挂起。
我想在命令的参数中使用命令来\TestProcedure
最大限度地减少作者的工作并最大限度地提高文档自动化。
\documentclass{article}
\usepackage{trace}
\usepackage{longtable}
\setcounter{LTchunksize}{1000}
\usepackage{subfig}
\usepackage[titles,subfigure]{tocloft}% to define requirements list for TOC,F,T
%local variables for the \TestProc macro command
\newcounter{TestProcItemCounter}
\newcounter{NTPRC}
%new list for test procedures
\newlistof[NTPRC]{testprocedure}{tpr}{\listtestproceduresname}
\newcommand{\numberedtestprocedure}[2]{%
\refstepcounter{testprocedure}%
\addcontentsline{tpr}{testprocedure}{\protect\numberline{#1}#2}\par}
% declaration of a command, with junk so I can see if it didn;t get set
\newcommand{\ThisTestProcNum}{?!?num} %this gets set and reset in \TestProc[6]
\newcommand{\ThisTestProcName}{?!?name} %this gets set and reset in \TestProc[6]
\newcommand{\ThisTestProcLabel}{?!?label} %this gets set and reset in \TestProc[6]
%
\setlength{\textwidth}{6.5in}%
\setlength{\hoffset}{0in}%
\setlength{\oddsidemargin}{0in}%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% beginning of Test Procedure Macro
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% the macros used within the \TestProcedure[6] macro to make things easier for test writers
% from below to compare \stepcounter{TestProcItemCounter}~R-\ThisTestProcNum-\theTestProcItemCounter & \parbox[top][12pt][c]{5.0in}{Hardcoded Requirement 1} \\ \hline%
\newcommand{\tpRqmt}[1]{\stepcounter{TestProcItemCounter}~R-\ThisTestProcNum-\theTestProcItemCounter & \parbox[top][12pt][c]{5.0in}{#1} \\ \hline}
%
% from below to compare \stepcounter{TestProcItemCounter}~S-\ThisTestProcNum-\theTestProcItemCounter & \parbox[top][42pt][t]{5in}{\vspace{2pt}Hardcoded Step 1} \\ \hline%
\newcommand{\tpStep}[2]{\stepcounter{TestProcItemCounter}~S-\ThisTestProcNum-\theTestProcItemCounter & \parbox[top][ #2][t]{5.0in}{\vspace{2pt}{#1}} \\ \hline}
%
% from below to compare \stepcounter{TestProcItemCounter}~N-\ThisTestProcNum-\theTestProcItemCounter & \parbox[top][12pt][c]{5in}{Hardcoded Note 1} \\ \hline%
\newcommand{\tpNote}[1]{\stepcounter{TestProcItemCounter}~N-\ThisTestProcNum-\theTestProcItemCounter & \parbox[top][12pt][c]{5.0in}{#1} \\ \hline}
%
\newcommand{\TestProcedure}[6]{%
% variables to avoid confusion between the #1, #2, and #3 args to \TestProcedure[6], which is also needed in \tpRqmt[1], \tpStep[2], and \tpNote[1]
\renewcommand{\ThisTestProcNum}{#1}% store away the test description number for use in the macro
\renewcommand{\ThisTestProcName}{#2}% store away the test description name for use in the macros
\renewcommand{\ThisTestProcLabel}{#3}% store away the test description label for use in the macros
%
% may need to run LaTeX three (3) times to get column widths correct, per LongTable documentation !
%
\begin{longtable}[l]{|r|l|}% base table has two columns <item number & item text>
%
\hline \hline%
\multicolumn{2}{|c|}{\parbox[top][12pt][c]{\textwidth}{{\centering \bf Test Procedure \ThisTestProcNum \numberedtestprocedure{\ThisTestProcNum}{\ThisTestProcName}}}}\\%
\multicolumn{2}{|c|}{\parbox[top][12pt][c]{\textwidth}{\centering \bf \ThisTestProcName}\label{\ThisTestProcLabel}}\\%
\hline \hline%
\endfirsthead%
\hline \hline%
\multicolumn{2}{|c|}{\parbox[top][12pt][c]{\textwidth}{\centering \bf Test Procedure \ThisTestProcNum~-- continued from previous page}} \\%
\hline \hline%
\endhead%
\hline \hline%
\multicolumn{2}{|r|}{\parbox[top][12pt][c]{\textwidth}{\centering \bf Test Procedure \ThisTestProcNum~-- continues on the next page}} \\%
\hline \hline%
\endfoot%
\hline%
\multicolumn{2}{|c|}{\parbox[top][12pt][c]{\textwidth}{\centering \bf End of Test Procedure \ThisTestProcNum}} \\%
\hline%
\endlastfoot%
%
% Requirements Validated in this Procedure
%
\hline \hline%
\multicolumn{2}{|c|}{\parbox[top][12pt][c]{\textwidth}{\centering \bf Requirements Covered by Test Procedure \ThisTestProcNum\setcounter{TestProcItemCounter}{0}}} \\%
\hline \hline%
%{#4}%when this line is uncommented, and two ``\stepcounter...'' lines below are commented out, LaTeX has 10 errors, or it hangs
% the \TestProcedure<> command with hardcoded 2nd column entries, this works just fine when these two lines below are uncommented and ``{#4}'' above is commented
\stepcounter{TestProcItemCounter}~R-\ThisTestProcNum-\theTestProcItemCounter & \parbox[top][12pt][c]{5.0in}{Hardcoded Requirement 1} \\ \hline%
\stepcounter{TestProcItemCounter}~R-\ThisTestProcNum-\theTestProcItemCounter & \parbox[top][12pt][c]{5.0in}{Hardcoded Requirement 2} \\ \hline%
%
% Steps Performed in this Procedure
%
\hline \hline%
\multicolumn{2}{|c|}{\parbox[top][12pt][c]{\textwidth}{\centering \bf Steps to be Performed for Test Procedure \ThisTestProcNum\setcounter{TestProcItemCounter}{0}}} \\%
\hline \hline%
%{#5}%when this line is uncommented, and two ``\stepcounter...'' lines below are commented out, LaTeX has 10 errors, or it hangs
% the \TestProcedure<> command with hardcoded 2nd column entries, this works just fine when these two lines below are uncommented and ``{#5}'' above is commented
\stepcounter{TestProcItemCounter}~S-\ThisTestProcNum-\theTestProcItemCounter & \parbox[top][42pt][t]{5in}{\vspace{2pt}Hardcoded Step 1} \\ \hline%
\stepcounter{TestProcItemCounter}~S-\ThisTestProcNum-\theTestProcItemCounter & \parbox[top][69pt][t]{5in}{\vspace{2pt}Hardcoded Step 2} \\ \hline%
%
% Noes About This Procedure
%
\hline \hline%
\multicolumn{2}{|c|}{\parbox[top][12pt][c]{\textwidth}{\centering \bf Notes About Test Procedure \ThisTestProcNum\setcounter{TestProcItemCounter}{0}}} \\%
\hline \hline%
%{#6}%when this line is uncommented, and two ``\stepcounter...'' lines below are commented out, LaTeX has 10 errors, or it hangs
% the \TestProcedure<> command with hardcoded 2nd column entries, this works just fine when these two lines below are uncommented and ``{#6}'' above is commented
\stepcounter{TestProcItemCounter}~N-\ThisTestProcNum-\theTestProcItemCounter & \parbox[top][12pt][c]{5in}{Hardcoded Note 1} \\ \hline%
\stepcounter{TestProcItemCounter}~N-\ThisTestProcNum-\theTestProcItemCounter & \parbox[top][12pt][c]{5in}{Hardcoded Note 2} \\ \hline%
%
\end{longtable}%
}%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% end of Test Procedure Macro
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
\begin{document}
\TestProcedure%[6] Test Procedure Container
% #1 is the test description number, usually built from section number + description within the section
{1.2.3.4.5.6}%#1
% #2 is the test description name
{Test Participant Information}%#2
% #3 is the test description LaTeX label
{lab:testproc_ParticipantInformation}%#3
%
% #4 is the list of requirements covered by this test
%
{%
\tpRqmt{Requirement 1 for realsies}%
\tpRqmt{Requirement 2 for realsies}%
}%#4
% #5 is the list of steps to be performed by this test
{%
\tpStep{Test Step 1 for realsies realsies and dndhshf hfdhc hdhcd hcdh chd chduic chuihecu hcueh chui hfuie chduich uhcuihc eh cheui hcuih chieu chdwui cwdu uivhdwui cuiwdhcuidwh cuihdui chduih ciuhdui chudiwh cuihd chiud hciudah iuch chdaui cidahcui chadui}{42pt}%
\tpStep{Test Step 2 for realsies realsies and dndhshf hfdhc hdhcd hcdh chd chduic chuihecu hcueh chui hfuie chduich uhcuihc eh cheui hcuih chieu chdwui cwdu uivhdwui cuiwdhcuidwh cuihdui chduih ciuhdui chudiwh cuihd chiud hciudah iuch chdaui cidahcui chadui}{69pt}%
}%#5
% #6 is the list of notes for this test
{%
\tpNote{Note 1 for realsies}%
\tpNote{Note 2 for realsies}%
}%#6
%%% end TestProcedure[6] test description container
%
\end{document}
答案1
这是最小化示例的更正版本。您不希望在表示参数的变量周围使用花括号,例如#2
not {#2}
。您需要这些将在这里扩展!
\documentclass{article}
\usepackage{longtable}
\setcounter{LTchunksize}{1000}
%local variables for the \TestProc macro command
\newcounter{TestProcItemCounter}
\newcounter{testprocedure}
\newcommand{\numberedtestprocedure}[2]{%
\refstepcounter{testprocedure}}
\newcommand{\ThisTestProcNum}{?!?num} %this gets set and reset in \TestProc[6]
\newcommand{\tpRqmt}[1]{%
\stepcounter{TestProcItemCounter}~R-\ThisTestProcNum-\theTestProcItemCounter
&
\parbox[top][12pt][c]{5.0in}{#1} \\ \hline
}
\newcommand{\TestProcedure}[2]{%
\renewcommand{\ThisTestProcNum}{#1}% store away the test description number for use in the macro
\begin{longtable}[l]{|r|l|}% base table has two columns <item number & item text>
\hline
\multicolumn{2}{|c|}{\parbox[top][12pt][c]{\textwidth}{\centering \bfseries Requirements Covered by Test Procedure \ThisTestProcNum\setcounter{TestProcItemCounter}{0}}} \\
\hline
#2
\end{longtable}%
}
\begin{document}
\TestProcedure
{1.2.3.4.5.6}
{%
\tpRqmt{Requirement 1 for realsies}%
\tpRqmt{Requirement 2 for realsies}%
}
\end{document}