1

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}
  • Please, provide complete code, which we can copy to our computers and compile. On the first look, you have strange construction of table: nested tables can't broke text onto more lines, so they overlap neighbored column(s). I'm afraid that for nice table settings you should edit each separately. – Zarko Jul 2 '16 at 8:42
  • 1
    Rule of thumb: Don't use a table generator, they can be helpful, but often they produce something like you see above: A pretty crappy result. – Johannes_B Jul 2 '16 at 8:49
  • This is the complete code - I just copied and pasted it from latex table generator website along with custom text and columns widths. – robjob27 Jul 2 '16 at 8:50
  • And thanks for the responses, I guess I'll have to create 100 tables like this – robjob27 Jul 2 '16 at 8:50
2

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

I propose two solutions with tabularx, a sideways table, and another ‘normal’ table, in case it might make sense for the real tables, with much less horizontal lines and a simpler code, just swapping rows and columns:

        \documentclass{article}%
\usepackage{geometry}
 \usepackage{ragged2e}
  \usepackage{booktabs}
        \usepackage{tabularx, rotating, makecell, cellspace, caption}
        \usepackage{blindtext}
\setlength\cellspacetoplimit{4pt}
\setlength\cellspacebottomlimit{5pt}
\addparagraphcolumntypes{X}
\setcellgapes{3pt}
        \begin{document}

\begin{sidewaystable}[!htbp]
  \footnotesize\captionsetup{font =footnotesize}
  \renewcommand{\tabularxcolumn}[1]{>{\arraybackslash\RaggedRight}p{#1}}
  \centering\setlength\tabcolsep{4pt}
  \caption{My caption}
  \label{my-label}\makegapedcells
  \begin{tabularx}{\textheight}{| >{\hsize=0.7\hsize}X |*{3}{>{\hsize=0.98\hsize}X|}*{2}{>{\hsize=1.2\hsize}X|} *{2}{>{\hsize=0.98\hsize}X|}}
    \cline{1-8}
                              & \makecell{Event & & & & & & \\ Identification} & \makecell{NamedEntity\\ Recognition} & \makecell{Object\\ Identification} & \makecell{Predicate\\ Relationship-Ident.} & \makecell{Predicate\\ Relationship-Count} & \makecell{WSD-Ident.} & \makecell{WSD-Count}\\%
    \cline{1-8}
    Manual\newline annotation & Assault, detonated, suicide & 9:20 p.m. (time), Friday (day),\newline 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), \\ \cline{1-8}
  \end{tabularx}
\end{sidewaystable}
\newpage

\begin{table}[!ht]
  \footnotesize\captionsetup{font =footnotesize}
  \renewcommand{\tabularxcolumn}[1]{>{\arraybackslash\RaggedRight}p{#1}}
  \centering
  \caption{My caption}
  \label{my-label2}
  \begin{tabularx}{\linewidth}{|l|S{X}|}
    \hline
    \rule[-1.6cm]{0pt}{1.6cm} & Manual annotation \\%
    \hline
    Event Identification & Assault, detonated, suicide \\%
    NamedEntity Recognition & 9:20 p.m. (time), Friday (day),\newline one terrorist (N\_count), soccer (sports), Paris (City) \\%
    Object Identification & Their, Bomb, gates, stadium, outskirts \\%
    Predicate Relationship-Ident. & Assault(their, 9:20p.m., Friday, detonated), detonated (one terrorist, bomb, outside the gates), suicide(bomb) \\%
    Predicate Relationship-Count & Assault(4), detonated(), suicide(0) \\%
    WSD-Ident. & Assault(), detonated(), suicide() \\%
    WSD-Count & Assault(7), detonated(2), suicide(2), \\%
    \hline
  \end{tabularx}
\end{table}

\end{document} 

enter image description here enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.