表格开头的标题

表格开头的标题

我是 LaTeX 新手。我从不同的链接获取了表格的代码,但现在我尝试添加标签时出现错误 \caption outside float。

\begin{adjustbox}{minipage=18cm, center}

\noindent\begin{tabularx}{\textwidth} 
{ 
  | @{\hspace{0.3em}}X
  | @{\hspace{0.3em}}X 
  | @{\hspace{0.3em}}X 
  | @{\hspace{0.3em}}X 
  | @{\hspace{0.3em}}X 
  | @{\hspace{0.3em}}X
  | @{\hspace{0.3em}}X
  | @{\hspace{0.3em}}X
  | @{\hspace{0.3em}}X |  }
\caption{A Table}\label{tab:1}\\
 \hline
 
A & B & C & D & E & F & G & H & I \\
 \hline
 A & 0.7 & 12.22  & $1.932 \pm 0.001$  & 12.46  & $1.826 \pm 0.002$ & 12.090 & $2.027 \pm 0.001$ & $1.928 \pm 0.082$ \\
 \hline
 A & 2 & 30.55  & $1.279 \pm 0.001$  & 28.26  & $1.341 \pm 0.001$ & 30.44 & $1.318 \pm 0.001$ & $1.312 \pm 0.026$ \\
\hline
 A & 3 & 44.22  & $0.8494 \pm 0.0004$  & 37.34  & $0.8886 \pm 0.0002$ & 37.91 & $0.8857 \pm 0.0005$ & $0.8746 \pm 0.0179$ \\
\hline
 B & 0.7 & 11.75  & $1.906 \pm 0.001$  & 11.35  & $1.885 \pm 0.001$ & 11.64 & $1.891 \pm 0.001$ & $1.894 \pm 0.009$ \\
\hline
 B & 3 & 46.94  & $0.8352 \pm 0.0003$  & 45.70  & $0.8807 \pm 0.0003$ & 46.96 & $0.8417 \pm 0.0002$ & $0.8586 \pm 0.0201$ \\
\hline
 B & 4 & 61,23  & $0.5590 \pm 0.0002$  & 61.83  & $0.5913 \pm 0.0001$ & 59.57 & $0.6298 \pm 0.0001$ & $0.5991 \pm 0.0290$ \\
\hline
 C & 0.7 & 11.27  & $1.828 \pm 0.002$  & 11.03  & $1.806 \pm 0.001$ & 11.40 & $1.841 \pm 0.001$ & $1.825 \pm 0.014$ \\
\hline
 C & 2 & 30.57  & $1.300 \pm 0.001$  & 30.60  & $1.272 \pm 0.001$ & 30.54 & $1.277 \pm 0.001$ & $1.283 \pm 0.012$ \\
\hline
 C & 3 & 45.10  & $0.7483 \pm 0.0004$  & 47.52  & $0.8156 \pm 0.0002$ & 46.55 & $0.8595 \pm 0.0001$ & $0.8078 \pm 0.046$ \\
\hline
 C & 4 & 60.15  & $0.6498 \pm 0.0001$  & 59.72  & $0.6469 \pm 0.0001$ & 58.99 & $0.6380 \pm 0.0001$ & $0.6449 \pm 0.0050$ \\
\hline
\end{tabularx}
\end{adjustbox}
  1. 主要问题是为什么当我尝试在表格开头添加标签时会出现错误

  2. 如果我收到任何关于如何更好地编写表格的建议,那也会很有帮助。它非常宽,所以我过去常常\begin{adjustbox}{minipage=18cm, center}为表格设置更宽的页面。然后我也尝试在右侧去掉一点填充@{\hspace{0.3em}}。但我是新手,真的不知道我在做什么。我将不胜感激所有建议。

答案1

根据您目前提供的信息,我认为没有理由使用环境tabularx——至少,具有 9 个等宽列的环境。我也认为没有理由使用锤子adjustbox。我会使用普通tabular环境或tabular*环境。如果使用后者,请务必省略所有竖线。(相信我,它们不是必需的。)使用较少但间距适当的水平线也会对表格的可读性产生奇效——请参见下面的第二个表格。我还将使第 3 至第 9 列的内容居中。

如果您希望使用\caption\label指令,则需要将它们与表格材料一起嵌入到环境中table

在此处输入图片描述

\documentclass{article}
\usepackage[letterpaper,margin=1in]{geometry} % set page parameters suitably
\usepackage{array}    % for the first table
\usepackage{booktabs} % for the second table
\begin{document}
\begin{table}[ht!]
\setlength\extrarowheight{2pt} % for a slighly more open "look"
\centering
\caption{A Table\strut}
\label{tab:1}
\setlength\tabcolsep{5.5pt} % default: 6pt
\begin{tabular}{ | l | l | *{7}{c|} }
\hline 
A & B & C & D & E & F & G & H & I \\
 \hline
 A & 0.7 & 12.22  & $1.932\pm0.001$   & 12.46  & $1.826\pm0.002$   & 12.090 & $2.027\pm0.001$ & $1.928\pm0.082$ \\
 \hline
 A & 2   & 30.55  & $1.279\pm0.001$   & 28.26  & $1.341\pm0.001$   & 30.44 & $1.318\pm0.001$ & $1.312\pm0.026$ \\
\hline
 A & 3   & 44.22  & $0.8494\pm0.0004$ & 37.34  & $0.8886\pm0.0002$ & 37.91 & $0.8857\pm0.0005$ & $0.8746\pm0.0179$ \\
\hline
 B & 0.7 & 11.75  & $1.906\pm0.001$   & 11.35  & $1.885\pm0.001$   & 11.64 & $1.891\pm0.001$ & $1.894\pm0.009$ \\
\hline
 B & 3   & 46.94  & $0.8352\pm0.0003$ & 45.70  & $0.8807\pm0.0003$ & 46.96 & $0.8417\pm0.0002$ & $0.8586\pm0.0201$ \\
\hline
 B & 4   & 61,23  & $0.5590\pm0.0002$ & 61.83  & $0.5913\pm0.0001$ & 59.57 & $0.6298\pm0.0001$ & $0.5991\pm0.0290$ \\
\hline
 C & 0.7 & 11.27  & $1.828\pm0.002$   & 11.03  & $1.806\pm0.001$   & 11.40 & $1.841\pm0.001$ & $1.825\pm0.014$ \\
\hline
 C & 2   & 30.57  & $1.300\pm0.001$   & 30.60  & $1.272\pm0.001$   & 30.54 & $1.277\pm0.001$ & $1.283\pm0.012$ \\
\hline
 C & 3   & 45.10  & $0.7483\pm0.0004$ & 47.52  & $0.8156\pm0.0002$ & 46.55 & $0.8595\pm0.0001$ & $0.8078\pm0.046$ \\
\hline
 C & 4   & 60.15  & $0.6498\pm0.0001$ & 59.72  & $0.6469\pm0.0001$ & 58.99 & $0.6380\pm0.0001$ & $0.6449\pm0.0050$ \\
\hline
\end{tabular}
\end{table}

\begin{table}[h]
\caption{Another Table\strut}
\label{tab:2}
\setlength\tabcolsep{0pt}
\begin{tabular*}{\textwidth}{@{\extracolsep{\fill}} ll *{7}{c}  }
\toprule
 
A & B & C & D & E & F & G & H & I \\
\midrule
 A & 0.7 & 12.22  & $1.932\pm0.001$   & 12.46  & $1.826\pm0.002$   & 12.090 & $2.027\pm0.001$ & $1.928\pm0.082$ \\
 %\hline
   & 2   & 30.55  & $1.279\pm0.001$   & 28.26  & $1.341\pm0.001$   & 30.44 & $1.318\pm0.001$ & $1.312\pm0.026$ \\
%\hline
   & 3   & 44.22  & $0.8494\pm0.0004$ & 37.34  & $0.8886\pm0.0002$ & 37.91 & $0.8857\pm0.0005$ & $0.8746\pm0.0179$ \\
%\hline
\addlinespace
 B & 0.7 & 11.75  & $1.906\pm0.001$   & 11.35  & $1.885\pm0.001$   & 11.64 & $1.891\pm0.001$ & $1.894\pm0.009$ \\
%\hline
   & 3   & 46.94  & $0.8352\pm0.0003$ & 45.70  & $0.8807\pm0.0003$ & 46.96 & $0.8417\pm0.0002$ & $0.8586\pm0.0201$ \\
%\hline
   & 4   & 61,23  & $0.5590\pm0.0002$ & 61.83  & $0.5913\pm0.0001$ & 59.57 & $0.6298\pm0.0001$ & $0.5991\pm0.0290$ \\
%\hline
\addlinespace
 C & 0.7 & 11.27  & $1.828\pm0.002$   & 11.03  & $1.806\pm0.001$   & 11.40 & $1.841\pm0.001$ & $1.825\pm0.014$ \\
%\hline
   & 2   & 30.57  & $1.300\pm0.001$   & 30.60  & $1.272\pm0.001$   & 30.54 & $1.277\pm0.001$ & $1.283\pm0.012$ \\
%\hline
   & 3   & 45.10  & $0.7483\pm0.0004$ & 47.52  & $0.8156\pm0.0002$ & 46.55 & $0.8595\pm0.0001$ & $0.8078\pm0.046\phantom{0}$ \\
%\hline
   & 4   & 60.15  & $0.6498\pm0.0001$ & 59.72  & $0.6469\pm0.0001$ & 58.99 & $0.6380\pm0.0001$ & $0.6449\pm0.0050$ \\
\bottomrule
\end{tabular*}
\end{table}
\end{document}

针对原始发帖人的后续评论的附录。感谢您提供有关文档设置的更多信息。我建议您将单位放在变量名称下方的一行中;这样您仍然可以在纵向模式下排版表格。但是,如果您的边距比约 2.5 厘米宽得多,则可能必须切换到横向模式。例如,这可以在包rotating及其sidewaystable环境的帮助下完成;请参阅下面的代码以了解实现(但未在单独的屏幕截图中显示)。

在此处输入图片描述

\documentclass[longbibliography,slovene,a4paper,12pt]{book}
\usepackage[margin=2.5cm]{geometry} % set width of text block suitably
\usepackage{babel}
\usepackage{amsmath,booktabs,siunitx}
\usepackage[figuresright]{rotating}
\begin{document}

\begin{table}[h]
\sisetup{per-mode=symbol}
\caption{A table in portrait mode\strut}
\label{tab:2}
\footnotesize % switch to 10pt font size
\setlength\tabcolsep{0pt} % let LaTeX figure out intercolumn whitespace amounts
\begin{tabular*}{\textwidth}{@{\extracolsep{\fill}} l l *{7}{c}  }
\toprule
 
Sample & $d$ & $M_1$ & $C_{p 1}$ & $M_2$ & $C_{p 2}$ 
& $M_3$ & $C_{p 3}$ & $C_{p,\mathrm{avg}}$ \\
& [\si{\milli\meter}] & [\si{\milli\gram}] & [\si{\joule\per{\gram\kelvin}}] 
& [\si{\milli\gram}] & [\si{\joule\per{\gram\kelvin}}] & [\si{\milli\gram}] 
& [\si{\joule\per{\gram\kelvin}}] & [\si{\joule\per{\gram\kelvin}}] \\
\midrule
 A & 0.7 & 12.22  & $1.932\pm0.001$   & 12.46 & $1.826\pm0.002$   & 12.09 & $2.027\pm0.001$   & $1.928\pm0.082$   \\
   & 2   & 30.55  & $1.279\pm0.001$   & 28.26 & $1.341\pm0.001$   & 30.44 & $1.318\pm0.001$   & $1.312\pm0.026$   \\
   & 3   & 44.22  & $0.8494\pm0.0004$ & 37.34 & $0.8886\pm0.0002$ & 37.91 & $0.8857\pm0.0005$ & $0.8746\pm0.0179$ \\
\addlinespace
 B & 0.7 & 11.75  & $1.906\pm0.001$   & 11.35 & $1.885\pm0.001$   & 11.64 & $1.891\pm0.001$   & $1.894\pm0.009$   \\
   & 3   & 46.94  & $0.8352\pm0.0003$ & 45.70 & $0.8807\pm0.0003$ & 46.96 & $0.8417\pm0.0002$ & $0.8586\pm0.0201$ \\
   & 4   & 61,23  & $0.5590\pm0.0002$ & 61.83 & $0.5913\pm0.0001$ & 59.57 & $0.6298\pm0.0001$ & $0.5991\pm0.0290$ \\
\addlinespace
 C & 0.7 & 11.27  & $1.828\pm0.002$   & 11.03 & $1.806\pm0.001$   & 11.40 & $1.841\pm0.001$ & $1.825\pm0.014$ \\
   & 2   & 30.57  & $1.300\pm0.001$   & 30.60 & $1.272\pm0.001$   & 30.54 & $1.277\pm0.001$ & $1.283\pm0.012$ \\
   & 3   & 45.10  & $0.7483\pm0.0004$ & 47.52 & $0.8156\pm0.0002$ & 46.55 & $0.8595\pm0.0001$ & $0.8078\pm0.046 \phantom{0}$ \\
   & 4   & 60.15  & $0.6498\pm0.0001$ & 59.72 & $0.6469\pm0.0001$ & 58.99 & $0.6380\pm0.0001$ & $0.6449\pm0.0050$ \\
\bottomrule
\end{tabular*}

\end{table}

\begin{sidewaystable}
\centering
\sisetup{per-mode=symbol}
\caption{A table in landscape mode\strut}
\label{tab:3}
\begin{tabular}{@{} l l *{7}{c} @{}}
\toprule
Sample & $d$ & $M_1$ & $C_{p 1}$ & $M_2$ & $C_{p 2}$ 
& $M_3$ & $C_{p 3}$ & $C_{p,\mathrm{avg}}$ \\
& [\si{\milli\meter}] & [\si{\milli\gram}] & [\si{\joule\per{\gram\kelvin}}] 
& [\si{\milli\gram}] & [\si{\joule\per{\gram\kelvin}}] & [\si{\milli\gram}] 
& [\si{\joule\per{\gram\kelvin}}] & [\si{\joule\per{\gram\kelvin}}] \\
\midrule
 A & 0.7 & 12.22  & $1.932\pm0.001$   & 12.46 & $1.826\pm0.002$   & 12.09 & $2.027\pm0.001$   & $1.928\pm0.082$   \\
   & 2   & 30.55  & $1.279\pm0.001$   & 28.26 & $1.341\pm0.001$   & 30.44 & $1.318\pm0.001$   & $1.312\pm0.026$   \\
   & 3   & 44.22  & $0.8494\pm0.0004$ & 37.34 & $0.8886\pm0.0002$ & 37.91 & $0.8857\pm0.0005$ & $0.8746\pm0.0179$ \\
\addlinespace
 B & 0.7 & 11.75  & $1.906\pm0.001$   & 11.35 & $1.885\pm0.001$   & 11.64 & $1.891\pm0.001$   & $1.894\pm0.009$   \\
   & 3   & 46.94  & $0.8352\pm0.0003$ & 45.70 & $0.8807\pm0.0003$ & 46.96 & $0.8417\pm0.0002$ & $0.8586\pm0.0201$ \\
   & 4   & 61,23  & $0.5590\pm0.0002$ & 61.83 & $0.5913\pm0.0001$ & 59.57 & $0.6298\pm0.0001$ & $0.5991\pm0.0290$ \\
\addlinespace
 C & 0.7 & 11.27  & $1.828\pm0.002$   & 11.03 & $1.806\pm0.001$   & 11.40 & $1.841\pm0.001$ & $1.825\pm0.014$ \\
   & 2   & 30.57  & $1.300\pm0.001$   & 30.60 & $1.272\pm0.001$   & 30.54 & $1.277\pm0.001$ & $1.283\pm0.012$ \\
   & 3   & 45.10  & $0.7483\pm0.0004$ & 47.52 & $0.8156\pm0.0002$ & 46.55 & $0.8595\pm0.0001$ & $0.8078\pm0.046 \phantom{0}$ \\
   & 4   & 60.15  & $0.6498\pm0.0001$ & 59.72 & $0.6469\pm0.0001$ & 58.99 & $0.6380\pm0.0001$ & $0.6449\pm0.0050$ \\
\bottomrule
\end{tabular}

\end{sidewaystable}
\end{document}

答案2

tabular*我建议根据、booktabs和进行以下重新设计siunitx

在此处输入图片描述

\documentclass{article}
\usepackage{geometry}
\usepackage{siunitx}
\usepackage{booktabs}
\usepackage{caption}
\begin{document}

\begin{table}
\small
\sisetup{separate-uncertainty=true}
\setlength{\tabcolsep}{0pt}
\caption{A Table}\label{tab:1}
\begin{tabular*}{\textwidth} 
{@{\extracolsep{\fill}}
  l
  S[table-format=1.1]
  S[table-format=2.2] 
  S[table-format=1.4(5)] 
  S[table-format=2.2] 
  S[table-format=1.4(5)]
  S[table-format=2.3] 
  S[table-format=1.4(5)]
  S[table-format=1.4(5)] }
\toprule
A & {B} & {C} & {D} & {E} & {F} & {G} & {H} & {I} \\
\midrule
 A & 0.7 & 12.22  & 1.932(1)  & 12.46  & 1.826(2) & 12.090 & 2.027(1) & 1.928(82) \\
 A & 2 & 30.55  & 1.279(1)  & 28.26  & 1.341(1) & 30.44 & 1.318(1) & 1.312(26) \\
 A & 3 & 44.22  & 0.8494(4)  & 37.34  & 0.8886(2) & 37.91 & 0.8857(5) & 0.8746(179) \\
\addlinespace
 B & 0.7 & 11.75  & 1.906(1)  & 11.35  & 1.885(1) & 11.64 & 1.891(1) & 1.894(9) \\
 B & 3 & 46.94  & 0.8352(3)   & 45.70  & 0.8807(3) & 46.96 & 0.8417(2) & 0.8586(201) \\
 B & 4 & 61,23  & 0.5590(2)  & 61.83  & 0.5913(1) & 59.57 & 0.6298(1) & 0.5991(290) \\
\addlinespace
 C & 0.7 & 11.27  & 1.828(2)  & 11.03  & 1.806(1) & 11.40 & 1.841(1) & 1.825(14) \\
 C & 2 & 30.57  & 1.300(1)  & 30.60  & 1.272(1) & 30.54 & 1.277(1) & 1.283(12) \\
 C & 3 & 45.10  & 0.7483(4)  & 47.52  & 0.8156(2) & 46.55 & 0.8595(1) & 0.8078(46) \\
 C & 4 & 60.15  & 0.6498(1)  & 59.72  & 0.6469(1) & 58.99 & 0.6380(1) & 0.6449(50) \\
\bottomrule
\end{tabular*}
\end{table}

\end{document}

答案3

还有另一种布局,带有siunitx, booktabs,multirowxcolor

\documentclass{article}
\usepackage[svgnames, table]{xcolor}
\usepackage{geometry}
\usepackage{tabularx, caption, multirow, booktabs} 
\usepackage{siunitx} 
\newcolumntype{U}{S[table-format=1.4, separate-uncertainty, table-figures-uncertainty=1]}

\begin{document}

\begin{table}
\sisetup{table-format=2.2, table-number-alignment=center}
\setlength{\tabcolsep}{5pt}
\centering\small
\caption{A Table}\label{tab:1}
\begin{tabular}
{@{\,}l S[table-format =1.1]*{3}{SU}S[table-format=1.4, separate-uncertainty, table-figures-uncertainty=3]@{\,}}
A & {B} & {C} & {D} & {E} & {F} & {G} & {H} & {I} \\[1ex]
\arrayrulecolor{SteelBlue} \toprule[1.5pt]
    & 0.7 & 12.22 & 1.932(1) & 12.46 & 1.826(2) & 12.090 & 2.027(1) & 1.920(82)\\
  A & 2 & 30.55 & 1.279(1) & 28.26 & 1.341(1) & 30.44 & 1.318(1) & 1.312(26) \\
    & 3 & 44.22 & 0.8494(4) & 37.34 & 0.8886(2)& 37.91 & 0.8857(5) & 0.8746(179) \\
\arrayrulecolor{WhiteSmoke!80! SteelBlue}\cmidrule[3pt]{2-9}
   & 0.7 & 11.75 & 1.906(1) & 11.35 & 1.885(1) & 11.64 & 1.891(1) & 1.894(9) \\
 B & 3 & 46.94 & 0.8352(3) & 45.70 & 0.8807(3) & 46.96 & 0.8417(2) & 0.8586(201) \\
  & 4 & 61,23 & 0.5590(2) & 61.83 & 0.5913(1) & 59.57 & 0.6298(1) & 0.5991(290) \\
\cmidrule[3pt]{2-9}
    & 0.7 & 11.27 & 1.828(2) & 11.03 & 1.806(1) & 11.40 & 1.841(1) & 1.825(14) \\
 \multirow{2}{*}{C} & 2 & 30.57 & 1.300(1) & 30.60 & 1.272(1) & 30.54 & 1.277(1) & 1.283(12) \\
  & 3 & 45.10 & 0.7483(4) & 47.52 & 0.8156(2) & 46.55 & 0.8595(1) & 0.8078(46) \\
  & 4 & 60.15 & 0.6498(1) & 59.72 & 0.6469(1) & 58.99 & 0.6380(1) & 0.6449(50) \\
\arrayrulecolor{SteelBlue}\bottomrule[1.5pt]
\end{tabular}
\end{table}

\end{document}

在此处输入图片描述

相关内容