5

Is there a way to create a table in LaTeX without specifying in advance the number of columns? What I want is something like

\documentclass{article}
\begin{document}
\begin{amazingtabular}
this & is & a\\
table & without & column specification
\end{amazingtabular}
\end{document}

Notice that there is no argument like {cll} after the amazingtable environment. What I want is that the environment should work for an arbitrary number of columns. If possible, I would like to avoid going into math mode to use the matrix environment.

  • Would there be a problem with simply specifying e.g. 50 columns and then not using all of them? – Gaussler Jul 8 '14 at 16:37
  • 2
    It would be better, if we know your real problem. In particular a piece of information of the type: the first column is centered, the others left aligned, maximal number of them is 30 would be useful. It seems to be unbelievable, that writing down the column specification is the problem itself. – Przemysław Scherwentke Jul 8 '14 at 16:43
  • They should all be left-aligned, and I very much doubt that their number will exceed 15. The problem is that I'm converting an XML script to LaTeX, and it does not use column specifications. – Gaussler Jul 8 '14 at 16:45
  • 1
    You can certainly specify 50 or more columns and only use, say, 10. You still have to inform LaTeX about whether the columns' contents should be typeset centered, justified, flush-right, flush-left, or whatever else. If all columns should be set flush-left, just use \begin{tabular}{*{50}{l}}. – Mico Jul 8 '14 at 16:45
  • 1
    Probably use stackengine... – Werner Jul 8 '14 at 16:48
4

If only the number of columns would be below 30...

\documentclass{article}
\begin{document}

\newenvironment{amazingtabular}{\begin{tabular}{*{30}{l}}}{\end{tabular}}

\begin{amazingtabular}
this & is & a\\
table & without & column specification
\end{amazingtabular}
\end{document}

enter image description here

  • Thank you for your answer, but I want it to work for an arbitrary number of columns. – Gaussler Jul 8 '14 at 16:37
  • 1
    @Gaussler Corrected according to your specification. – Przemysław Scherwentke Jul 8 '14 at 17:06
  • 1
    @Gaussler TeX will be quite happy to specify 10000 columns, if you like to. Of course, it won't be able to typeset a table with 10000 columns, because it can't manage lines longer than about 4.5 meters. I'd say that 100 columns is a reasonable compromise. – egreg Jul 8 '14 at 17:40
  • @egreg I understand your intentions, but it seems that 10000 is too much. The compilation time was at least 100 times longer than with the value 1000. – Przemysław Scherwentke Jul 8 '14 at 18:18

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.