请帮忙,我正在尝试创建一个多列表,但没有任何进展。我想要两列,女性和男性,下面有非正式、正式和总计,如图所示。这是我的代码,但输出不是我想要的。谢谢。
\documentclass[a4paper,12pt]{book}
\usepackage{amsmath}
\usepackage{bm}
\pagestyle{plain}
\usepackage{setspace}
\raggedbottom
\usepackage{mathtools}
\usepackage{longtable}
\usepackage{booktabs}
\usepackage{multirow}
\usepackage{array, booktabs, ragged2e}
\usepackage{threeparttablex}
{\renewcommand*{\arraystretch}{1.5}
\begin{spacing}{.85}
\begin{ThreePartTable}
\begin{TableNotes}
\footnotesize
\item [a] Data source: SLLFS 2014
\item [b] Percentage values in the table are percentages of the number of women (xxxx) and men (xxxx) in the sample
\end{TableNotes}
\begin{longtable}{p{1ex}>{\RaggedRight}p{1.95cm}*{3}{p{1.45cm}p{2cm}}}
\caption{Characteristics of study sample by job type and gender\tnote{a}}\label{chap1:tab1}\\\toprule
\endfirsthead
\multicolumn{7}{p{4cm}} {Table 1 (\emph{continued})}\\ \toprule
& & \multicolumn{2}{l}{Female} & \multicolumn{2}{l}{Male} & \\
\cmidrule{3-4} \cmidrule(lr){5-6} \cmidrule{7-8}
& & Informal & Formal & Total & Informal & Formal & Total \\\midrule
\endhead
\hline\multicolumn{7}{r}{\tablename\ \thetable\ -- \textit{Continued on next page}} \\
\endfoot
\hline
\insertTableNotes % tell LaTeX where to insert the contents of "TableNotes"
\endlastfoot
& & \multicolumn{2}{l}{Female} & \multicolumn{2}{l}{Male} &\\
\cmidrule{3-4} \cmidrule(lr){5-6} \cmidrule{7-8}
& & Informal & Formal & Total & Informal & Formal & Total \\\midrule
\multicolumn{2}{l}{\textit{Age}} & \\
& 15-24 & 663 & 20.994 & 19 & 5.791 & 682 & 20.019\\
& 25-34 & 1071 & 32.091 & 114 & 37.959 & 1185 & 32.383\\
& 35-44 & 866 & 23.826 & 86 & 28.394 & 952 & 24.053\\
& 45-54 & 530 & 15.416 & 58 & 18.217 & 588 & 15.555\\
& 55-64 & 251 & 7.721 & 29 & 9.636 & 280 & 7.816\\
\bottomrule
\end{longtable}
\end{ThreePartTable}
\end{spacing}
}
答案1
大部分内容与主题无关:
- 表格内容不一致且不清楚。它是否包含小数或
.
组分隔符? - 哪一列包含百分比?
- 列标题的代码不一致
- 该包
mathtools
也已加载amsmath
,因此无需再次加载 - 每个包裹仅装载一次即可
\renewcommand*{\arraystretch}{1.5}
和 的使用\begin{spacing}{.85}
不清楚。仅使用 还不够吗\renewcommand*{\arraystretch}{1.2}
?- 对于最后六列,我建议使用
S
包提供的列类型siunitx
。它可以更好地对齐数字(小数点处)
(红线表示文本边框)
\documentclass[a4paper,12pt]{book}
\usepackage{mathtools} % not used in this mwe
\usepackage{bm} % not used in this mwe
\usepackage{setspace} % not used in this mwe
\raggedbottom
\usepackage{siunitx} % new
\usepackage{ragged2e}
\usepackage{array, booktabs, longtable,
multirow, threeparttablex}
%---------------- show page layout. don't use in a real document!
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%
\begin{document}
\pagestyle{plain}
\begin{ThreePartTable}
\begin{TableNotes}\footnotesize
\item [a] Data source: SLLFS 2014
\item [b] Percentage values in the table are percentages of the number of women (xxxx) and men (xxxx) in the sample
\end{TableNotes}
\renewcommand*{\arraystretch}{1.2}
\setlength{\LTcapwidth}{\linewidth} % that caption width is equal table width
\setlength\LTleft{0pt}
\setlength\LTright{0pt}
\setlength\tabcolsep{5pt}
\begin{longtable}{@{\extracolsep{\fill}}
p{1ex}
>{\RaggedRight}p{3cm}
S[table-format=4.0]
S[table-format=2.3]
S[table-format=3.0]
S[table-format=2.3]
S[table-format=4.0]
S[table-format=2.3]
} \caption{Characteristics of study sample by job type and gender\tnote{a}}
\label{chap1:tab1}\\
\toprule
& & \multicolumn{3}{c}{Female} & \multicolumn{3}{c}{Male} \\
\cmidrule(r){3-5}
\cmidrule(l){6-8}
& & {Informal} & {Formal} & {Total} & {Informal} & {Formal} & {Total} \\
\midrule
\endfirsthead
\caption{Characteristics of study sample by job type and gender (\textit{continued})}\\
\toprule
& & \multicolumn{3}{c}{Female} & \multicolumn{3}{c}{Male} \\
\cmidrule(r){3-5}
\cmidrule(l){6-8}
& & {Informal} & {Formal} & {Total} & {Informal} & {Formal} & {Total} \\
\midrule
\endhead
\midrule
\multicolumn{8}{r}{\textit{Continued on the next page}} \\
\endfoot
\bottomrule
\insertTableNotes % tell LaTeX where to insert the contents of "TableNotes"
\endlastfoot
\multicolumn{2}{l}{\textit{Age}}
& & & & & & \\
& 15-24 & 663 & 20.994 & 19 & 5.791 & 682 & 20.019 \\
& 25-34 & 1071 & 32.091 & 114 & 37.959 & 1185 & 32.383 \\
& 35-44 & 866 & 23.826 & 86 & 28.394 & 952 & 24.053 \\
& 45-54 & 530 & 15.416 & 58 & 18.217 & 588 & 15.555 \\
& 55-64 & 251 & 7.721 & 29 & 9.636 & 280 & 7.816 \\
\multicolumn{2}{l}{\textit{Education}}
& & & & & & \\
& Primary or less
& 2789 & 88.027 & 51 & 17.534 & 2840 & 84.439 \\
\end{longtable}
\end{ThreePartTable}
\end{document}
答案2
我将\multicolumn{2}{l}{Female}
其改为\multicolumn{3}{l}{Female}
(与 相同{Male}
)并删除了尾随的&
。还将cmidrule
s 更改为适当的宽度。在这种情况下,\cmidrule(lr){3-5}
和\cmidrule(l){6-8}
可以解决问题。
\documentclass[a4paper,12pt]{book}
\usepackage{amsmath}
\usepackage{bm}
\pagestyle{plain}
\usepackage{setspace}
\raggedbottom
\usepackage{mathtools}
\usepackage{longtable}
\usepackage{booktabs}
\usepackage{multirow}
\usepackage{array, booktabs, ragged2e}
\usepackage{threeparttablex}
\begin{document}
{\renewcommand*{\arraystretch}{1.5}
\begin{spacing}{.85}
\begin{ThreePartTable}
\begin{TableNotes}
\footnotesize
\item [a] Data source: SLLFS 2014
\item [b] Percentage values in the table are percentages of the number of women (xxxx) and men (xxxx) in the sample
\end{TableNotes}
\begin{longtable}{p{1ex}>{\RaggedRight}p{1.95cm}*{3}{p{1.45cm}p{2cm}}}
\caption{Characteristics of study sample by job type and gender\tnote{a}}\label{chap1:tab1}\\\toprule
\endfirsthead
\multicolumn{7}{p{4cm}} {Table 1 (\emph{continued})}\\
\toprule
& & \multicolumn{3}{l}{Female} & \multicolumn{3}{l}{Male}\\
\cmidrule(lr){3-5} \cmidrule(l){6-8}
& & Informal & Formal & Total & Informal & Formal & Total\\
\midrule
\endhead
\hline\multicolumn{7}{r}{\tablename\ \thetable\ -- \textit{Continued on next page}} \\
\endfoot
\hline
\insertTableNotes % tell LaTeX where to insert the contents of "TableNotes"
\endlastfoot
& & \multicolumn{3}{l}{Female} & \multicolumn{3}{l}{Male}\\
\cmidrule(lr){3-5} \cmidrule(l){6-8}
& & Informal & Formal & Total & Informal & Formal & Total\\
\midrule
\multicolumn{2}{l}{\textit{Age}} &\\
& 15-24 & 663 & 20.994 & 19 & 5.791 & 682 & 20.019\\
& 25-34 & 1071 & 32.091 & 114 & 37.959 & 1185 & 32.383\\
& 35-44 & 866 & 23.826 & 86 & 28.394 & 952 & 24.053\\
& 45-54 & 530 & 15.416 & 58 & 18.217 & 588 & 15.555\\
& 55-64 & 251 & 7.721 & 29 & 9.636 & 280 & 7.816\\
\bottomrule
\end{longtable}
\end{ThreePartTable}
\end{spacing}
}
\end{document}
答案3
我建议这样做,使用siunitx
小数点对齐数字。另外,我不明白使用spacing
表格环境的意义何在,因为\arraystretch
可以使用特定于表格的命令:
\documentclass[a4paper,12pt]{book}
\usepackage[utf8]{inputenc}
\usepackage{mathtools}
\usepackage{bm}
\pagestyle{plain}
\raggedbottom
\usepackage{longtable}
\usepackage{booktabs}
\usepackage{multirow}
\usepackage{array, siunitx, ragged2e}%
\usepackage{threeparttablex}
\begin{document}
{\renewcommand*{\arraystretch}{1.25}
\sisetup{table-format=2.3, table-number-alignment=center}
\newcolumntype{N}{S[table-format=4.0]}
\setlength{\LTcapwidth}{\linewidth}
\begin{ThreePartTable}
\begin{TableNotes}
\footnotesize
\item [a] Data source: SLLFS 2014
\item [b] Percentage values in the table are percentages of the number of women (xxxx) and men (xxxx) in the sample
\end{TableNotes}
\begin{longtable}{@{}p{1em}@{}c@{\hskip2pc}NSN@{\hskip3pc}SNS@{}}
\caption{Characteristics of study sample by job type and gender\tnote{a}}\label{chap1:tab1}\\
\toprule
& & \multicolumn{2}{c}{Female} & & \multicolumn{2}{c}{Male} \\
\cmidrule(r){3-4} \cmidrule(lr){6-7}
& & Informal & Formal & Total & Informal & Formal & Total \\
\midrule
\multicolumn{2}{@{}l}{\textit{Age}} & \\
\endfirsthead
\multicolumn{8}{l} {Table 1 (\emph{continued})}\\
\toprule
& & \multicolumn{2}{c}{Female} & & \multicolumn{2}{c}{Male} \\
\cmidrule{3-4} \cmidrule(lr){6-7}
& & Informal & Formal & Total & Informal & Formal & Total \\
\midrule
\multicolumn{2}{@{}l}{\textit{Age}} & \\
\endhead
\hline\multicolumn{8}{r}{\textit{Continued on next page}} \\
\endfoot
\bottomrule
\insertTableNotes % tell LaTeX where to insert the contents of "TableNotes"
\endlastfoot%
& 15-24 & 663 & 20.994 & 19 & 5.791 & 682 & 20.019\\
& 25-34 & 1071 & 32.091 & 114 & 37.959 & 1185 & 32.383\\
& 35-44 & 866 & 23.826 & 86 & 28.394 & 952 & 24.053\\
& 45-54 & 530 & 15.416 & 58 & 18.217 & 588 & 15.555\\
& 55-64 & 251 & 7.721 & 29 & 9.636 & 280 & 7.816
\end{longtable}
\end{ThreePartTable}
\end{document}