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.

5
  • Would there be a problem with simply specifying e.g. 50 columns and then not using all of them?
    – Gaussler
    Commented Jul 8, 2014 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. Commented Jul 8, 2014 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
    Commented Jul 8, 2014 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
    Commented Jul 8, 2014 at 16:45
  • 1
    Probably use stackengine...
    – Werner
    Commented Jul 8, 2014 at 16:48

2 Answers 2

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

4
  • Thank you for your answer, but I want it to work for an arbitrary number of columns.
    – Gaussler
    Commented Jul 8, 2014 at 16:37
  • 1
    @Gaussler Corrected according to your specification. Commented Jul 8, 2014 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
    Commented Jul 8, 2014 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. Commented Jul 8, 2014 at 18:18
0

It’s easy peasy with tblr environment of the new LaTeX3 package tabularray: you can create a table without specifying in advance the number of columns, or only specifying the second column.

\documentclass{article}
\usepackage{tabularray}
\begin{document}

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

\bigskip

\begin{tblr}{column{2}={c}}
this  & is      & a \\
table & without & column specification
\end{tblr}

\end{document}

enter image description here

You must log in to answer this question.

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