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.

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
share|improve this question
4  
You can use, for example, \begin{tabular}{*{5}{c}} to indicate five columns of c type. –  Gonzalo Medina 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
add comment

1 Answer

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

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.