我在 TabularX 中製作了一個列寬表格,並希望將其放置在頁面頂部,但還沒有找到如何做到這一點的答案 - 有辦法嗎?
\begin{center}
\footnotesize
\begin{tabularx} {\columnwidth} {
| >{\centering\arraybackslash}X
| >{\centering\arraybackslash}X
| >{\centering\arraybackslash}X
| >{\centering\arraybackslash}X |}
\hline
\makecell{Planet\\} & \makecell{Mass\\(M\textsubscript{s})} & \makecell{SMA\\(AU)} & \makecell{TA\\(\textdegree)} \\
\hline
b & 0.003 & 70 & 153 \\
\hline
c & 0.004 & 38.9 & 48 \\
\hline
d & 0.005 & 25.6 & 292 \\
\hline
e & 0.008 & 14.4 & 327 \\
\hline
\end{tabularx}
\captionof{table}{Parameters calculated using figs 2 and 3.}
\label{Table 1}
\end{center}
答案1
若要強制 LaTeXtabularx
在列頂部排版材料,請將材料放置在table
環境中,而不是center
環境中。請注意,由於環境的寬度tabularx
設定為\columnwidth
,因此\centering
不需要明確指令。
還要考慮@David Carlisle 的建議,將三個資料列中的數字與其(顯式或隱式)小數標記對齊。並且,請嘗試透過擺脫所有垂直規則並使用較少但間距良好的水平規則來使表格更加開放和吸引人。下面的螢幕截圖顯示了這兩個建議的應用情況。
\documentclass[twocolumn]{article}
\usepackage{tabularx,makecell,dcolumn,booktabs,lipsum}
\newcolumntype{C}{>{\centering\arraybackslash}X}
\newcolumntype{d}[1]{D..{#1}}
% handy shortcut macros:
\newcommand\mC[1]{\multicolumn{1}{C}{#1}} % without vertical rules
\newcommand\mD[1]{\multicolumn{1}{C|}{#1}} % with vertical rules
\begin{document}
\lipsum[1] % filler text
\begin{table}[t]
%\footnotesize % not needed
\begin{tabularx}{\columnwidth}{
| *{4}{C|} }
\hline
\makecell{Planet\\} &
\makecell{Mass\\(M\textsubscript{s})} &
\makecell{SMA\\(AU)} &
\makecell{TA\\(\textdegree)} \\
\hline
b & 0.003 & 70 & 153 \\
\hline
c & 0.004 & 38.9 & 48 \\
\hline
d & 0.005 & 25.6 & 292 \\
\hline
e & 0.008 & 14.4 & 327 \\
\hline
\end{tabularx}
\caption{OP's original version}
\label{table:parameters1}
\bigskip
\begin{tabularx}{\columnwidth}{
| >{\centering}X | d{1.3} | d{2.1} | d{3.0} |}
\hline
Planet &
\mD{\makecell{Mass\\(M\textsubscript{s})}} &
\mD{\makecell{SMA\\(AU)}} &
\mD{\makecell{TA\\(\textdegree)}} \\
\hline
b & 0.003 & 70 & 153 \\
\hline
c & 0.004 & 38.9 & 48 \\
\hline
d & 0.005 & 25.6 & 292 \\
\hline
e & 0.008 & 14.4 & 327 \\
\hline
\end{tabularx}
\caption{Numbers aligned on decimal markers}
\label{table:parameters2}
\bigskip
\begin{tabularx}{\columnwidth}{
@{} >{\centering}X d{1.3} d{2.1} d{3.0} @{}}
\toprule
Planet &
\mC{\makecell{Mass\\(M\textsubscript{s})}} &
\mC{\makecell{SMA\\(AU)}} &
\mC{\makecell{TA\\(\textdegree)}} \\
\midrule
b & 0.003 & 70 & 153 \\
c & 0.004 & 38.9 & 48 \\
d & 0.005 & 25.6 & 292 \\
e & 0.008 & 14.4 & 327 \\
\bottomrule
\end{tabularx}
\caption{Numbers aligned on decimal markers, no vertical rules, fewer but well-spaced horizontal rules}
\label{table:parameters3}
\end{table}
\lipsum[2-4] % more filler text
\end{document}