[Tex/LaTex] Text running off from cell in table

rotatingtables

I am trying to create a table using latex – more specifically, the latex table generator (http://www.tablesgenerator.com/) because I have tons of tables from MS powerpoint that I would like to import and I think copying and pasting tables individually is the most efficient as of now.

In any case, I have a table that I want to import below.

enter image description here

The problem here is that the width of the columns is what I want but as you can see, the text is spilling over to the neighboring cell. Does anyone have a suggestion to fix this? I was also thinking of modifying the row heights but I'm not too sure how to auto adjust the row height because some tables may have more or less text in different rows. Anyways, I would appreciate it, thanks!

The code that I used to generate this table is below and if possible, I would like to not use external packages as I'm very new to latex and I rather not deal with configuring the document with external packages (I'm using a template provided to me).

\documentclass{article}
\usepackage{rotfloat}

\begin{document}
\begin{sidewaystable}[]
\tiny
\centering
\caption{My caption}
\label{my-label}
\begin{tabular}{|p{1.5cm}|p{1.5cm}|p{2cm}|p{2cm}|p{2cm}|p{2cm}|p{2cm}|p{2cm}|}
\cline{1-8}
 & \begin{tabular}[c]{@{}l@{}}Event\\   Identification\end{tabular} & \begin{tabular}[c]{@{}l@{}}Named\\   Entity Recognition\end{tabular} & \begin{tabular}[c]{@{}l@{}}Object\\   Identification\end{tabular} & \begin{tabular}[c]{@{}l@{}}Predicate\\   Relationship - Ident.\end{tabular} & \begin{tabular}[c]{@{}l@{}}Predicate\\   Relationship - Count\end{tabular} & \begin{tabular}[c]{@{}l@{}}WSD\\   - Ident.\end{tabular} & \begin{tabular}[c]{@{}l@{}}WSD\\   - Count\end{tabular} &  \\ \cline{1-8}
\begin{tabular}[c]{@{}l@{}}Manual\\   annotation\end{tabular} & \begin{tabular}[c]{@{}l@{}}Assault,\\   detonated, suicide\end{tabular} & \begin{tabular}[c]{@{}l@{}}9:20\\   p.m. (time), Friday (day), one terrorist (N\_count), soccer (sports), Paris (City)\end{tabular} & \begin{tabular}[c]{@{}l@{}}Their,\\   Bomb, gates, stadium, outskirts\end{tabular} & \begin{tabular}[c]{@{}l@{}}Assault(their,\\   9:20p.m., Friday, detonated), detonated(one terrorist ,bomb, outside the\\   gates), suicide(bomb)\end{tabular} & \begin{tabular}[c]{@{}l@{}}Assault(4),\\   detonated(), suicide(0)\end{tabular} & \begin{tabular}[c]{@{}l@{}}Assault(),\\   detonated(), suicide()\end{tabular} & \begin{tabular}[c]{@{}l@{}}Assault(7),\\   detonated(2), suicide(2),\end{tabular} &  \\ \cline{1-8}
\end{tabular}
\end{sidewaystable}
\end{document}

Best Answer

The first and foremost take-away: Don't use http://www.tablesgenerator.com/ -- at least not for tables for which line wrapping within cells should be allowed.

Further observations:

  • It is truly pointless to specify column types (p) that allow line-wrapping but then to override that setting for each and every cell with a column type (l) that does not allow line-wrapping.

  • Since the columns are quite narrow, full justification must yield unsatisfactory results. Better to use ragged-right while allowing hyphenation.

  • Using a \tiny font size throughout more or less guarantees that the material will be unreadable, at least not unless extra magnifying glasses are made available. Consider using \scriptsize or (better still) \footnotesize instead.

  • For goodness' sake, replace all instances of \cline{1-8} with \hline.

The following screenshot shows two tables that implement these ideas. The first uses footnotesize, the second uses scriptsize.

enter image description here

\documentclass{article}
\usepackage{rotating,array,ragged2e,caption}
\newcolumntype{P}[1]{>{\RaggedRight\arraybackslash}p{#1}}
\begin{document}
\begin{sidewaystable}
\setlength\extrarowheight{2pt}
\setlength\tabcolsep{3pt} % default: 6pt
\centering

%% First, \footnotesize
\captionsetup{size=footnotesize}
\footnotesize

\caption{My caption -- footnotesize}
\label{my-label}
\begin{tabular}{|*{2}{P{1.5cm}|}*{7}{P{2.3cm}|}}
\hline
& Event Identification & Named Entity Recognition & Object Identification 
& Predicate Relationship -- Ident. & Predicate Relationship -- Count 
& WSD -- Ident. & WSD -- Count \\ 
\hline
Manual annotation & Assault, detonated, suicide & 9:20 p.m~(time), Friday (day), 
one terrorist (N\_count), soccer (sports), Paris (City) 
& Their, Bomb, gates, stadium, outskirts 
& Assault (their, 9:20p.m., Friday, detonated), detonated (one terrorist bomb 
outside the gates), 
suicide (bomb) 
& Assault (4), detonated(), suicide (0) & Assault (), detonated (), suicide () 
& Assault (7), detonated (2), suicide~(2), \\ 
\hline
\end{tabular}

\bigskip\bigskip
%% Second, \scriptsize
\captionsetup{size=scriptsize}
\scriptsize

\caption{My caption, scriptsize}
\label{my-label}
\begin{tabular}{|*{2}{P{1.5cm}|}*{7}{P{2.3cm}|}}
\hline
& Event Identification & Named Entity Recognition & Object Identification 
& Predicate Relationship -- Ident. & Predicate Relationship -- Count 
& WSD -- Ident. & WSD -- Count \\ 
\hline
Manual annotation & Assault, detonated, suicide & 9:20 p.m~(time), Friday (day), 
one terrorist (N\_count), soccer (sports), Paris (City) 
& Their, Bomb, gates, stadium, outskirts 
& Assault (their, 9:20p.m., Friday, detonated), detonated (one terrorist bomb 
outside the gates), 
suicide (bomb) 
& Assault (4), detonated(), suicide (0) & Assault (), detonated (), suicide () 
& Assault (7), detonated (2), suicide~(2), \\ 
\hline
\end{tabular}

\end{sidewaystable}
\end{document}