当我运行此代码时,TexMaker 显示一条错误消息,指出第一行“\begin{table}[!htbp]\centering”导致问题。任何见解都值得赞赏。
\begin{table}[!htbp] \centering
\caption{Descriptive Statistics - Bangladesh 1991}
\label{}
\begin{tabular}{@{\extracolsep{5pt}}lccccc}
\\[-1.8ex]\hline
\hline \\[-1.8ex]
Statistic & \multicolumn{1}{c}{N} & \multicolumn{1}{c}{Mean} &
\multicolumn{1}{c}{St. Dev.} & \multicolumn{1}{c}{Min} & \multicolumn{1
{c}{Max} \\
\hline \\[-1.8ex]
Consumption & 826 & 4,163.1 & 2,167.9 & 1,352.5 & 27,447.7 \\
Age (Years) & 826 & 40.8 & 12.0 & 18 & 75 \\
Education (Years) & 826 & 1.0 & 0.2 & 0 & 1 \\
Sex & 826 & 2.4 & 3.3 & 0 & 16 \\
Household Land (Decimals) & 826 & 81.0 & 246.8 & 0.2 & 4,618.0 \\
\hline \\[-1.8ex]
\multicolumn{6}{l}{Figures reference a 1991 study on 826 households in
Bangladesh.} \\
\multicolumn{6}{l}{Full data set includes 24 variables on information at
the} \\
\multicolumn{6}{l}{household (head's education, land ownership,
expenditure, etc.)} \\
\multicolumn{6}{l}{and village (infastructure, price information of the
main consumer} \\
\multicolumn{6}{l}{goods, etc.) levels.} \\
\end{tabular}
\end{table}
答案1
欢迎来到 TeX.SX。正如 @Torbjørn 指出的那样,错误是由于缺少括号造成的。
您的桌子在尺寸和对齐方面存在一些挑战。人们有不同的偏好和实现所需解决方案的方式。
以下内容可能有助于您实现最终的期望结果。整个示例中都有注释来解释代码的作用。您还可以阅读“LATEX2ε 中的表格:包和方法”。
\documentclass[12pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage{booktabs} % for toprule, midrule and bottomrule
\usepackage{siunitx} % for alignment of numbers in columns
\usepackage{adjustbox}
\sisetup{
group-minimum-digits = {3}, % use this so that the comma is placed when number are thousands
group-separator = {,} % the thousands separator is a comma
}
\begin{document}
\begin{table}[htb] \centering
\caption{Descriptive Statistics - Bangladesh 1991}
\label{}
\begin{adjustbox}{width=\linewidth} %this sets the table within the line with of the page
\begin{tabular}{
@{\extracolsep{15pt}} % extra spacing between columns. adjust according to preference.
l % first column is left aligned
S[table-format=3.0] %second column, 3 integers, no decimals
*3{S[table-format=4.1]} %3rd, 4th & 5th columns, 4 integers, 1 decimal
S[table-format=5.1] % 6th column, 5 integers, 1 decimal
@{}
}
\toprule
Statistic & {N} & {Mean} & {St. Dev.} & {Min} & {Max} \\ % protect the headings in braces to avoid siunitx typesetting them
\midrule
Consumption & 826 & 4163.1 & 2167.9 & 1352.5 & 27447.7 \\
Age (Years) & 826 & 40.8 & 12.0 & 18 & 75 \\
Education (Years) & 826 & 1.0 & 0.2 & 0 & 1 \\
Sex & 826 & 2.4 & 3.3 & 0 & 16 \\
Household Land (Decimals) & 826 & 81.0 & 246.8 & 0.2 & 4618.0 \\
\bottomrule
\end{tabular}
\end{adjustbox} % end of adjustbox
\end{table}
\noindent Figures reference a 1991 study on 826 households in Bangladesh. Full data set includes 24 variables on information at household (head's education, land ownership, expenditure, etc.) and village (infrastructure, price information of the main consumer goods, etc.) levels.
\end{document}