LaTex 表格问题

来源:互联网 发布:mac vmware tools 编辑:程序博客网 时间:2024/05/16 10:29

表格问题1************************************************************************

合并表格后,合并单元格的下面三行不能平均分配列,如图所示:


源代码是:

\begin{table}[htbp]\centering  \begin{tabular}{|l|c|c|c|c|c|c|}   \hline   \multirow{2}{*}{\textbf{Model}} & \multicolumn{3}{|c|}{\textbf{Trigger Boundary(\%)}} & \multicolumn{3}{|c|}{\textbf{Trigger Boundary + Type(\%)}} \\   \cline{2-7}    & P & R & F & P & R & F \\   \hline    \textit{Single-word} & 55 & 55 & 55 & 55 &  55 & 55 \\   \hline    \textit{Multi-word} & 55 & 55 & 55 & 55 & 55 & 55\\   \hline    \textit{All} & 55 & 55 & 55 & 55 & 55 & 55 \\   \hline\end{tabular}\caption{Number of words in triggers}\label{event:triggerNum}\end{table}

表格宽度分配不均匀,所以需要指定列的宽度,代码如下:

\begin{table}[htbp]\centering \begin{tabular}{|p{2cm}|p{1cm}|p{1cm}|p{1cm}|p{1.2cm}|p{1.2cm}<{\centering}|p{1.2cm}<{\centering}|}   \hline   \multirow{2}{*}{\textbf{Model}} & \multicolumn{3}{|c|}{\textbf{Trigger Boundary(\%)}} & \multicolumn{3}{|c|}{\textbf{Trigger Boundary + Type(\%)}} \\   \cline{2-7}    & P & R & F & P & R & F \\   \hline    \textit{Single-word} & 55 & 55 & 55 & 55 &  55 & 55 \\   \hline    \textit{Multi-word} & 55 & 55 & 55 & 55 & 55 & 55\\   \hline    \textit{All} & 55 & 55 & 55 & 55 & 55 & 55 \\   \hline\end{tabular}\caption{Number of words in triggers}\label{event:triggerNum}\end{table}

代码运行后的结果是:


由此又产生了另外一个问题,即单元格中的文字没有句中:

需要将代码改为:

 \begin{tabular}{|p{3cm}<{\centering}|p{1cm}<{\centering}|p{1cm}<{\centering}|p{1cm}<{\centering}|p{1.2cm}<{\centering}|p{1.2cm}<{\centering}|p{1.2cm}<{\centering}|}

问题完美解决。

表格问题2********************************************************


\begin{tabular}{@{}>{\sf }lcclcclcc@{}}\toprule & \multicolumn{2}{c}{\bf Specific Heats} &  & \multicolumn{2}{c}{\bf Specific Heats}  &  & \multicolumn{2}{c}{\bf Specific Heats} \\  \cmidrule{2-3} \cmidrule{5-6} \cmidrule{8-9}& $c$  &  $C$ &   & $q$  &  $Q$ &  & $e$  &  $E$ \\\midruleAluminum     & 900  & 24.3 & & 900  & 24.3 & & 900  & 24.3 \\Copper       & 385  & 24.4 & & 900  & 24.3 & & 900  & 24.3 \\Gold         & 130  & 25.6 & & 900  & 24.3 & & 900  & 24.3 \\Steel/Iron   & 450  & 25.0 & & 900  & 24.3 & & 900  & 24.3 \\Lead         & 130  & 26.8 & & 900  & 24.3 & & 900  & 24.3 \\Mercury      & 140  & 28.0 & & 900  & 24.3 & & 900  & 24.3 \\Water        & 4190 & 75.4 & & 900  & 24.3 & & 900  & 24.3 \\Ice          & 2100 & 38   & & 900  & 24.3 & & 900  & 24.3 \\\bottomrule\end{tabular}

效果如果显示:


此处再给出一个复杂点的表格源码:


\begin{table*}\newcommand{\tabincell}[2]{\begin{tabular}{@{}#1@{}}#2\end{tabular}}\small\begin{tabular}{|p{2cm}<{\centering}|p{2cm}<{\centering}|p{2cm}<{\centering}|p{2cm}<{\centering}|p{2cm}<{\centering}|p{2cm}<{\centering}|p{2cm}<{\centering}|}\hline\multirow{2}{*}{\centering \tabincell{l}{trigger \\types}} & \multicolumn{3}{|c|}{one-word Noum$F(\%)$} & \multicolumn{3}{|c|}{one-word and multi-word Noum$F(\%)$}\\  \cline{2-4}\cline{5-7} & common feature & \tabincell{l}{common + \\unique \\feature} & \tabincell{l}{common+\\qunique+\\global \\feature} & \tabincell{l}{common \\feature} & \tabincell{l}{common + \\unique \\feature} & \tabincell{l}{common+\\unique+\\global\\ feature}\\\hlinePho       & 900 & 900 & 900 & 900 & 900 & 900 \\Gen & 385 & 900 & 900 & 900 & 900 & 900 \\Tra     & 130 & 900 & 900 & 900 & 900 & 900 \\Loc      & 450 & 900 & 900 & 900 & 900 & 900 \\Cat      & 130 & 900 & 900 & 900 & 900 & 900 \\Bin   & 140 & 900 & 900 & 900 & 900 & 900 \\Reg      & 419 & 900 & 900 & 900 & 900 & 900 \\Pos  & 210 & 900 & 900 & 900 & 900 & 900 \\Neg  & 210 & 900 & 900 & 900 & 900 & 900 \\\hlineOverall   & 210 & 900 & 900 & 900 & 900 & 900 \\\hline\end{tabular}\caption{different feature compare}\label{diffFeatureCompare}\end{table*}



可以使用 diagbox 宏包,基本语法格式是:
\diagbox[选项]{左}{右}
\diagbox[选项]{左}{中}{右}
\diagbox[dir=⟨方向⟩]{A}{B}
这个表头可以由以下命令实现:
\diagbox[dir=SE]{A}{B}{C}
调用宏包后,直接把上面命令放在 tabular 环境里的对应位置即可。

0 0
原创粉丝点击