texblog

Repeat column type in LaTeX tabular

I am sure you know the situation where you have several columns in a tabular which all are of the same type:

\begin{tabular}{|r|c|c|c|c|c|}

Now this can be simplified as follows using the *(star) symbol:

\begin{tabular}{|r*{5}{|c}|}

The advantages are obvious, the table can be easily extended, you don’t have to count the numerous c’s, l’s or r’s and it saves you time.

It also works if you define a custom column type (array package):

\usepackage{array}
\newcolumntype{V}{>{\bf\centering\arraybackslash} m{.2\linewidth} }
...
\begin{tabular}{*{3}{V}}

\documentclass{article}
\usepackage{array}
\newcolumntype{V}{>{\bf\centering\arraybackslash} m{.2\linewidth} }
\begin{document}
\begin{table}[ht]
\caption{Repetition of custom-defined column type.}
\begin{center}
\begin{tabular}{*{3}{V}}
\hline
aaa&bbb&ccc\\
\hline
aaa&bbb&ccc\\
aaa&bbb&ccc\\
\hline
\end{tabular}
\end{center}
\end{table}
\end{document}
Exit mobile version