[Tex/LaTex] Table with 100 % width and vertical / horizontal alignment

tablestabularx

I want to draw the following table in LaTeX. In the first column the text should be left aligned. The text in all other cells should be centered. The first problem occurs with D in the first row. If I write a \centering in front of D, I get a LaTeX error. The second problem is, that I want to vertically align the text in all cells but I don't know how. I have found a solution but it doesn't work if the width of the first column is specified.

\documentclass{article}
\usepackage{blindtext}
\usepackage{tabularx}

\begin{document}
  \begin{tabularx}{\textwidth}{|p{4cm}|X|X|X|X|}
    \hline
               & \centering A & \centering B & \centering C & D\\
    \hline
    \blindtext & 123 & 123 & 123 & 123\\
    \hline
  \end{tabularx}
\end{document}

Best Answer

For horizontally and vertically centered text redefine the X column definition:

\documentclass{article}
\usepackage{ragged2e}
\usepackage{tabularx}
\renewcommand\tabularxcolumn[1]{>{\Centering}m{#1}}

\newcommand\TEXT{%
I want to draw the following table in Latex. In the first column the text should be left aligned. The text in all other cells should be centered.}% only for demo


\begin{document}
\begin{tabularx}{\textwidth}{|m{4cm}*4{|X}|}\hline
           &  A  &   B &   C & D         \\\hline
\TEXT\TEXT & 123 & 123 & 123 & \TEXT\\\hline
\end{tabularx}
\end{document}

enter image description here

Related Question