我有一张有 2 列 12 行的表格。我需要表格显示在页面的左侧(我可以做到),但是标题位于页面的中央。我想将标题放在表格下方,并使其位于表格下方的中央。输出如下所示。
\documentclass[12pt,english]{article}
\usepackage{caption}
\begin{document}
\begin{table}[H]
\begin{tabular}{|c|>{\centering}p{2cm}|}
\hline
Year & Population (millions)\tabularnewline
\hline
$1900$ & $1650$\tabularnewline
$1910$ & $1750$\tabularnewline
$1920$ & $1860$\tabularnewline
$1930$ & $2070$\tabularnewline
$1940$ & $2300$\tabularnewline
$1950$ & $2560$\tabularnewline
$1960$ & $3040$\tabularnewline
$1970$ & $3710$\tabularnewline
$1980$ & $4450$\tabularnewline
$1990$ & $5280$\tabularnewline
$2000$ & $6070$\tabularnewline
\hline
\end{tabular}
\raggedright{}\caption{World Population}\label{table1}
\end{table}
\end{document}
答案1
这里有一种方法(因为您已经想要[H]
选项并且已经加载了caption
包,我想这对您来说没问题):
\documentclass[12pt,english]{article}
\usepackage{caption}
\usepackage{array}
\begin{document}
% A \noindent is possibly needed here as @Mico suggested in his comment
\noindent\begin{minipage}{0.35\textwidth}
\centering
\begin{tabular}{|c|>{\centering}p{2cm}|}
\hline
Year & Population (millions)\tabularnewline
\hline
$1900$ & $1650$\tabularnewline
$1910$ & $1750$\tabularnewline
$1920$ & $1860$\tabularnewline
$1930$ & $2070$\tabularnewline
$1940$ & $2300$\tabularnewline
$1950$ & $2560$\tabularnewline
$1960$ & $3040$\tabularnewline
$1970$ & $3710$\tabularnewline
$1980$ & $4450$\tabularnewline
$1990$ & $5280$\tabularnewline
$2000$ & $6070$\tabularnewline
\hline
\end{tabular}
\captionof{table}{World Population}\label{table1}
\end{minipage}
\end{document}
答案2
由于表格内容必须排版为左对齐(又称右对齐),我认为如果标题也设置为左对齐,看起来会更好。(但是,请参见下文以了解不同的解决方案。)可以通过加载带有caption
选项singlelinecheck=false
和的包来实现此格式化目标justification=raggedright
。
\documentclass[12pt,english]{article}
\usepackage{array,caption}
\captionsetup{singlelinecheck=false,justification=raggedright}
\begin{document}
\begin{table}[ht!]
\begin{tabular}{|c|>{\centering\arraybackslash}p{2cm}|}
\hline
Year & Population (millions)\\ \hline
$1900$ & $1650$\\
$1910$ & $1750$\\
$1920$ & $1860$\\
$1930$ & $2070$\\
$1940$ & $2300$\\
$1950$ & $2560$\\
$1960$ & $3040$\\
$1970$ & $3710$\\
$1980$ & $4450$\\
$1990$ & $5280$\\
$2000$ & $6070$\\
\hline
\end{tabular}
\caption{World Population}\label{table1}
\end{table}
\end{document}
或者,如果标题必须位于tabular
材料正下方和材料tabular
必须排版左对齐,我建议您(a)运行\captionsetup{justification=centering}
,(b)加载三部分表包,以及 (c) 将tabular
环境和\caption
语句都包含在threeparttable
环境中。此设置允许 LaTeX 测量tabular
材料的宽度并将标题置于表格下方的中心;如果需要,LaTeX 会自动在标题中插入换行符。此行为如以下屏幕截图所示。
\documentclass[12pt,english]{article}
\usepackage{array,caption,threeparttable}
\captionsetup{justification=centering}
\begin{document}
\begin{table}[ht!]
\begin{threeparttable}
\begin{tabular}{|c|>{\centering\arraybackslash}p{2cm}|}
\hline
Year & Population (millions)\\ \hline
$1900$ & $1650$\\
$1910$ & $1750$\\
$1920$ & $1860$\\
$1930$ & $2070$\\
$1940$ & $2300$\\
$1950$ & $2560$\\
$1960$ & $3040$\\
$1970$ & $3710$\\
$1980$ & $4450$\\
$1990$ & $5280$\\
$2000$ & $6070$\\
\hline
\end{tabular}
\caption{World Population}\label{table1}
\end{threeparttable}
\end{table}
\end{document}