在已允许文本换行的表格中换行并逐项列出

在已允许文本换行的表格中换行并逐项列出

已加载的软件包和代码如下:

\documentclass[12pt]{report}
 \usepackage{array,ltablex, makecell}%
\renewcommand\theadfont{\normalsize\bfseries}
% \renewcommand*\descriptionlabel[1]{\hspace\leftmargin$#1$}%This is for descriptions to appear on the LHS with an indent
\newenvironment{conditions}
 {\par\vspace{\abovedisplayskip}\noindent\begin{tabular}{>{$}l<{$} @{${}={}$} l}}
 {\end{tabular}\par\vspace{\belowdisplayskip}}%This is for descriptions of equations
\usepackage[]{multirow}%Essential for cells in table spanning multiple rows
\usepackage[autostyle]{csquotes}% This is for quotes
\usepackage{tabulary}% This is for tables
\usepackage{longtable,array,ragged2e}% This is formatting for long tables
\usepackage{tabularx,caption}
\newcolumntype{L}[1]{>
{\raggedright\let\newline\\\arraybackslash\hspace{0pt}}p{#1}}%This is a wrapper to make everything a certain width -left aligned columns with stuff at the top.
\newcolumntype{U}{>{\raggedright\arraybackslash\hspace{0pt}}X}%This is a wrapper to make everything a certain width -left aligned columns with stuff at the top.
\newcolumntype{C}[1]{>{\centering\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}%C is for central aligned columns and middle aligned.
\newcolumntype{Y}{>{\centering\arraybackslash\hspace{0pt}}X}%C is for central aligned columns and middle aligned.
\newcolumntype{R}[1]{>{\raggedleft\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
% \newcommand{\specialcell}[2][c]{\begin{tabular}[#1]{@{}c@{}}#2\end{tabular}}%This is to force new lines in cells
\usepackage{graphicx}% This is for images
\usepackage{booktabs,dcolumn,caption}
\newcommand{\ra}[1]{\renewcommand{\arraystretch}{#1}}%This is for precision tables per property
%

\begin{table}[!ht]
 \small
 \caption{Freebase Relation Example}
 \centering
\begin{tabular}{|p{3.25cm}|p{3.25cm}|}
\toprule
\textbf{Entity-Pair} & \textbf{<Barack Obama, US>} \\
\midrule
\multirow{2}{*}{Relation instances from knowledge bases} & 
1. \textbf{PresidentOf(Barack Obama, US)} \\ &
2. \textbf{BornIn(Barack Obama, US)} \\
\hline
\multirow{4}{*}{Relation mentions from free texts} & 1. \textbf{Barack Obama} is the 44th and current president of the \textbf{US} (PresidentOf) \\ &
2. \textbf{Barack Obama} ended \textbf{US} military involvement in the Iraq War. (*) \\ & 
3. \textbf{Barack Obama} was born in Honolulu, Hawaii, \textbf{US}. (BornIn) \\ &
4. \textbf{Barack Obama} ran for the \textbf{US} senate in 2004. (SenateOf) \\
\bottomrule
\end{tabular}
\end{table}

我正在尝试重新创建:

在此处输入图片描述

但是 a) 我无法itemize在这种tabular环境中执行此操作,并且 b) 第一列没有将我的文本换行到我指定的固定宽度 3.25 厘米。

当前表:

在此处输入图片描述

答案1

输出

在此处输入图片描述

代码

\documentclass{article}
\usepackage{booktabs}
\usepackage{tabularx}
\usepackage{caption}
\usepackage{enumitem}
\usepackage[table]{xcolor}

\begin{document}

\begin{table}[!ht]
  \setenumerate{noitemsep}% Removes spaces between items in list.
  \rowcolors{2}{white}{yellow!10}% This will color every even row. use \rowcolor{color} if you only want to color a single row.
  \small
  \caption{Freebase Relation Example}
  \centering
  \renewcommand{\tabularxcolumn}[1]{m{#1}}% To have tabularx use the m-columntype instead of p, so that we can center the content virtically
  \begin{tabularx}{\textwidth}{>{\centering}m{3.25cm}X}
    \toprule
    \textbf{Entity-Pair} & \multicolumn{1}{c}{\textbf{\textless Barack Obama, US\textgreater}} \\
    \midrule
      Relation instances

      from

      knowledge bases &%
      % \vspace*{-\topsep}\vspace*{-\parsep}%
      \begin{enumerate}
        \item \textbf{PresidentOf(Barack Obama, US)}
        \item \textbf{PresidentOf(Barack Obama, US)}
      \end{enumerate}\\
      \midrule
      Relation mentions

      from

      free texts &
      % \vspace*{-\topsep}\vspace*{-\parsep}%To remove space from top of enumerate
      \begin{enumerate}
          \item \textbf{Barack Obama} is the 44th and current president of the \textbf{US} (President of)
          \item \textbf{Barack Obama} ended \textbf{US} military involvement in the Iraq War. (-)
          \item \textbf{Barack Obama} was born in Honolulu, Hawaii, \textbf{US}. (Born in)
          \item \textbf{Barack Obama} ran for the \textbf{US} senate in 2004. (Senate of)
        \end{enumerate}\\
      \bottomrule
  \end{tabularx}
\end{table}


\end{document}

答案2

虽然您可以在 中指定环境(\center, \raggedright\newcolumntype,但您也可以使用 指定特定于单元格的环境minipage。然后您可以在其中插入图像、列表甚至子表!

\documentclass[english]{article}
\usepackage{booktabs}
\begin{document}

\begin{tabular}{lllll}
\toprule
ColA & ColB & ColC & ColD & ColE \\ 
\midrule
Left (year) & Left & Left & \begin{minipage}[b]{0.10\textwidth}\raggedleft
Right 
\end{minipage} & Left \\ 
\bottomrule
\end{tabular}

\end{document}

具有特定于单元格的小页面环境的示例表

相关内容