2

What is the best way to create an environment that takes a number of arguments, like this:

\finding{%
Text argument #1,
Text argument #2,
Text argument #3,
Text argument #4}

and produces something like this:

\documentclass[11pt,letterpaper]{article}

\begin{document}
\begin{table}
\begin{tabular}{|l|l|} 
\multicolumn{1}{l}{\textbf{Finding \foo}} \\
\hline
\textbf{Synopsis:}  & \textbf{Text argument \#1} \\
\hline
Recommendation:     & Text argument \#2 \\
\hline
Comments:           & Text argument \#3 \\
\hline
Risk value          & Text argument \#4 \\
\hline
\end{tabular}
\end{table}
\end{document}

Where \foo is a custom stepcounter defined by

\newcounter{bar}
\newcommand{\foo}{%
    \stepcounter{bar}%
    \thebar}
3
  • 1
    Are you sure you want that syntax for \finding? What if a "text argument" contains a comma? \finding{Text argument #1}{Text argument #2}{Text argument #3}{Text argument #4} would be easier to set up and less ambiguous. And how would you specify a caption?
    – jub0bs
    Aug 6, 2014 at 23:20
  • Good point. Your suggestion is better. For this table, I do not want a caption. Aug 6, 2014 at 23:25
  • 2
    Please make your code compilable (if possible), or at least complete it with \documentclass{...}, the required \usepackage's, \begin{document}, and \end{document}. That may seem tedious to you, but think of the extra work it represents for TeX.SX users willing to give you a hand. Help them help you: remove that one hurdle between you and a solution to your problem.
    – jub0bs
    Aug 6, 2014 at 23:32

1 Answer 1

4

Specifying the four arguments as a comma-separated list is probably not a good idea: what if an argument contains a comma? Using the regular TeX syntax for passing arguments is preferable.

Note that \tn is defined nowhere in your code snippet; I substituted \\ for every occurence of it.

enter image description here

\documentclass[12pt]{article}

\newcommand\finding[4]{%
    \begin{table}
    \begin{tabular}{|l|l|} 
    \multicolumn{1}{l}{\textbf{Finding AUTOMATIC\_COUNTER}} \\
    \hline
    \textbf{Synopsis:}  & \textbf{#1} \\
    \hline
    Recommendation:     & #2 \\
    \hline
    Comments:           & #3 \\
    \hline
    Risk value          & #4 \\
    \hline
    \end{tabular}
    \end{table}
}

\begin{document}
\finding
  {one}
  {two}
  {three}
  {four}
\end{document}
0

You must log in to answer this question.

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