我是 Latex 的初学者,我搜索了整个互联网,但找不到可用于创建下表的代码。有谁知道更简单的方法吗?
答案1
这里有两个您可以开始使用的 MWE。
在我推荐的示例 1 中,我使用了标题、书标并且无垂直线。
示例 2 是您的这个示例的复制品。但是,我使用了固定宽度的列,以确保中间的六列大致具有相同的宽度。
示例 1 – booktabs 规则
\documentclass{article}
\usepackage{array, tabularx, booktabs}
\usepackage{geometry}
\usepackage[bf, font=bf]{caption}
\setlength{\extrarowheight}{1pt}
\renewcommand{\arraystretch}{1.2}
\setlength{\tabcolsep}{0.0em}
\begin{document}
\begin{table}
\small
\caption{Some key infant indicators in sub-Saharan Africa and other EHO regions}
\begin{tabular*}{\textwidth}{@{\extracolsep{\fill}}wl{3cm}*{6}{wc{1.3cm}}c}
\toprule
\bfseries Country &
\multicolumn{3}{c}{\bfseries Neonatal mortality rate*} &
\multicolumn{3}{c}{\bfseries Infant mortality rate*} &
\bfseries Low birthweight \\
\midrule
& 2009 & 2012 & 2016 & 2009 & 2012 & 2016 & 2007—2016\\
\midrule
\bfseries Malawi & 30 & 24 & 23 & 69 & 46 & 42 & 12 \\
Zambai & 29 & 29 & 23 & 86 & 46 & 42 & 11 \\
Zimbabwe & 30.5 & 27.8 & 22 & 58 & 48 & 38 & 11 \\
Botswana & 22 & 29 & 26 & 43 & 41 & 33 & 13 \\
Kenya & 27 & 27 & 23 & 55 & 49 & 36 & 8 \\
\midrule
\bfseries
WHO region & & & & & & & \\
African & 36 & 32 & 28 & 80 & 63 & 53 & 14 \\
America & 9 & 8 & 4 & 15 & 13 & 5 & 8 \\
Europe & 7 & 6 & 2 & 12 & 10 & 3 & 7 \\
Asia & 31 & 27 & 28 & 45 & 39 & 39 & 30 \\
\bottomrule
\multicolumn{6}{@{}l}{\small \emph{Source} Malawi data ans World Bank Development Indicators (2015)}\\\addlinespace[-1ex]
\multicolumn{6}{@{}l}{\footnotesize \emph{Note: *per 1000 live births }}\\
\end{tabular*}
\end{table}
\end{document}
示例 2 – 类似单词
\documentclass{article}
\usepackage{array}
\usepackage{geometry}
\usepackage[bf, font=bf, hang]{caption}
\setlength{\extrarowheight}{1pt}
\renewcommand{\arraystretch}{1.2}
\setlength{\tabcolsep}{0.3em}
\begin{document}
\begin{table}
\caption{Some key infant indicators in sub-Saharan Africa and other EHO regions}
\begin{tabular}{wl{2.4cm}|*{6}{wc{1.3cm}|}wc{2cm}}
\hline
\bfseries Country & \multicolumn{3}{c|}{\bfseries Neonatal mortality rate*} & \multicolumn{3}{c|}{\bfseries Infant mortality rate*} & \multicolumn{1}{c}{\bfseries Low birthweight} \\
\hline
& \multicolumn{1}{c}{2009} & \multicolumn{1}{c}{2012} & \multicolumn{1}{c|}{2016}
& \multicolumn{1}{c}{2009} & \multicolumn{1}{c}{2012} & \multicolumn{1}{c|}{2016}
& 2007-2016\\
\hline
\bfseries Malawi & 30 & 24 & 23 & 69 & 46 & 42 & 12 \\\hline
Zambai & 29 & 29 & 23 & 86 & 46 & 42 & 11 \\\hline
Zimbabwe & 30.5 & 27.8 & 22 & 58 & 48 & 38 & 11 \\\hline
Botswana & 22 & 29 & 26 & 43 & 41 & 33 & 13 \\\hline
Kenya & 27 & 27 & 23 & 55 & 49 & 36 & 8 \\
\hline
\bfseries
WHO region & & & & & & & \\
African & 36 & 32 & 28 & 80 & 63 & 53 & 14 \\
America & 9 & 8 & 4 & 15 & 13 & 5 & 8 \\
Europe & 7 & 6 & 2 & 12 & 10 & 3 & 7 \\
Asia & 31 & 27 & 28 & 45 & 39 & 39 & 30 \\
\hline
\multicolumn{6}{@{}l}{\small \emph{Source} Malawi data ans World Bank Development Indicators (2015)}\\\addlinespace[-1ex]
\multicolumn{6}{@{}l}{\footnotesize \emph{Note: *per 1000 live births }}\\
\end{tabular}
\end{table}
\end{document}
答案2
您可以使用http://www.tablesgenerator.com/。我认为这是最简单的方法。
编辑:您可以从 Microsoft Excel 粘贴现有表格,或导入 CSV 文件。然后您会立即获得一个可用作起点的 latex 代码。例如,对于上面的表格,将生成下表。
\begin{table}[]
\centering
\caption{Some key infant indicators in sub-Saharan Africa and other WHO regions}
\label{tab:my-table}
\resizebox{\textwidth}{!}{%
\begin{tabular}{@{}lccccccc@{}}
\toprule
\multicolumn{1}{c}{\multirow{2}{*}{Country}} & \multicolumn{3}{c}{\textbf{Neonatal mortality rate*}} & \multicolumn{3}{c|}{\textbf{Infant mortality rate*}} & \textbf{Low birthweight} \\ \cmidrule(l){2-8}
\multicolumn{1}{c}{} & 2009 & 2012 & \multicolumn{1}{c|}{2016} & 2009 & 2012 & \multicolumn{1}{c|}{2016} & 2007-2016 \\ \midrule
\multicolumn{1}{l|}{\textbf{Malawi}} & \textbf{30} & \textbf{24} & \multicolumn{1}{c|}{\textbf{23}} & \textbf{69} & \textbf{46} & \multicolumn{1}{c|}{\textbf{42}} & \textbf{12} \\
\multicolumn{1}{l|}{Zambia} & 29 & 29 & \multicolumn{1}{c|}{23} & 86 & 56 & \multicolumn{1}{c|}{44} & 11 \\
\multicolumn{1}{l|}{Zimbabwe} & 30.5 & 27.8 & \multicolumn{1}{c|}{22} & 58 & 48 & \multicolumn{1}{c|}{38} & 11 \\
\multicolumn{1}{l|}{Botswana} & 22 & 29 & \multicolumn{1}{c|}{26} & 43 & 41 & \multicolumn{1}{c|}{33} & 13 \\
\multicolumn{1}{l|}{Kenya} & 27 & 27 & \multicolumn{1}{c|}{23} & 55 & 49 & \multicolumn{1}{c|}{36} & 8 \\ \midrule
\multicolumn{8}{l}{\textbf{WHO region}} \\
\multicolumn{1}{l|}{African} & 36 & 32 & \multicolumn{1}{c|}{28} & 80 & 63 & \multicolumn{1}{c|}{53} & 14 \\
\multicolumn{1}{l|}{America} & 9 & 8 & \multicolumn{1}{c|}{4} & 15 & 13 & \multicolumn{1}{c|}{5} & 8 \\
\multicolumn{1}{l|}{Europe} & 7 & 6 & \multicolumn{1}{c|}{2} & 12 & 10 & \multicolumn{1}{c|}{3} & 7 \\
\multicolumn{1}{l|}{Asia} & 31 & 27 & \multicolumn{1}{c|}{28} & 45 & 39 & \multicolumn{1}{c|}{39} & 30 \\ \midrule
\multicolumn{8}{l}{\begin{tabular}[c]{@{}l@{}}Source: Malawi data ans World Bank Development Indicators (2015)\\ Note: *per 1000 live births\end{tabular}}
\end{tabular}%
}
\end{table}