如何在表格中繪製缺少的垂直線?

如何在表格中繪製缺少的垂直線?

我想在 中繪製缺少的垂直線tabular。我認為\multirow{2}{*}{}可以防止繪製表格的垂直線。

我的程式碼:

\documentclass{article}
\usepackage[a4paper,margin=1in,landscape]{geometry}
\usepackage{makecell}
\usepackage{multirow}
\usepackage{booktabs}

\begin{document}
\begin{center}
    \begin{table*}[!t]  %
        \centering
        \caption{Results ...}
        \begin{tabular}{|c|c|c|c|c|c|c|c|c|}
          \hline
          \textbf{Test} & \multicolumn{2}{c|}{Workflow} & Method
          & \multirow{2}{*}{\makecell{Completion                                                 \\ Time (min)}}
                        & \multirow{2}{*}{\makecell{Gas Used for                                               \\
          \textit{submitJob} (gas)}}
                        & \multirow{2}{*}{\makecell{Gas Used for                                               \\
          \textit{processPayment} (gas)}}
                        & \multirow{2}{*}{\makecell{Actual/Complete                                            \\ Cost
          (\textit{Cent})}}
                        & \multirow{2}{*}{\makecell{Failed}}                                                   \\
          \cmidrule(lr){2-3}
                        &       $|V|$                   & $|E|$                                                \\
          \hline
          $T_1$         & 16                            & 28 & ALGO & 27 & 1722983 & 1942770 & 0.827/0.827 & 0 \\ \hline
        \end{tabular}
    \end{table*}
\end{center}
\end{document}

輸出:

在此輸入影像描述

想要的輸出:在此輸入影像描述

答案1

您可以nicematrix與該hvlines選項一起使用。多行和多列單元格的命令都是\Block

請記住,這\Block不會導致單元格被跳過,因此&&在工作流程和方法單元格之間是必要的。另外不要忘記編譯兩次。

該線\NiceMatrixOptions{cell-space-limits = 2pt}是可選的,並在行之間創建一些額外的垂直空間。

在此輸入影像描述

\documentclass{article}
\usepackage[a4paper,margin=1in,landscape]{geometry}
\usepackage{nicematrix}

\begin{document}
\begin{center}
    \begin{table*}[!t]  %
        \centering
        \caption{Results ...}
        \NiceMatrixOptions{cell-space-limits = 2pt}
        \begin{NiceTabular}{ccccccccc}[hvlines]
          \Block{2-1}{\textbf{Test}} & \Block{1-2}{Workflow} && \Block{2-1}{Method} & \Block{2-1}{Completion\\Time (min)}
                        & \Block{2-1}{Gas Used for\\ \textit{submitJob} (gas)}
                        & \Block{2-1}{Gas Used for\\ \textit{processPayment} (gas)}
                        & \Block{2-1}{Actual/Complete\\ Cost (\textit{Cent})}
                        & \Block{2-1}{Failed}\\
          & $|V|$ & $|E|$ \\
          $T_1$ & 16 & 28 & ALGO & 27 & 1722983 & 1942770 & 0.827/0.827 & 0
        \end{NiceTabular}
    \end{table*}
\end{center}
\end{document}

答案2

如果您要使用booktabs套件的畫線宏,請不要使用垂直線。沒辦法,沒辦法。

在此輸入影像描述

請注意,如果您landscape在載入geometry套件時指定選項,整個文件將以橫向模式排版。不需要\begin{landscape}\end{landscape}

\documentclass{article}
\usepackage[a4paper,margin=1in,landscape]{geometry}
\usepackage{booktabs,array,calc}
\newcommand\mytab[1]{\smash{\begin{tabular}[t]{@{} c @{}} #1 \end{tabular}}}
\newlength\mylen
\setlength\mylen{\widthof{Workflow}-4\tabcolsep}
\begin{document}

\begin{table}[h]
\centering
\caption{Results \dots}
\smallskip
\begin{tabular}{@{} *{2}{wc{\mylen}} *{7}{c} @{}}
  \toprule
  Test
  & \multicolumn{2}{@{}c@{}}{Workflow} 
  & Method
  & \mytab{Completion   \\ Time (min)}
  & \mytab{Gas used for \\ \textit{submitJob} (gas)}
  & \mytab{Gas used for \\ \textit{processPayment} (gas)}
  & \mytab{Actual/Complete \\ Cost (\textit{Cent})}
  & Failed \\
  \cmidrule(lr){2-3}
  & $V$ & $E$ \\
  \midrule
  $T_1$ & 16 & 28 & ALGO & 27 & 1722983 & 1942770 & 0.827/0.827 & 0 \\ 
  \bottomrule
\end{tabular}
\end{table}

\end{document}

答案3

如果沒有其他辦法,我會選擇一個天真的方法:

\documentclass{article}
\usepackage[a4paper,margin=1in,landscape]{geometry}
\usepackage{makecell}
\usepackage{multirow}
\usepackage{booktabs}

\begin{document}
%\begin{landscape}
    \begin{center}
        \begin{table*}[!t]  %
            \centering
            \caption{Results ...}
            \begin{tabular}{|c|c|c|c|c|c|c|c|c|}
              \hline
              \textbf{Test} & \multicolumn{2}{c|}{Workflow} & Method
                            & Completion  
                            & Gas Used for 
                            & Gas Used for 
                            & Actual/Complete 
                            & Failed \\ 
                            & $|V|$ & $|E|$ 
                            &
                            & Time (min) 
                            & \textit{submitJob} (gas) 
                            & \textit{processPayment} (gas) 
                            & Cost (\textit{Cent}) 
                            & \\
              \hline
              $T_1$         & 16                            & 28 & ALGO & 27 & 1722983 & 1942770 & 0.827/0.827 & 0 \\ \hline
            \end{tabular}
        \end{table*}
    \end{center}
%\end{landscape}
\end{document}

當然,「失敗」不再位於中間,但「方法」也是如此

相關內容