1

Is there any standard way of defining a class so that

\startTable
\newTableEntry{x}{12.1}
\newTableEntry{y}{11.1}
\endTable

can be done?

The result should be

x    12.1
y    11.1

Thanks!

  • 1
    your question is very unclear, you don't say what you want to happen. \def\startTable{\begin{tabular}{cc}}, \def\endTable{\end{tabular}}, \def\newTableEntry#1#2{#1&#2\\} might work, although it would be better to use standard \begin .. \end environment syntax. – David Carlisle Jul 18 '16 at 14:55
  • I corrected the question. Hope I am not vague now :) – Karthik Nishanth Jul 18 '16 at 15:12
  • @DavidCarlisle Can you kindly post the comment as an answer? I will mark it as an answer. – Karthik Nishanth Jul 18 '16 at 15:28
1

You could do

 \def\startTable{\begin{tabular}{cc}}
 \def\endTable{\end{tabular}}
 \def\newTableEntry#1#2{#1&#2\\} 

although it would be much better better to use standard \begin .. \end environment syntax and so not use the first two lines, you could still use

\begin{tabular}{cc}
\newTableEntry{x}{12.1}
\newTableEntry{y}{11.1}
\end{tabular}

note that especially \endTable as a command name is completely against lateX syntax rules, and could not be defined with \newcommand, but even if you changed that to be (say) \stopTable as corresponding to \startTable hiding the environment syntax just makes it harder for editors to offer context sensitive help and syntax colouring.

| improve this answer | |
  • Is there a way to do the same for tabularx based table? – Karthik Nishanth Jul 20 '16 at 20:19
  • @KarthikNishanth ?? just replace tabular by tabularx{some width} in the above, what did you try? – David Carlisle Jul 20 '16 at 20:34
  • I tried, but get the error similar to tex.stackexchange.com/questions/287529/… I apologise, I am really a noob at this. – Karthik Nishanth Jul 21 '16 at 15:15
  • 1
    @KarthikNishanth oh sorry yes of course use \tabularx{\textwidth}{XXX} and \end{tabularx} not \begin{tabularx} in the first form, but really why do it at all, isn't it simpler to just use tabularx directly in the document, as in the second example above? – David Carlisle Jul 21 '16 at 15:20
3

For such simple things, plain tex can be nice too

\settabs \+x\qquad&RESULT\qquad\cr
\+ x&12.1\cr
\+ y&12.2\cr
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.