我正在使用以下代码来编写表格
\documentclass[11pt, fullscreen=true, bookmarks=false]{beamer}
\usepackage[utf8x]{inputenc}
%\usepackage[T2A]{fontenc}
\usepackage{beamerthemesplit}
\usetheme{Berlin}
\usepackage[english]{babel}
\usepackage{amssymb,amsfonts,amsmath,mathtext}
\usepackage{longtable}
\usepackage{multirow}
\usepackage{booktabs,tabularx,ragged2e}
\newcolumntype{L}{>{\RaggedRight\arraybackslash}X}
\usepackage{ragged2e}
\renewcommand{\raggedright}{\leftskip=0pt \rightskip=0pt plus 0cm}
\begin{document}
$\begin{table}[h]
\begin{tabular}{lccl}
\hline
\multicolumn{1}{c}{}
& \multicolumn{2}{l}{Direction of Prior Stock Market Movement} & \\ \hline
\multicolumn{1}{c}{\begin{tabular}[c]{@{}c@{}}Incumbent Election\\ Result\end{tabular}} & \begin{tabular}[c]{@{}c@{}}Large\\ Positive\end{tabular} & \begin{tabular}[c]{@{}c@{}}Large \\ Negative\end{tabular} & Fisher's Exact Test \\ \hline
& \multicolumn{2}{c}{In Percentage Change:} & \\ \hline
Landslide Victory & 11 (73,3\%) & 0 (0\%) & \\ \hline
Landslide Loss & 1 (6,7\%) & 3 (20\%) & 0,009 \\ \hline
& \multicolumn{1}{l}{} & \multicolumn{1}{r}{} & \\ \hline
& \multicolumn{2}{c}{In Lognormal Transform:} & \\ \hline
Landslide Victory & 9 (75,0\%) & 0 (0\%) & \\ \hline
Landslide Loss & 0 (0\%) & 3 (25,0\%) & \multicolumn{1}{c}{0,005} \\ \hline
& \multicolumn{1}{l}{} & \multicolumn{1}{l}{} & \\ \hline
\end{tabular}
\end{table}
\end{document}
但是我得到的结果与我想要的不同,而且我无法将表格安装到幻灯片上。我希望表格看起来像这样:
我的代码有什么问题?可以改进吗?非常感谢!
答案1
您可以使用makecell
包来让 l、r 或 c 类型的单元格接受\\
,并使用\addlinespace
命令来booktabs
改善垂直间距。实际上,您加载了 booktabs 但没有使用它。这是一个更简单的代码;我删除了此表所有不必要的包:
\documentclass[11pt, fullscreen=true, bookmarks=false]{beamer}
\usepackage[utf8x]{inputenc}
%\usepackage[T2A]{fontenc}
\usepackage{beamerthemesplit}
\usetheme{Berlin}
\usepackage[english]{babel}
\usepackage{multirow}
\usepackage{booktabs}
\usepackage{caption}
\usepackage{makecell}
\begin{document}
\begin{table}[h]
\begin{tabular}{@{}lccc@{}}
\toprule
& \multicolumn{2}{c}{\makecell{Direction of Prior Stock\\ Market Movement}} \\
\cmidrule{2-3}
\makecell{Incumbent Election\\ Result} & \makecell{Large\\ Positive} & \makecell{Large \\ Negative} & Fisher's Exact Test \\
\midrule
\addlinespace[1.5ex]
\multicolumn{4}{c}{In Percentage Change:} \\
\midrule
Landslide Victory & 11 (73,3\,\%) & 0 (0\,\%) & \\
\addlinespace[0.5ex]
Landslide Loss & 1 (6,7\%) & 3 (20\%) & 0,009 \\
\midrule
\addlinespace[1.5ex]
\multicolumn{4}{c}{In Lognormal Transform:} \\
\midrule
Landslide Victory & 9 (75,0\%) & 0 (0\%) & \\
\addlinespace[0.5ex]
Landslide Loss & 0 (0\%) & 3 (25,0\%) & \multicolumn{1}{c}{0,005} \\
\bottomrule
\end{tabular}
\caption{The Market Romance}
\end{table}
\end{document}