我尝试使用以下代码创建表格(Crosstabulation),但它给出了一个我不明白的错误。我对 Tex 还比较陌生,如果有人能帮助我,我将不胜感激。
\begin{frame}
\frametitle{Association: discrete case}
\begin{table}[h]\footnotesize
\begin{tabular}{lccc}
\hline
\textbf{Account Size} / \textbf{Recommendation} & No(=0) & Yes(=1) & Row Total \\
\hline
Large(=3) & 34 & 18 & 52 \\
& 0.654 & 0.346 & 0.406 \\
& 0.493 & 0.305 & \\
& 0.266 & 0.141 & \\
\hline
Medium(=2) & 22 & 23 & 45 \\
& 0.489 & 0.511 & 0.352 \\
& 0.319 & 0.390 & \\
& 0.172 & 0.180 & \\
\hline
Small(=1) & 13 & 18 & 31 \\
& 0.419 & 0.581 & 0.242 \\
& 0.188 & 0.305 & \\
& 0.102 & 0.141 & \\
\hline
Column Total & 69 & 59 & 128 \\
& 0.539 & 0.461 &
\hline
\end{tabular}
\end{table}
\end{frame}
答案1
这是我的建议:除了添加缺失的,我还用包中的线条\\
替换了水平s ,添加是为了改善数字的对齐,并用于在第一列的长标题中引入换行符。通过这些更改,您甚至可以将 fnt 大小增加到 ,而表格仍然适合。\hline
booktabs
siunitx
makecell
\small
beamer
frame
\documentclass{beamer}
\usepackage{makecell}
\usepackage{siunitx}
\usepackage{booktabs}
\begin{document}
\begin{frame}
\frametitle{Association: discrete case}
\begin{table}[h]\small
\begin{tabular}{l*{2}{S[table-format=2.3]}S[table-format=3.3]}
\toprule
\makecell[lc]{Account Size /\\ Recommendation} & {No(=0)} & {Yes(=1)} & {Row Total} \\
\midrule
Large(=3) & 34 & 18 & 52 \\
& 0.654 & 0.346 & 0.406 \\
& 0.493 & 0.305 & \\
& 0.266 & 0.141 & \\
\midrule
Medium(=2) & 22 & 23 & 45 \\
& 0.489 & 0.511 & 0.352 \\
& 0.319 & 0.390 & \\
& 0.172 & 0.180 & \\
\midrule
Small(=1) & 13 & 18 & 31 \\
& 0.419 & 0.581 & 0.242 \\
& 0.188 & 0.305 & \\
& 0.102 & 0.141 & \\
\midrule
Column Total & 69 & 59 & 128 \\
& 0.539 & 0.461 & \\
\bottomrule
\end{tabular}
\end{table}
\end{frame}
\end{document}
答案2
\begin{table}[h]\footnotesize
\begin{tabular}{lSSS}
\hline
{\textbf{Account Size} / \textbf{Recommendation}} & {No(=0)} & {Yes(=1)} & {Row Total} \\
\hline
Large(=3) & 34 & 18 & 52 \\
& 0.654 & 0.346 & 0.406 \\
& 0.493 & 0.305 & \\
& 0.266 & 0.141 & \\
\hline
Medium(=2) & 22 & 23 & 45 \\
& 0.489 & 0.511 & 0.352 \\
& 0.319 & 0.390 & \\
& 0.172 & 0.180 & \\
\hline
Small(=1) & 13 & 18 & 31 \\
& 0.419 & 0.581 & 0.242 \\
& 0.188 & 0.305 & \\
& 0.102 & 0.141 & \\
\hline
Column Total & 69 & 59 & 128 \\
& 0.539 & 0.461 &\\
\hline
\end{tabular}
\end{table}