5

I am currently trying to remove the lines in the table, that doesn't contain anything.

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{caption}
\usepackage{float}

\begin{document}

\begin{table}[H]
    \begin{tabular}{ |p{3cm}||p{3cm}|p{3cm}|p{3cm}|p{3cm}| }
    \hline
    \multicolumn{4}{|c|}{Title} \\
    \hline
    Window size: 9 &  Results & Window size: 15 &  Results \\ 
    \hline
    Accuracy &  0.70 & Accuracy &  0.60  \\
    Validation accuracy&    0.19 & Validation accuracy&    0.16 \\  
    \hline
    Window size: 32 &  Results  \\
    \hline
    Accuracy &  0.14 \\
    Validation accuracy&    0.07 \\   
    \hline
    \end{tabular}
\end{table}

\end{document}

enter image description here

How do i remove the empty lines in this table?

Is there a simple way to remove it?..

2
  • Please make your code compilable (if possible), or at least complete it with \documentclass{...}, the required \usepackage's, \begin{document}, and \end{document}. That may seem tedious to you, but think of the extra work it represents for TeX.SX users willing to give you a hand. Help them help you: remove that one hurdle between you and a solution to your problem.
    – dexteritas
    Jul 31, 2017 at 9:12
  • @dexteritas you are right.. I added that.
    – dfh
    Jul 31, 2017 at 9:15

2 Answers 2

4

You can use \cline{x-y} to make horizontal lines for specified columns.

There was one unused column, so I removed the last p{3cm}|.

For 4 equal columns you can also use: *4{p{3cm}|}.

\documentclass{article}
\usepackage{caption}

\begin{document}

\begin{table}
    \begin{tabular}{ |*4{p{3cm}|} }
        \hline
        \multicolumn{4}{|c|}{Title} \\
        \hline
        Window size: 9 &  Results & Window size: 15 &  Results \\ 
        \hline
        Accuracy &  0.70 & Accuracy &  0.60  \\
        Validation accuracy&    0.19 & Validation accuracy&    0.16 \\  
        \hline
        Window size: 32 &  Results  \\
        \cline{1-2}
        Accuracy &  0.14 \\
        Validation accuracy&    0.07 \\   
        \cline{1-2}
    \end{tabular}
\end{table}

\end{document}

enter image description here

0
0

In this case the problem is not the long lines, but the design of the table leaving unnecessary empty cells and redundant row headers. The solution is redesign the table. I suggest strongly also avoid all vertical lines and use the commands of booktabs package. Then you can use \cmidrule instead of \cline for horizontal lines in selected columns only.

mwe

\documentclass{article}
\usepackage{booktabs,caption,siunitx}
\begin{document}
\begin{table}
\centering
    \caption*{Meaningful Title About the Results}
    \begin{tabular}{S[table-format=2.0]cc}
    \toprule
    {Window size} &  Accuracy &  {Validation}\\
    \cmidrule(rl){1-1}\cmidrule(rl){2-2}\cmidrule(rl){3-3} 
    % ... or simply \midrule
     9 & 0.70 & 0.19\\
    15 & 0.60 & 0.16\\
    32 & 0.14 & 0.07\\\bottomrule
    \end{tabular}
\end{table}
\end{document}

You must log in to answer this question.

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