# Align rows elements in the tabular form

I have a problem with the the aligning of a tabular. I used the code

\begin{center}
\begin{tabular}{|m{1.5cm}|m{1.5cm}||m{1.5cm}|m{1.5cm}|}
\hline
1& 2 & 7 & 8 \\
0 & 89 & 100 & 55\\
4 & 6  & 4999& 055\\
\hline
\end{tabular}
\end{center}


and I want the elements centered. What command I should use?

• do you really want centering here? It is more normal to make numeric columns be aligned so that the digits are in vertical columns. – David Carlisle Dec 15 '15 at 17:00

## 2 Answers

There is no need for the m-type columns, since they're intended for vertical alignment of cell contents. You seem to be interested in a centred p-type column:

\documentclass{article}
\usepackage{array,booktabs}
\begin{document}
\begin{center}
\begin{tabular}{ *{4}{>{\centering\arraybackslash}p{1.5cm}} }
\toprule
1 &  2 &   7  &  8  \\
0 & 89 &  100 &  55 \\
4 &  6 & 4999 & 055 \\
\bottomrule
\end{tabular}
\end{center}
\end{document}


The above suggests a number of things:

1. Using booktabs for tabular presentation;

2. Use a short-hand notation for duplicate column specifications: *{<num>}{<col spec>}; and

3. Using array to insert content with every cell in a column with the notation >{<before>} (or <{<after>}).

If you're into aligning numbers at the least significant digit, then consider using siunitx:

\documentclass{article}
\usepackage{booktabs,siunitx}
\begin{document}
\begin{center}
\sisetup{table-column-width=15mm}
\begin{tabular}{
S[table-format=1]%    x
S[table-format=2]%   xx
S[table-format=4]% xxxx
S[table-format=3]%  xxx
}
\toprule
1 &  2 &    7 &   8 \\
0 & 89 &  100 &  55 \\
4 &  6 & 4999 & 055 \\
\bottomrule
\end{tabular}
\end{center}
\end{document}


Note that 0-prefixes in numbers are removed (which it should).

• I would tend to write \newcolumntype{C}{>{\centering\arraybackslash}p{1.5cm}<{}} and then \begin{tabular}{CCCC} but otherwise I fully agree. – Denis Dec 15 '15 at 16:44
• I do not understand how can Iadd columns? – Sakis Dec 15 '15 at 17:12
• @VanityFair: You can add columns around my *{<num>}{<col spec>} specification. Or, you can increase <num> to set the number of columns you need. – Werner Dec 15 '15 at 18:01
\documentclass{article}
\usepackage{array,booktabs,ragged2e}
\newcolumntype{C}[1]{>{\Centering}p{#1}}
\begin{document}
\begin{center}
\begin{tabular}{ *4{C{1.5cm}} }% or { C{1.5cm} C{1.5cm} ... }
\toprule
1 &  2 &   7  &  8  \\
0 & 89 &  100 &  55 \\
4 &  6 & 4999 & 055 \\
\bottomrule
\end{tabular}
\end{center}
\end{document}