[Tex/LaTex] Both horizontal and vertical centering in tabularx

tables

How to set a width of columns to be centered in vertical direction? Or in vertical and horizontal direction and the cells bellow as well?
Thank you

\documentclass[12pt,a4paper]{report}
\usepackage{booktabs, makecell, tabularx}
\setlength\textwidth{145mm}
\setlength\textheight{247mm}
\setlength\oddsidemargin{15mm}
\setlength\evensidemargin{15mm}
\setlength\topmargin{0mm}
\setlength\headsep{0mm}
\setlength\headheight{0mm}
\let\openright=\clearpage
\begin{document}
 \begin{table}
\small
\renewcommand{\arraystretch}{1.2}
\begin{tabularx}{\textwidth}{>{\hsize=0.2\hsize}X
                             >{\hsize=0.25\hsize}X
                             >{\hsize=0.25\hsize}X
                             >{\hsize=0.3\hsize}X}

\Xhline{1.2pt}\noalign{\vskip 0.4ex}\Xhline{1.2pt}%                          
Název souboru&  Průměrná hodnota chyby& \makecell{Odchylka určení \\ průměrné chyby}&   \makecell{Počet středovaných \\ bodů}\\
\Xhline{1.2pt}\noalign{\vskip 0.4ex}
B & A&  C&  D\\  

\Xhline{1.2pt}  
\end{tabularx}
\end{table}

\end{document}

enter image description here

Best Answer

Combining \renewcommand\tabularxcolumn[1]{m{#1}} (from Vertical centering of all columns in \tabularx environment) and \newcolumntype{C}{>{\centering\arraybackslash}X} (from Centering in tabularx and X columns) you can achieve the following:

enter image description here

\documentclass[12pt,a4paper]{report}
\usepackage{booktabs, makecell, tabularx}


\renewcommand\tabularxcolumn[1]{m{#1}}
\newcolumntype{C}{>{\centering\arraybackslash}X}
\begin{document}
 \begin{table}
\small
\renewcommand{\arraystretch}{1.2}
\begin{tabularx}{\textwidth}{>{\hsize=0.2\hsize}C
                             >{\hsize=0.25\hsize}C
                             >{\hsize=0.25\hsize}C
                             >{\hsize=0.3\hsize}C}

    \Xhline{1.2pt}\noalign{\vskip 0.4ex}\Xhline{1.2pt}%                          
 Název souboru&  Průměrná hodnota chyby& Odchylka určení průměrné chyby&   Počet středovaných  bodů\\
\Xhline{1.2pt}\noalign{\vskip 0.4ex}
B & A&  C&  D\\

\Xhline{1.2pt}  
\end{tabularx}
\end{table}

\end{document}

Please keep in mind that I have removed the \makecell cmmands as they distorted the vertical alignment. If you need to place the linebreaks manually, you can either use \makecell[cc]{<text>} in every column header (as suggested by Paul Stanley in the comments) or replace \newcolumntype{C}{>{\centering\arraybackslash}X} by \newcolumntype{C}{>{\centering\let\newline\\\arraybackslash}X} and use \newline where you want the linebreak to appear.

Related Question