1

I am creating one command to define a functional requirement and many non functional requeriment in a table. I wrote the following code:

  \newcounter{Number}
  \newcommand{\Item}{\stepcounter{Number}\theNumber}
  \newcounter{NumberReqF}
  \newcommand{\ReqF}{F\stepcounter{NumberReqF}\theNumberReqF ~- }
  \newcounter{NumberReqNF}[NumberReqF]
  \newcommand{\ReqNF}{NF \stepcounter{NumberReqNF}\theNumberReqF .\theNumberReqNF ~- }

  \usepackage{tabularx,calc}
  \newcolumntype{Y}[1]{>{\setlength\hsize{#1\hsize}%
                   \raggedright\arraybackslash}X}
  \newcolumntype{F}{|p{\columnwidth-2\tabcolsep-2\arrayrulewidth}|}
  \setlength\extrarowheight{2pt}

  \newcommand{\TabelaRequisito}[8]{
\setcounter{NumberReqNF}{0}
\begin{table}[h]
    \noindent\begin{tabularx}{\columnwidth}{|Y{0.5}|Y{0.25}|Y{0.25}|c|c|}
        \hline
        \multicolumn{3}{|l|}{\ReqF #1} & \multicolumn{2}{l|}{Hidden (#2)}\tabularnewline
        \hline
        \multicolumn{5}{F}{#3}\tabularnewline
        \hline
        \multicolumn{5}{|c|}{Non-Functional Requirements}\tabularnewline
        \hline
        Name & Restriction & Category & Desirable & Permanent\tabularnewline
        \hline
        \ReqNF #4 & #5 & #6 & (#7) & (#8)\tabularnewline
        \hline
        \ReqNF New Non-Functional Requirement Name &  &  &  &\tabularnewline
        \hline
        % more and more requirements here...
    \end{tabularx}
\end{table}
  }

So I would reuse this table format all the time with the command

 \TabelaRequisito{Functional Requirement Name}{X}{
        Functional Requirement description
        }{Name}{}{Security}{X}

enter image description here

But I am limited to add just one non-functional requirement, I would like to know a solution that I could add as many as non-functional requirement I want. One, two, three, four,...

1
  • Could you add an example of how you want to use this for several "non-functional requirements". Commented Mar 28, 2012 at 20:15

2 Answers 2

2

You can enumerate non-functional requirements like this (full MWE repeated):

\documentclass{article}

\newcounter{Number}
\newcommand{\Item}{\stepcounter{Number}\theNumber}
\newcounter{NumberReqF}
\newcommand{\ReqF}{F\stepcounter{NumberReqF}\theNumberReqF ~- }
\newcounter{NumberReqNF}[NumberReqF]
\newcommand{\ReqNF}{NF \stepcounter{NumberReqNF}\theNumberReqF .\theNumberReqNF ~- }

\usepackage{tabularx,calc}
\newcolumntype{Y}[1]{>{\setlength\hsize{#1\hsize}%
    \raggedright\arraybackslash}X}
\newcolumntype{F}{|p{\columnwidth-2\tabcolsep-2\arrayrulewidth}|}
\setlength\extrarowheight{2pt}

\newcommand\NFReq[5]{%
  \ReqNF #1 & #2 & #3 & (#4) & (#5)\tabularnewline
  \hline
}

\newcommand{\TabelaRequisito}[4]{
  \setcounter{NumberReqNF}{0}
  \begin{table}[h]
    \noindent\begin{tabularx}{\columnwidth}{|Y{0.5}|Y{0.25}|Y{0.25}|c|c|}
      \hline
      \multicolumn{3}{|l|}{\ReqF #1} & \multicolumn{2}{l|}{Hidden (#2)}\tabularnewline
      \hline
      \multicolumn{5}{F}{#3}\tabularnewline
      \hline
      \multicolumn{5}{|c|}{Non-Functional Requirements}\tabularnewline
      \hline
      Name & Restriction & Category & Desirable & Permanent\tabularnewline
      \hline
      #4%
      \ReqNF New Non-Functional Requirement Name &  &  &  &\tabularnewline
      \hline
      % more and more requirements here...
    \end{tabularx}
  \end{table}
}

\begin{document}
\TabelaRequisito{Functional Requirement Name}{X}
{Functional Requirement description}
{%
  \NFReq{Name}{}{Security}{X}{}%
  \NFReq{foo}{}{bar}{X}{}%
}
2

It is possible, but it is best not to do it. LaTeX never uses different numbers of {} groups for varying arguments, it either uses , separated lists or extra commands. Here I would use extra commands:

 \TabelaRequisito{Functional Requirement Name}{X}{
        Functional Requirement description
        }{
   \nunfuncreq{Name}{}{Security}{X}
   \nunfuncreq{zzz}{}{kjahxaxa}{Y}
   \nunfuncreq{jjj}{}{llll}{Y}
   }

so the last argument of your command takes any number of \nunfuncreq commands, and that can then have a simple definition as a four-argument command making a row of the table.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .