如何为数组添加标题?

如何为数组添加标题?

到目前为止,这就是我所得到的。

\usepackage{amsmath}
\usepackage{graphicx}
\usepackage[colorinlistoftodos]{todonotes}
\usepackage[colorlinks=true, allcolors=blue]{hyperref}
\usepackage[square]{natbib}
\usepackage{amssymb}
\usepackage{float}
\usepackage{caption}
\usepackage{appendix}
\frenchspacing
 $\begin{array}{  l  l  l  l  l  }
 & Stage & ln\_labor & ln\_hours & p(emp) \\ \hline\hline
\text{Currently living in urban areas}  & 1st & 0.21482 & 0.13242 & 0.19161 \\ 
 & 2nd & -0.09168 & -0.06626 & -0.16811 \\ \hline
\text{Lived in a state capital when aged 15} & 1st & 0.47462 & 0.63929^{*} & 0.95309^{**} \\ 
 & 2nd & 0.04447 & 0.11124 & -0.08064 \\ \hline
\text{Lived in urban area when aged 15} & 1st & 0.65694^{**} & 0.57415^{**} & 0.60316^{*} \\ 
 & 2nd & 0.24461^{**} & 0.15895 & -0.08445 \\ \hline
\text{Currently living in urban areas}  & 1st & 0.01835 & 0.02033 & 0.01678 \\ 
 & 2nd & -1.198 & -0.54056 & -1.7587 \\ \hline
\text{Lived in a state capital when aged 15} & 1st & 0.04432 & 0.0328 & 0.0331 \\ 
 & 2nd & 1.822 & 2.263 & 0.01657 \\ \hline
\text{Lived in urban area when aged 15} & 1st & 0.09357^{**} & 0.08919^{**} & 0.09271^{***} \\ 
 & 2nd & 1.775^{**} & 1.1184 & -0.26679 \\ 
\caption{$*$ for significant at $10\%$, $**$ for significance at $5\%$ and $***$ for significance at $1\%$}

\end{array}
$

我收到此错误信息:

Package caption Error: \caption outside float.

See the caption package documentation for explanation.
Type  H <return>  for immediate help.
 ...                                              

l.15 \caption
             {$*$ for significant at $10\%$, $**$ for significance at $5\%$ ...

那么我该怎么办?

答案1

例如table可以添加环境:

\begin{table}
  \caption{...}
  $\begin{array}{...}
    ...
  \end{array}$
\end{table}

答案2

首先,caption通常插入到浮点环境中,如tablefigure。在这里,table似乎更正确。其次,虽然内容主要是文本,但您使用了array而不是,请切换到。第三,为了更好地对齐数字,请使用包在小数点周围对齐数字。最后,使用可以大大提高可读性,在不同行之间添加小空格,。 tabulartabulardcolumnbooktabs\addlinespace

\documentclass[12pt,a4paper]{article}
\usepackage{amsmath}
\usepackage{graphicx}
\usepackage[colorinlistoftodos]{todonotes}
\usepackage[colorlinks=true, allcolors=blue]{hyperref}
\usepackage[square]{natbib}
\usepackage{amssymb}
\usepackage{float}
\usepackage{booktabs}
\usepackage{dcolumn} 
\frenchspacing

\begin{document}

\begin{table}\centering
\caption{$^*$for significant at 10\%, $^{**}$for significance at 5\% and $^{***}$for significance at $1\%$}\par\medskip
\begin{tabular}{ @{} l l *3{D{.}{.}{6}} }
\toprule
 & Stage & \multicolumn{1}{c}{ln\_labor} & \multicolumn{1}{c}{ln\_hours} & \multicolumn{1}{c}{p(emp)} \\ \midrule
Currently living in urban areas  & 1\textsuperscript{st} & 0.21482 & 0.13242 & 0.19161 \\ 
 & 2\textsuperscript{nd} & -0.09168 & -0.06626 & -0.16811 \\ \addlinespace
Lived in a state capital when aged 15 & 1\textsuperscript{st} & 0.47462 & 0.63929^{*} & 0.95309^{**} \\ 
 & 2\textsuperscript{nd} & 0.04447 & 0.11124 & -0.08064 \\ \addlinespace
Lived in urban area when aged 15 & 1\textsuperscript{st} & 0.65694^{**} & 0.57415^{**} & 0.60316^{*} \\ 
 & 2\textsuperscript{nd} & 0.24461^{**} & 0.15895 & -0.08445 \\ \addlinespace
Currently living in urban areas  & 1\textsuperscript{st} & 0.01835 & 0.02033 & 0.01678 \\ 
 & 2\textsuperscript{nd} & -1.198 & -0.54056 & -1.7587 \\ \addlinespace
Lived in a state capital when aged 15 & 1\textsuperscript{st} & 0.04432 & 0.0328 & 0.0331 \\ 
 & 2\textsuperscript{nd} & 1.822 & 2.263 & 0.01657 \\ \addlinespace
Lived in urban area when aged 15 & 1\textsuperscript{st} & 0.09357^{**} & 0.08919^{**} & 0.09271^{***} \\ 
 & 2\textsuperscript{nd} & 1.775^{**} & 1.1184 & -0.26679 \\ \bottomrule
\end{tabular}
\end{table}

\end{document}

在此处输入图片描述

相关内容