I am using the following code to format my tables for my thesis (template based on this question here: Wrap text in table column header AND fit table width to pagewidth
\usepackage[utf8]{inputenc}
\usepackage{fourier}
\usepackage{array}
\usepackage{booktabs}
\usepackage{tabularx}
\usepackage{makecell}
\newcolumntype{Z}{ >{\centering\arraybackslash}X }
\renewcommand\theadfont{\bfseries}
%\renewcommand\theadalign{cc}
\usepackage[autolanguage, np]{numprint}
\begin{document}
\begin{table}[!h]
\setlength\tabcolsep{4pt}
\begin{tabularx}{\textwidth}{*{4}{Z}}
\toprule
\multicolumn{4}{c}{xxx xx xxxx} \\
\midrule
\thead{miRNA} & \thead{logFC \\ (ABCDEF vs \\ ABCFED) } & \thead{PValue} & \thead{False \\Discovery\\ Rate} \\%
\midrule
abcd efg hijka & $-1.854$ & \np{9.52E-11} & \np{8.41E-10} \\
abcd efg hijka & $-1.815$ & \np{3.38E-09} & \np{2.42E-08} \\
\bottomrule
\end{tabularx}
\end{table}
a lot of text here to show text width a lot of text here to show text width a lot of text here to show text width a lot of text here to show text width a lot of text here to show text width a lot of text here to show text width a lot of text here to show text width
\end{document}
I was wondering how can I left align only the data in the first column of this table? Is there an easy way to maybe change the \newcolumntype{Z}{ >{\centering\arraybackslash}X }
command to only leftalign data in the first column of the table and not the header? The other columns and headers should remain centered.
Best Answer
This code should do it:
since an
X
column, by default, is left-aligned, but\thead
is centred (vertically and horizontally).Additionally, I think
\cmidrule(lr){1-4}
between the first two rows will look nicer than\midrule
.