具有不同宽度和行的表格

具有不同宽度和行的表格

我正在使用以下代码来编写表格

   \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} 

在此处输入图片描述

相关内容