如何在 LaTeX 中将表格居中

如何在 LaTeX 中将表格居中

我想将表格居中放置在标题下方,但结果却是右对齐。
我尝试了,\begin{center}\begin{table}结果相同。

\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}

结果:右对齐

答案1

表格对于可用的文本宽度来说太大,请参阅 Christian Hupfer 的评论

一条建议:

  • Xtabularx与列类似p,但会自动使用可用空间,无需明确指定尺寸。只有表格才有宽度。

  • \midrule包装的booktabs周围有适当的垂直空白,以获得更好的规则。

  • \RaggedRight通过允许连字符,使包ragged2e变得更平滑。\raggedright

  • \hangindent=1em\hangafter1\relax用于缩进单元格第一段中的后续行。

  • \slash而不是/带有断点的斜线。

\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}

结果

相关内容