与此非常相似问题但不完全准确。
我正在写一篇论文,我想创建一个以树形保存信息的表格。我能够将表格放入页面内,但我希望它与该页面上的文本具有相同的边距。请看下图,我的表格是什么样的:
我编写的创建它的代码如下:
\begin{table}[H]
\centering
\begin{tabular}{|l|l|l|l|}
\hline
\multicolumn{1}{|c|}{Premise 1} & \multicolumn{1}{c|}{Premise 2} & \multicolumn{1}{c|}{=\textgreater} & \multicolumn{1}{c|}{hypothesis} \\ \hline
\texttt{\small [are:VX [?Y:NN [both:DT]} & \texttt{\small [?Y:NN [?X:JJ]} & & \texttt{\small [are:VX [?Y:NN [both:DT]} \\
\hspace*{7.4em}\texttt{\small [?X:JJ]]} & \hspace*{3.5em}\texttt{\small [are:VX [who:WP]} & $\Rightarrow$ & \hspace*{7.4em}\texttt{\small [?X:JJ]]} \\
\hspace*{3.8em}\texttt{\small [?Z:JJ]]} & \hspace*{7.6em}\texttt{\small [?Z:JJ]} & & \hspace*{3.8em}\texttt{\small [?A:JJ]]} \\
& \hspace*{7.2em}\texttt{\small [are:VX[?A:JJ]]]]} & & \\ \hline
\end{tabular}
\caption{The dependency tree for a multi-premise FraCaS rule}
\label{showDTreeFraCaS}
\end{table}
有什么线索吗?
答案1
您只需稍微缩小表格,使其符合您需要的比例即可。由于您已经使用了\centering
,因此您不必担心表格在页面中的比例位置。它会自动居中。
以下是我为您提供的解决方案:
\begin{table}[H]
\centering
\scalebox{.8}{
\begin{tabular}{|l|l|l|l|}
\hline
\multicolumn{1}{|c|}{Premise 1} & \multicolumn{1}{c|}{Premise 2} & \multicolumn{1}{c|}{=\textgreater} & \multicolumn{1}{c|}{hypothesis} \\ \hline
\texttt{\small [are:VX [?Y:NN [both:DT]} & \texttt{\small [?Y:NN [?X:JJ]} & & \texttt{\small [are:VX [?Y:NN [both:DT]} \\
\hspace*{7.4em}\texttt{\small [?X:JJ]]} & \hspace*{3.5em}\texttt{\small [are:VX [who:WP]} & $\Rightarrow$ & \hspace*{7.4em}\texttt{\small [?X:JJ]]} \\
\hspace*{3.8em}\texttt{\small [?Z:JJ]]} & \hspace*{7.6em}\texttt{\small [?Z:JJ]} & & \hspace*{3.8em}\texttt{\small [?A:JJ]]} \\
& \hspace*{7.2em}\texttt{\small [are:VX[?A:JJ]]]]} & & \\ \hline
\end{tabular}
}
\caption{The dependency tree for a multi-premise FraCaS rule}
\label{showDTreeFraCaS}
\end{table}
得出下表:
\scalebox{.8}{}帮助您将环境缩小到所需的大小。
答案2
为了确保表格内容适合文本块的宽度,我建议您使用环境tabularx
并将\small
指令更改为\footnotesize
。 完成这些修改后,唯一的手动调整就是将最后一行的缩进量从 更改7.2em
为3.7em
。
\documentclass{article}
\usepackage{tabularx}
\begin{document}
\begin{table}
\setlength\extrarowheight{1pt}
\footnotesize
\setlength\tabcolsep{3pt} % default: 6pt
\begin{tabularx}{\textwidth}{|X|X|c|X|}
\hline
\multicolumn{1}{|c|}{Premise 1} &
\multicolumn{1}{c|}{Premise 2} &
$\Rightarrow$ &
\multicolumn{1}{c|}{Hypothesis} \\
\hline
\texttt{[are:VX [?Y:NN [both:DT]} &
\texttt{[?Y:NN [?X:JJ]} & &
\texttt{[are:VX [?Y:NN [both:DT]} \\
\hspace*{7.4em}\texttt{[?X:JJ]]} &
\hspace*{2.9em}\texttt{[are:VX [who:WP]} &
$\Rightarrow$ &
\hspace*{7.4em}\texttt{[?X:JJ]]} \\
\hspace*{3.4em}\texttt{[?Z:JJ]]} &
\hspace*{7.6em}\texttt{[?Z:JJ]} & &
\hspace*{3.8em}\texttt{[?A:JJ]]} \\
&
\hspace*{3.7em}\texttt{[are:VX[?A:JJ]]]]} & & \\
\hline
\end{tabularx}
\caption{The dependency tree for a multi-premise FraCaS rule}
\label{showDTreeFraCaS}
\end{table}
\end{document}