[Tex/LaTex] Centering in tabularx and X columns

horizontal alignmenttablestabularx

How can I center the column when using X in tabularx environment like in this example?

\begin{tabularx}{\textwidth}{@{}lXXXXX@{}}
 1 & 2 & 3 & 4 & 5 \\   
\end{tabularx}

Best Answer

I recently dealt with the same task, so here I present my solution: I defined a new columntype Y to center the cells in a tabularxenvironment.

In the preamble define:

\newcolumntype{Y}{>{\centering\arraybackslash}X}

to typeset the example simply enter

\begin{tabularx}{\textwidth}{@{}lYYYYY@{}}
 1 & 2 & 3 & 4 & 5 & 6\\   
\end{tabularx}
Related Question