LaTeX技巧653:如何隔開LaTeX表格鄰近\cline表格線?

原文鏈接:http://www.latexstudio.net/archives/700.html

LaTeX製作表格,若是需要做局部畫線的表格,會用到如下的命令\cline,示例如下:

                              

代碼如下:

\begin{tabular}{lrrrrrrr}
 \hline
 \multicolumn{2}{c}{level1} \multicolumn{2}{c}{level2} \multicolumn{2}{c}{level3} \\
  \cline{3-8}
 type & f1 & f2 & f3 & f4 & f5 & f6 & f7 \\ 
   \hline
 Section    & 2.3 & 2.288 & 0.009 &  1.779 & 0.008 & 0.338 & 2.1\\ 
   Period    & 2.8 & 3.309 & 0.002  &  4.060 & 0.000 & 0.866 & 2.3\\ 
   \hline
 \end{tabular}

若是我們需要的效果是:

                                  

用下面的代碼:

\begin{tabular}{lrrrrrrr}
 \hline
  &  & \multicolumn{2}{c}{level1} & \multicolumn{2}{c}{level2} & 
 \multicolumn{2}{c}{level3} \\
  \cline{3-4}  \cline{5-6} \cline{7-8}
 type & f1 & f2 & f3 & f4 & f5 & f6 & f7 \\ 
   \hline
 Section    & 2.3 & 2.288 & 0.009 &  1.779 & 0.008 & 0.338 & 2.1\\ 
   Period    & 2.8 & 3.309 & 0.002  &  4.060 & 0.000 & 0.866 & 2.3\\ 
   \hline
 \end{tabular}

顯示的效果仍舊是上面的表格效果。 【解決方案】 我們可以使用booktabs裏所提供的命令\cmidrule 命令,上面的效果實現的代碼如下:

 \begin{tabular}{lrrrrrrr}
 \hline
  &  & \multicolumn{2}{c}{level1} & \multicolumn{2}{c}{level2} & 
 \multicolumn{2}{c}{level3} \\
  \cmidrule(r){3-4}  \cmidrule(r){5-6} \cmidrule(r){7-8}
 \noalign{\smallskip} 
 type & f1 & f2 & f3 & f4 & f5 & f6 & f7 \\ 
   \hline
 Section    & 2.3 & 2.288 & 0.009 &  1.779 & 0.008 & 0.338 & 2.1\\ 
   Period    & 2.8 & 3.309 & 0.002  &  4.060 & 0.000 & 0.866 & 2.3\\ 
   \hline
 \end{tabular}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章