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.

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}
share|improve this question
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? –  Jubobs Aug 6 at 23:20
    
Good point. Your suggestion is better. For this table, I do not want a caption. –  Martin Clouthier Aug 6 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. –  Jubobs Aug 6 at 23:32

1 Answer 1

up vote 4 down vote accepted

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}
share|improve this answer

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.