[Tex/LaTex] Column alignment and spacing in tabularx

tabularx

I have a problem with my tables and I am not sure why. I made this table format a long time ago and wanted to use the same style again. Though I cannot seem to get the leftmost column to behave.

I just want all the columns to be equal and be centered.

\begin{table}[!ht]
\begin{tabularx}{\linewidth}{X*{4}{c}}
  \hline\\   \multicolumn{4}{c}{\Large Keywords}
  \\
  \hline
  \\
  \large A & \large B & \large C & \large D\\\\ 
  1 & 2 & 3  & 4\\ 

  \hline
\end{tabularx}
\caption{test}\label{test}
\end{table}

enter image description here

This is what it looks like now.

How would one go about fixing this? 🙂

//Bogi

Best Answer

The preamble of your tabularx environment wasn't correct for what you want (you had one X column and 4 centred columns with their natural width). I took the liberty to replace the \hlines with rules from the booktabs package, which hace some vertical padding around them and a variable width, looking more ‘professional’:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{tabularx, booktabs}
\renewcommand{\tabularxcolumn}[1]{>{\centering\arraybackslash}p{#1}}

\begin{document}

\begin{table}[!ht]
  \begin{tabularx}{\linewidth}{*{4}{X}}
    \toprule
    \multicolumn{4}{c}{\Large Keywords}
    \\
    \midrule
    \\
    \large A & \large B & \large C & \large D \\\\
    1 & 2 & 3 & 4 \\
    \bottomrule
  \end{tabularx}
  \caption{test}\label{test}
\end{table}

\end{document} 

enter image description here

Related Question