1

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

  • 1
    Welcome to TeX.SX!! It is better to post a full minimal working example. For example, A LaTeX MWE should start with a \documentclass command, have a minimal preamble and then \begin{document}...\end{document}. Unless the problem is a compilation error, the code should compile and be as small as possible to demonstrate your problem. This makes it much easier for people to help you --- and much more likely that they will! – Andrew Apr 18 '16 at 9:06
  • The tabularx manual states: Do not use \multicolumn with X ;-) – user31729 Apr 18 '16 at 9:08
  • You can also check the less known tabulary package with its C column-type. – ebosi Apr 18 '16 at 10:15
1

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

1

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

I suggest you define a centered version of the X column type and use it for all four columns.

enter image description here

\documentclass{article}
\usepackage{tabularx}
\newcolumntype{C}{>{\centering\arraybackslash}X}
\begin{document}
\begin{table}[!ht]
\begin{tabularx}{\linewidth}{*{4}{C}}
  \hline\\  
  \multicolumn{4}{c}{\Large Keywords}
  \\
  \hline
  \\
  \large A & \large B & \large C & \large D\\[1\baselineskip] 
  1 & 2 & 3  & 4\\ 
  \hline
\end{tabularx}
\caption{test}\label{test}
\end{table}
\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.