將標題置於表格下方居中

將標題置於表格下方居中

我有一個 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}

相關內容