表格中单元格外的文本

表格中单元格外的文本

我正在尝试使用 latex 创建一个表 - 更具体地说,latex 表生成器(http://www.tablesgenerator.com/) 因为我有大量来自 MS powerpoint 的表格想要导入,而且我认为单独复制和粘贴表格是目前最有效的。

无论如何,我有一个想要在下面导入的表格。

在此处输入图片描述

这里的问题是,列的宽度是我想要的,但正如您所看到的,文本溢出到了相邻的单元格。有人有什么建议可以解决这个问题吗?我也想过修改行高,但我不太清楚如何自动调整行高,因为有些表格可能在不同的行中有更多或更少的文本。无论如何,我会很感激的,谢谢!

下面是我用来生成该表的代码,如果可能的话,我不想使用外部包,因为我对 latex 很陌生,而且我不想使用外部包来配置文档(我正在使用提供给我的模板)。

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

答案1

第一个也是最重要的一点:不要使用http://www.tablesgenerator.com/——至少对于应允许单元格内换行的表格来说是这样。

进一步观察:

  • 指定允许换行的列类型( ),然后使用不允许换行的列p类型()覆盖每个单元格的设置,这确实是没有意义的。l

  • 由于列非常窄,完全对齐的结果肯定不令人满意。最好使用右对齐,同时允许使用连字符。

  • 通篇使用\tiny字体大小或多或少会导致内容无法阅读,除非有额外的放大镜。考虑使用\scriptsize或(更好)\footnotesize

  • 看在上帝的份上,把所有的 都替换\cline{1-8}\hline

以下截图展示了两个实现这些想法的表格。第一个使用 footnotesize,第二个使用 scriptsize。

在此处输入图片描述

\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

我提出了两种解决方案tabularx,一个是侧向表,另一个是“普通”表,以防它对真实的表有意义,水平线更少,代码更简单,只需交换行和列:

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

在此处输入图片描述 在此处输入图片描述

相关内容