如何将表格的第一行分成两行

如何将表格的第一行分成两行

我想将第一行的文本分成两行,这样我的表格就会显示在 A4 纸上。我该怎么做?

我想使用 p{dimen} 以外的命令

\begin{tabular}{|l|l|l|l|}
\hline
\multicolumn{1}{|c|}{the speeding rate} & \multicolumn{1}{c|}{speed by applying the algorithm} & \multicolumn{1}{c|}{speed without applying the algorithm} & \multicolumn{1}   {c|}{Improvement of the speed} \\
\hline
\multicolumn{1}{|c|}{57} & \multicolumn{1}{c|}{777} & \multicolumn{1}{c|}{8777} &     \multicolumn{1}{c|}{1} \\
\hline
\multicolumn{1}{|c|}{10} & \multicolumn{1}{c|}{86} & \multicolumn{1}{c|}{80} &   \multicolumn{1}{c|}{5} \\
\hline
\multicolumn{1}{|c|}{7} & \multicolumn{1}{c|}{2} & \multicolumn{1}{c|}{12} &   \multicolumn{1}{c|}{9} \\
\hline
\end{tabular}

答案1

您可以使用p{<dimen>}适当的列说明符<dimen>。或者使用tabularx或自行将标题放在两行中。

\documentclass[a4paper]{article}
\begin{document}
  \begin{tabular}{|l|l|l|l|}
\hline
\multicolumn{1}{|p{1.5cm}|}{speeding rate} & \multicolumn{1}{p{2.8cm}|}{\raggedright speed by applying the algorithm} & \multicolumn{1}{p{3.5cm}|}{\raggedright speed without applying the algorithm} & \multicolumn{1}   {p{2.6cm}|}{\raggedright Improvement of the speed} \\
\hline
\multicolumn{1}{|c|}{57} & \multicolumn{1}{c|}{777} & \multicolumn{1}{c|}{8777} &     \multicolumn{1}{c|}{1} \\
\hline
\multicolumn{1}{|c|}{10} & \multicolumn{1}{c|}{86} & \multicolumn{1}{c|}{80} &   \multicolumn{1}{c|}{5} \\
\hline
\multicolumn{1}{|c|}{7} & \multicolumn{1}{c|}{2} & \multicolumn{1}{c|}{12} &   \multicolumn{1}{c|}{9} \\
\hline
\end{tabular} 
\end{document}

在此处输入图片描述

适当调整内部尺寸等。此外,您还可以使用以下方法p{2.5cm}减少列间空间:@{}

\multicolumn{1}{|p{1.5cm}@{}|}{speeding rate} & \multicolumn{1}{p{2.8cm}@{}|}{\raggedright speed by applying the algorithm} & \multicolumn{1}{p{3.5cm}@{}|}{\raggedright speed without applying the algorithm} & \multicolumn{1}   {p{2.6cm}@{}|}{\raggedright Improvement of the speed} \\
\hline

tabularx

\documentclass[a4paper]{article}
\usepackage{tabularx}
\begin{document}
  \begin{tabularx}{\linewidth}{*{5}{|c}}
\hline
\multicolumn{1}{|X|} {\raggedright speeding rate} &  \multicolumn{1}{X|} {\raggedright speed by applying the algorithm} & \multicolumn{1}{X|} {\raggedright speed without applying the algorithm} & \multicolumn{1}{X|} {\raggedright Improvement of the speed} \\
\hline
57 & 777 & 8777 &  1 \\
\hline
10 & 86 & 80 &   5 \\
\hline
7 & 2 & 12 &  9 \\
\hline
\end{tabularx}
\end{document}

通过暴力破解:

\documentclass[a4paper]{article}
\begin{document}
  \begin{tabular}{*{5}{|c}}
\hline
\multicolumn{1}{|l|} {speeding}  & \multicolumn{1}{l|} {speed by applying} &  \multicolumn{1}{l|} {speed without applying} &  \multicolumn{1}{l|} {Improvement} \\
 \multicolumn{1}{|l|} {rate} &   \multicolumn{1}{l|} {the algorithm} &  \multicolumn{1}{l|} {the algorithm} &  \multicolumn{1}{l|} {of the speed} \\
\hline
57 & 777 & 8777 &  1 \\
\hline
10 & 86 & 80 &   5 \\
\hline
7 & 2 & 12 &  9 \\
\hline
\end{tabular}
\end{document}

在此处输入图片描述

带包装且不带垂直线看起来怎么样booktabs?我喜欢的方式如下:

\documentclass[a4paper]{article}
\usepackage{booktabs}
\begin{document}
  \begin{tabular}{*{5}{c}}
\toprule
\multicolumn{1}{l} {speeding}  & \multicolumn{1}{l} {speed by applying} &  \multicolumn{1}{l} {speed without applying} &  \multicolumn{1}{l} {Improvement} \\
 \multicolumn{1}{l} {rate} &   \multicolumn{1}{l} {the algorithm} &  \multicolumn{1}{l} {the algorithm} &  \multicolumn{1}{l} {of the speed} \\
\midrule
57 & 777 & 8777 &  1 \\
10 & 86 & 80 &   5 \\
7 & 2 & 12 &  9 \\
\bottomrule
\end{tabular}
\end{document}

在此处输入图片描述

答案2

表格可能是表格的一个元素,因此您可以在您的位置写入the speeding rate例如

\begin{tabular}{l}
the speeding\\
rate
\end{tabular}

(手指交叉)。

相关内容