# Multicolumn Table with Merged Cells

I am having great trouble producing the table that I have attached to this post. The difficulty I am having is firstly fitting the table on the page as it is very wide and also getting the merging of the columns done correctly. I would like to columns to expand to fit the text.

Even when I try to build the table piece by piece I am falling down on the basics. Any help would be greatly appreciated. Also I don't mind if the text is shrunk so that the table can fit or if it is display in landscape mode. Thanks in advance.

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

• All you really need is another "c|". The resulting tabular is 8.05 inches wide. Aug 15 '15 at 18:55
• @JohnKormylo, thanks. Is it possible to put this in normal mode (ie not landscape mode) but have the table shrunk so that it fits the width of the page? if I take out the sideways option, it overflows.
– user81633
Aug 15 '15 at 19:34

I propose two solutions based on tabularx, using a smaller font, and a smaller value for \tabcolsep. One is with vertical rules, the other only with horizontal rules, and the booktabs package. Also loading geometry provides more sensible margins:

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