带合并单元格的多列表格

带合并单元格的多列表格

我在制作附在本帖中的表格时遇到了很大麻烦。我遇到的困难首先是表格太宽,无法适应页面,其次是无法正确合并列。我希望列能够扩展以适合文本。

即使我尝试逐块构建表格,我还是会忘记基本内容。任何帮助都将不胜感激。另外,我也不介意将文本缩小以适合表格,或者将其以横向模式显示。提前致谢。在此处输入图片描述

\documentclass[a4paper]{article}

\usepackage[english]{babel}
\usepackage[utf8x]{inputenc}
\usepackage{amsmath}
\usepackage{graphicx}
\usepackage[colorinlistoftodos]{todonotes}
\usepackage{rotating}

\title{Foo}

\begin{document}
\maketitle

\section{Analysis}

\begin{sidewaystable}[h]
\begin{tabular}{ |c|c|c|c|c|c|  }
  Event & No Cond & Top & Middle & Last & After Last & Top\\
  \hline
  New & Insert & Insert At Top & Split, Insert, Push down & Split, insert, push down & insert  &  Insert at top, push down    \\
  Delete       & -   & Delete at top & Split, delete, push up   & Split, insert, push up   & - & delete top, push down     \\
  Update       & -   & Update values & Update values            & Update values            & - & update values     \\
  \hline
\end{tabular}
\end{sidewaystable}
\section{Implementation}

\end{document}

答案1

我提出了两种基于 的解决方案tabularx,使用较小的字体和较小的 值\tabcolsep。一种是使用垂直规则,另一种是仅使用水平规则和booktabs包。此外,加载geometry提供了更合理的边距:

\documentclass[a4paper]{article}

\usepackage[english]{babel}
\usepackage[utf8x]{inputenc}
\usepackage{amsmath}
\usepackage{graphicx}
\usepackage[colorinlistoftodos]{todonotes}
\usepackage{rotating, tabularx, booktabs}
\renewcommand{\tabularxcolumn}[1]{>{\raggedright\arraybackslash}m{#1}}
\usepackage{geometry}
\usepackage{showframe}
\title{Foo}

\begin{document}
\maketitle

\section{Analysis}

\begin{table}[! ht]
  \setlength\tabcolsep{3pt}
  \begin{tabularx}{\linewidth}{|l|c|X|X|X|c|X| }
    \hline
    Event & No Cond & Top & Middle & Last & After Last & Top \\
    \hline
    New & Insert & Insert At Top & Split, insert, push down & Split, insert, push down & insert & Insert at top, push down \\[1ex]
    Delete & -- & Delete at top & Split, delete, push up & Split, insert, push up & -- & Delete top, push down \\[1.5ex]
    Update & -- & Update values & Update values & Update values & -- & Update values \\[1.5ex]
    \hline
  \end{tabularx}
\end{table}

\begin{table}[! ht]
  \setlength\tabcolsep{4pt}
  \begin{tabularx}{\linewidth}{@{}lcXXXcX @{}}
    \toprule
    Event & No Cond & Top & Middle & Last & After Last & Top \\
    \midrule
    New & Insert & Insert At Top & Split, insert, push down & Split, insert, push down & insert & Insert at top, push down \\
    \addlinespace
    Delete & -- & Delete at top & Split, delete, push up & Split, insert, push up & -- & Delete top, push down \\
    \addlinespace
    Update & -- & Update values & Update values & Update values & -- & Update values \\
    \bottomrule
  \end{tabularx}
\end{table}
\section{Implementation}

\end{document} 

在此处输入图片描述

相关内容