[Tex/LaTex] How to center a table in LaTeX

horizontal alignmenttables

I want to put a centered table below the title, instead i get a right handed alignment.
I tried \begin{center} instead of \begin{table}, i get the same result.

\documentclass{article}
\usepackage{array}
\usepackage{multicol}
\usepackage{lineno}


\begin{document}

\title{Title:\\ more title}
\maketitle

\begin{table}[h]
\centering
\small
\setlength\tabcolsep{3pt}
\setlength\extrarowheight{2pt}

\begin{tabular}{llll}
\textsc{column 1}   & \textsc{column 2}              & \textsc{column 3}& 
\textsc{column 4}        \\ \hline
something here      & something more here            & something here a     & something here           \\
something here      & something here                 & Rsomething more here & something here           \\
something here      & something here /something here & something here n     & something more here      \\
something more here & something more here            & something here       & something more here more \\
something here      & something here                 &                      & something here
\end{tabular}

\end{table}

\end{document}

Result: right alignment

Best Answer

The table is too large for the available text width, see Christian Hupfer's comment.

A suggestion:

  • X columns of tabularx are similar to p columns, but use the available space automatically without explicit dimension. Only the table gets a width.

  • \midrule of package booktabs for a nicer rule with proper vertical white space around.

  • \RaggedRight of package ragged2e to get a smoother \raggedright by allowing hyphenation.

  • \hangindent=1em\hangafter1\relax for indentation of the follow-up lines in the cells' first paragraph.

  • \slash instead of / for a slash with break point.

\documentclass{article}
\usepackage{array}
\usepackage{booktabs}
\usepackage{tabularx}
\usepackage{ragged2e}
\usepackage{multicol}
\usepackage{lineno}


\begin{document}

\title{Title:\\ more title}
\maketitle

\begin{table}[h]
\centering
\small
\setlength\tabcolsep{3pt}
\setlength\extrarowheight{2pt}

\begin{tabularx}{\linewidth}{*{4}{>{\hangindent=1em\hangafter=1\RaggedRight}X}}
\textsc{column 1}   & \textsc{column 2}              & \textsc{column 3}&
\textsc{column 4}        \\ \midrule
something here      & something more here            & something here a     & something here           \\
something here      & something here                 & Rsomething more here & something here           \\
something here      & something here\slash something here & something here  & something more here      \\
something more here & something more here            & something here       & something more here more \\
something here      & something here                 &                      & something here
\end{tabularx}
\end{table}

\end{document}

Result

Related Question