如何在表格中制作漂亮的垂直边框

如何在表格中制作漂亮的垂直边框

我想打印带有垂直线的表格。这是我目前拥有的:

% Preamble: \usepackage{multirow}
% \usepackage{booktabs}
\begin{table}[htbp]
\begin{tabular}{|c|ccccccccc|}
\toprule
& & \multicolumn{3}{c}{U-Net} & \multicolumn{3}{c}{FC-DenseNet} & \multicolumn{2}{c}{DeepLabv3+} \\
\cmidrule(r){3-5} \cmidrule(lr){6-8} \cmidrule(l){9-10}
& & 256 & 512 & 1024 & 256 & 512 & 1024 & 256 & 512\\
\cmidrule(r){3-10}
\multirow{2}{*}{\rotatebox[origin=c]{90}{U-Net}}        & \rotatebox[origin=c]{90}{512}  & 1 & & & & & & &\\[5pt]
                                                        & \rotatebox[origin=c]{90}{1024} & 1 & 1 & & & & & &\\[7pt]
\multirow{3}{*}{\rotatebox[origin=c]{90}{FC-DenseNet}}  & \rotatebox[origin=c]{90}{256}  & 0.1 & 1 & 1 & & & & &\\[5pt]
                                                        & \rotatebox[origin=c]{90}{512}  & 1 & 1 & 1 & 1 & & & &\\[5pt]
                                                        & \rotatebox[origin=c]{90}{1024} & \textless 0.001 & \textless 0.001 & \textless 0.001 & \textless 0.001 & \textless 0.001 & & &\\[7pt]
\multirow{3}{*}{\rotatebox[origin=c]{90}{DeepLabv3+}}   & \rotatebox[origin=c]{90}{256}  & 0.008 & 0.378 & 0.785 & 1 & 1 & \textless 0.001 & &\\[5pt]
                                                        & \rotatebox[origin=c]{90}{512}  & \textless 0.001 & 0.007 & 0.078 & 0.544 & 1 & \textless 0.001 & 0.569 &\\[5pt]
                                                        & \rotatebox[origin=c]{90}{1024} & 0.146 & 0.243 & 0.436 & 1 & 1 & \textless 0.001 & 1 & 1\\[5pt]
\bottomrule
\end{tabular}
\end{table}

生成此表: 当前表

您可能已经猜到我想要一个实心的外框。但最重要的是,我想要与左侧的标题具有相同的样式,即类似于表格\cmidrule但会在表格的多行中产生线条。

答案1

tabularray两种情况:

  • 前两列的文本被旋转
  • 旋转的文本仅在第一列中

\documentclass{article}
%--------------- show page layout. don't use in a real document!
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}

\usepackage{graphicx}
\usepackage{tabularray}
\UseTblrLibrary{booktabs}

\begin{document}
    \begin{table}[!ht]
\begin{tblr}{colspec= {|Q[c,m]|*{9}{X[c,m]}|},
             colsep=4pt
             }
    \toprule
    &   \SetCell[c=3]{c}  U-Net
        &   &   &   \SetCell[c=3]{c}  FC-DenseNet
                    &   \SetCell[c=2]{c}  DeepLabv3+
                        &                                   \\
    \cmidrule[r]{3-5} \cmidrule[lr]{6-8} \cmidrule[l]{9-10}
    &   & 256 & 512 & 1024 & 256 & 512 & 1024 & 256 & 512   \\
    \cmidrule{3-10}
\SetCell[r=2]{c}  \rotatebox[origin=c]{90}{U-Net}        
    & \rotatebox[origin=c]{90}{512}  
        & 1 & & & & & & &           \\
    & \rotatebox[origin=c]{90}{1024} 
        & 1 & 1 & & & & & &         \\
    \addlinespace
\SetCell[r=3]{c}    \rotatebox[origin=c]{90}{FC-DenseNet}
     & \rotatebox[origin=c]{90}{256}  
        & 0.1   & 1  & 1 & & & & &  \\
     & \rotatebox[origin=c]{90}{512}  
        & 1 & 1 & 1 & 1 & & & &     \\
     & \rotatebox[origin=c]{90}{1024} 
        & \textless 0.001 & \textless 0.001 & \textless 0.001 
        & \textless 0.001 & \textless 0.001 &   &   &   \\
    \addlinespace
\SetCell[r=3]{c}    \rotatebox[origin=c]{90}{DeepLabv3+}   
    & \rotatebox[origin=c]{90}{256}  
        & 0.008 & 0.378 & 0.785 & 1 & 1 & \textless 0.001 & &   \\
    & \rotatebox[origin=c]{90}{512}  
        & \textless 0.001 & 0.007 & 0.078 & 0.544 
        & 1 & \textless 0.001 & 0.569 &             \\
    & \rotatebox[origin=c]{90}{1024} 
        & 0.146 & 0.243 & 0.436 & 1 & 1 & \textless 0.001 & 1 & 1\\
    \bottomrule
\end{tblr}
    \end{table}
    \begin{table}[!ht]
\begin{tblr}{colspec = {|Q[c,m]|*{9}{X[c,m]}|},
              colsep = 4pt,
            row{3-Y} = {rowsep=0.5pt},
               vspan = even}
    \toprule
    &   &   \SetCell[c=3]{c}  U-Net
            &   &   &   \SetCell[c=3]{c}  FC-DenseNet
                        &   &   &   \SetCell[c=2]{c}  DeepLabv3+
                                    &                       \\
    \cmidrule[r]{3-5} \cmidrule[lr]{6-8} \cmidrule[l]{9-10}
    &   & 256 & 512 & 1024 & 256 & 512 & 1024 & 256 & 512   \\
    \cmidrule{3-10}
\SetCell[r=2]{c}  \rotatebox[origin=c]{90}{U-Net}
    & 512
        & 1 & & & & & & &           \\
    & 1024
        & 1 & 1 & & & & & &         \\
    \addlinespace
\SetCell[r=3]{c}    \rotatebox[origin=c]{90}{FC-DenseNet}
     & 256 
        & 0.1   & 1  & 1 & & & & &  \\
     & 512
        & 1 & 1 & 1 & 1 & & & &     \\
     & 1024
        & \textless 0.001 & \textless 0.001 & \textless 0.001
        & \textless 0.001 & \textless 0.001 &   &   &   \\
    \addlinespace
\SetCell[r=3]{c}    \rotatebox[origin=c]{90}{DeepLabv3+}
    & 256
        & 0.008 & 0.378 & 0.785 & 1 & 1 & \textless 0.001 & &   \\
    & 512
        & \textless 0.001 & 0.007 & 0.078 & 0.544
        & 1 & \textless 0.001 & 0.569 &             \\
    & 1024
        & 0.146 & 0.243 & 0.436 & 1 & 1 & \textless 0.001 & 1 & 1\\
    \bottomrule
\end{tblr}
    \end{table}
\end{document}

在此处输入图片描述

(红线显示页面布局)

答案2

如果中间的垂直线不重要,你可以在整体周围添加一个框架tabular

在此处输入图片描述

\documentclass{article}
\usepackage{booktabs}
\usepackage{rotating}
\usepackage{multirow}


\begin{document}
\begin{table}[htbp]
    \centering
    \setlength{\fboxrule}{\heavyrulewidth}
    \setlength{\fboxsep}{0pt}
    \fbox{%
        \begin{tabular}{*{10}{c}}
        \addlinespace[3pt]
        & & \multicolumn{3}{c}{U-Net}
            & \multicolumn{3}{c}{FC-DenseNet}
            & \multicolumn{2}{c}{DeepLabv3+} \\
        \cmidrule(r){3-5} \cmidrule(lr){6-8} \cmidrule(lr){9-10}
        & & 256 & 512 & 1024 & 256 & 512 & 1024 & 256 & 512\\
        \cmidrule(r){3-10}
        \multirow{2}{*}{\rotatebox[origin=c]{90}{U-Net}} & \rotatebox[origin=c]{90}{512}  & 1 &   &&&&&&\\[5pt] & \rotatebox[origin=c]{90}{1024} & 1 & 1 &&&&&&\\[7pt]
        \multirow{3}{*}{\rotatebox[origin=c]{90}{FC-DenseNet}} & \rotatebox[origin=c]{90}{256}  & 0.1 & 1 & 1 &   &&&&\\[5pt]
            & \rotatebox[origin=c]{90}{512}  & 1   & 1 & 1 & 1 &&&&\\[5pt]
            & \rotatebox[origin=c]{90}{1024} & \textless 0.001 & \textless 0.001 & \textless 0.001 & \textless 0.001 & \textless 0.001 & & &\\[7pt]
        \multirow{3}{*}{\rotatebox[origin=c]{90}{DeepLabv3+}}
            & \rotatebox[origin=c]{90}{256}  & 0.008 & 0.378 & 0.785 & 1 & 1 & \textless 0.001 & &\\[5pt]
            & \rotatebox[origin=c]{90}{512}  & \textless 0.001 & 0.007 & 0.078 & 0.544 & 1 & \textless 0.001 & 0.569 &\\[5pt]
            & \rotatebox[origin=c]{90}{1024} & 0.146 & 0.243 & 0.436 & 1 & 1 & \textless 0.001 & 1 & 1\\[5pt]
    \end{tabular}}
\end{table}
\end{document}

相关内容