5

I want to draw missing vertical lines in a tabular. I think \multirow{2}{*}{} prevents table's vertical line to be drawn.

My code:

\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}

output:

enter image description here

Wanted output:enter image description here

6
  • 1
    Your code produced error as landscape not defined, please check and update
    – MadyYuvi
    Apr 23 at 13:44
  • Don't use vertical lines if you use the booktabs package (and also don't use vertical lines if you don't use the booktabs package) Apr 23 at 13:52
  • Should your title read: "How can I draw missing vertical lines in tabular?"? Apr 23 at 13:53
  • @samcarter_is_at_topanswers.xyz updated
    – alper
    Apr 23 at 14:01
  • @MadyYuvi Thanks fixed
    – alper
    Apr 23 at 14:04

3 Answers 3

5

You can use nicematrix with the hvlines option. The command for both multirow and multicolumn cells is \Block.

Remember that \Block does not cause the cells to be skipped so && is necessary between the Workflow and Method cells. Also don't forget to compile twice.

The line \NiceMatrixOptions{cell-space-limits = 2pt} is optional and creates some additional vertical space between rows.

enter image description here

\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}
4

If you're going to use the line-drawing macros of the booktabs package, don't use vertical lines. No way, no how.

enter image description here

Do note that if you specify option landscape while loading the geometry package, the entire document will be typeset in landscape mode. No need for \begin{landscape} and \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}
2
  • 1
    Thanks. Your answer is actually my first choice and the correct way. But unfortunately my university forces us to use vertical-lines in tabular for our thesis :-(
    – alper
    Apr 23 at 14:18
  • 2
    @alper if you need vertical lines, you can't use booktabs. It's stated quite clearly in the manual... there are other packages, like nicematrix or tabularray, that probably fulfill better your objective.
    – Rmano
    Apr 23 at 15:55
3

If nothing else works, I'd choose a naive approach:

\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}

Granted, the "Failed" isn't positioned in the middle any longer, but that's true for "Method" as well

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .