3

I have this code which works fine

\begin{table}[ht]
\caption{Table Data }  
\centering          
\begin{tabular}{c c c c}    % centered columns (4 columns)

Now i have the dynamic headers so i have to hard code this line every time accoring to headers

begin{tabular}{c c c c}

is there any way to apply that to all coumns instead of all like this

begin{tabular}{c} for all
2
  • 4
    You can use, for example, \begin{tabular}{*{5}{c}} to indicate five columns of c type. May 1 '13 at 1:09
  • so it means i need to know before hand how many columns should be there
    – user17
    May 1 '13 at 1:24
3

You can specify a number of columns which is more that you need -- there is no problem with extra column specification, AFAIK. Also, as per Gonzalo Medina's comment you can use the {*{15}{c}} notation to specify a maximum of 15 columns.

enter image description here

Notes:

Code:

\documentclass{article}
\usepackage{booktabs}

\begin{document}      
\begin{tabular}{c c c c c c c c c c c c c c c} \toprule
One & Two \\ \cmidrule{1-2}
 1  & 2   \\ \bottomrule
\end{tabular}
\begin{tabular}{*{15}{c}} \toprule
One & Two & Three \\ \cmidrule{1-3}
 1  & 2   & 3 \\ \bottomrule
\end{tabular}
\end{document}

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.