【650】LaTeX表格合并实现

LaTex制作表格之合并单元格

latex 表格如何精细控制行高,行距,行与行之间的距离

Latex 表格 行合并,列合并,控制行间距 单元格宽度

Tables Generator

  在制作LaTex表格的时候,常常需要合并行和列,本文介绍的是使用 multirow 包里面的命令完成合并行列的方法。

  需要先导入以下库:

usepackage{multirow}

  举例:

egin{table*}
%usepackage{multirow}
center
egin{tabular}{|c|c|c|c|c|}
  hline % horizontal line
  multirow{2}{*}{1 & 2} & multicolumn{2}{l|}{ 3 & 4 } & 5 & 6\ %end line
  cline{2-5} %short partial horizontal lines from column 2 to column 5
   & 7 & 8 & 9 & 10\ %first cell is occupied by the multirow
  hline
  hline
  $ s_{1} $ & 2 & 3 & 4 & 5\
  $ s_{2} $ & 2 & 3 & 4 & 5\
  hline
  hline
  $ s_{3} $ & 2 & 3 & 4 & 5\ 
  $ s_{4} $ & 2 & 3 & 4 & 5\
  hline
end{tabular}
end{table*}

  效果 

egin{table}[h]
    caption{Optimization summary.}
    label{tab:summary}
    egin{tabular}{cccc}
        	oprule
        multirow{2}{*}{Design} & multicolumn{2}{c}{Problem size} & multirow{2}{*}{CPU time(s)} \
        cline{2-3}
        & Binary variables & Constraints\
        midrule
        OM1 & 199 & 13,017 & 000 \
        OM2 & 199 & 1,525 & 000 \
        ottomrule
    end{tabular}
    label{tab:my_label}
end{table}

  效果(后面有改进版)

  举例:

egin{table}[h]
    caption{Optimization summary.}
    centering
    vspace{2mm}
    egin{tabular}{ccccccccc}
        	oprule
        multirow{2}{*}{Model Name} & multicolumn{4}{c}{Building Roof} & multicolumn{4}{c}{Building}\
        cline{2-9}
        & Precision & Recall & $F_1$ & IoU & Precision & Recall & $F_1$ & IoU\
        midrule
        FCN-8s cite{long2015fully}             & 69.83   & 69.83   & 69.83   & 69.83    & 69.83   & 69.83    & 69.83   & 69.83\
        U-Net cite{ronneberger2015u}           & 69.83   & 69.83   & 69.83   & 69.83    & 69.83   & 69.83    & 69.83   & 69.83\
        Res-U-Net cite{xu2018building}         & 69.83   & 69.83   & 69.83   & 69.83    & 69.83   & 69.83    & 69.83   & 69.83\
        SegNet cite{badrinarayanan2017segnet}  & 69.83   & 69.83   & 69.83   & 69.83    & 69.83   & 69.83    & 69.83   & 69.83\
        DeepLabV3+ cite{chen2018encoder}       & 69.83   & 69.83   & 69.83   & 69.83    & 69.83   & 69.83    & 69.83   & 69.83\
        DeConvNet cite{noh2015learning}        & 69.83   & 69.83   & 69.83   & 69.83    & 69.83   & 69.83    & 69.83   & 69.83\
        Our Model                               & 69.83   & 69.83   & 69.83   & 69.83    & 69.83   & 69.83    & 69.83   & 69.83\
        ottomrule
    end{tabular}
    label{tab:my_label}
end{table}

  效果:

上面表格的问题在于两行标题栏距离太近,通过下面解决,也可以参考网站 https://www.tablesgenerator.com (Booktabs table style)

修改代码:

% Please add the following required packages to your document preamble:
% usepackage{booktabs}
% usepackage{multirow}

egin{table}[h]
    caption{Optimization summary.}
    label{tab:summary}
    egin{tabular}{cccc}
        	oprule
        multirow{2}{*}{Design} & multicolumn{2}{c}{Problem size} & multirow{2}{*}{CPU time(s)} \
        cmidrule{2-3}
        & Binary variables & Constraints\
        midrule
        OM1 & 199 & 13,017 & 78.7 \
        OM2 & 199 & 1,525 & 13.8 \
        ottomrule
    end{tabular}
    label{tab:my_label}
end{table}

 效果:(更协调了一些,目前最优

  • toprule:最上面的线(粗)
  • cmidrule:标题中间的线(细)
  • midrule:中间的线(中)
  • bottomrule:最下面的线(粗)

 

  添加表格注释,参考:Latex如何在表格下方显示注脚_小白皮皮-程序员宅基地_latex 表格下方注释

  导入以下库:

usepackage{threeparttable}

  举例:

egin{table}[h]
    centering
    caption{Quantitative comparison of four conventionally used metrics obtained from the segmentation results by FCN-8s, U-Net, Res-U-Net, SegNet, DeepLabV3+, DeConvNet, and the proposed model, where the values in bold format are the highest numbers for corresponding metrics.}
    
    vspace{2mm}
    egin{threeparttable} % 增加部分
    egin{tabular}{ccccccccc}
        	oprule
        multirow{2}{*}{Model Name} & multicolumn{4}{c}{Building Roof} & multicolumn{4}{c}{Building}\
        cline{2-9}
        & Precision & Recall & $F_1$ & IoU & Precision & Recall & $F_1$ & IoU\
        midrule
        FCN-8s cite{long2015fully}             & 69.83   & 69.83   & 69.83   & 69.83    & 69.83   & 69.83    & 69.83   & 69.83\
        U-Net cite{ronneberger2015u}           & 69.83   & 69.83   & 69.83   & 69.83    & 69.83   & 69.83    & 69.83   & 69.83\
        Res-U-Net cite{xu2018building}         & 69.83   & 69.83   & 69.83   & 69.83    & 69.83   & 69.83    & 69.83   & 69.83\
        SegNet cite{badrinarayanan2017segnet}  & 69.83   & 69.83   & 69.83   & 69.83    & 69.83   & 69.83    & 69.83   & 69.83\
        DeepLabV3+ cite{chen2018encoder}       & 69.83   & 69.83   & 69.83   & 69.83    & 69.83   & 69.83    & 69.83   & 69.83\
        DeConvNet cite{noh2015learning}        & 69.83   & 69.83   & 69.83   & 69.83    & 69.83   & 69.83    & 69.83   & 69.83\
        Our Model                               & 69.83   & 69.83   & 69.83   & 69.83    & 69.83   & 69.83    & 69.83   & 69.83\
        ottomrule
    end{tabular}
    label{tab:my_label}
    egin{tablenotes}  %增加部分
		item The bolded numbers indicate the largest number in the column, easier to find out which one performs better in this format.
     end{tablenotes}  %增加部分
    end{threeparttable}  %增加部分
end{table}

   效果:

原文地址:https://www.cnblogs.com/alex-bn-lee/p/15200982.html