[Tex/LaTex] Delete column line in tabular

columnstables

I have the following table, but I want to delete the two vertical lines in the GBM and MJD row:

\documentclass{beamer}

\usepackage{booktabs}

\begin{document}

\frame{
\frametitle{Test}
\begin{tabular}{l|l|llr}
\toprule
%\multicolumn{4}{r}{GBM MJD} \\
%\cmidrule(r){1-2}
 &  & GBM& MJD\\
\midrule

 &1\%  & 1& 2\\
 Microsoft & 5\%  &1& 2 \\
 &10\%  & 1& 2\\  
   \midrule
 &1\%  & 1& 2\\
 Allianz & 5\%  &1& 2 \\
 &10\%  & 1& 2\\  

\bottomrule
\end{tabular}
}
\end{document}

I want to delete the following lines:

enter image description here

Best Answer

You can do this using \multicolumn which has a width of 1 column; it may seem a little funny, but it's a standard way to fix this.

I've used

\multicolumn{1}{c}{}

in the columns that you didn't want your |. You can read it as a 'multicolumn that spans 1 column, is centered, and has no content'. I also noted that you had an extra column in your tabular declaration which didn't harm things, but I've removed it.

screenshot

\documentclass{beamer}

\usepackage{booktabs}

\begin{document}

\begin{frame}
    \frametitle{Test}

    \begin{tabular}{l|l|ll}
        \toprule
        \multicolumn{1}{c}{}& \multicolumn{1}{c}{} & GBM& MJD\\
        \midrule
                  & 1\%  & 1 & 2 \\
        Microsoft & 5\%  & 1 & 2 \\
                  & 10\% & 1 & 2 \\  
        \midrule
                  & 1\%  & 1 & 2 \\
        Allianz   & 5\%  & 1 & 2 \\
                  & 10\% & 1 & 2 \\  
        \bottomrule
    \end{tabular}
\end{frame}

\end{document}

Some folks would recommend avoiding vertical lines altogether (including the author of the booktabs package), but that is personal preference.

Just for reference, if you use

\begin{tabular}{llll}

which removes all the vertical lines, then you get

screenshot

See also Why not use vertical lines ('|') in a tabular?

Another idea (thanks @doncherry, @Qrrbrbirlbel) is to right align the columns and insert <{\,\%} between columns 2 and 3; this requires the array package; note that this trick adds a % to each row in that column, so I've had to use the multicolumn trick again to remove it from the first row.

enter image description here

\documentclass{beamer}
\usepackage{array}
\usepackage{booktabs}

\begin{document}

\begin{frame}
    \frametitle{Test}

    \begin{tabular}{lr<{\,\%}cc}
        \toprule
                  & \multicolumn{1}{c}{}   & GBM& MJD\\
        \midrule
                  & 1  & 1 & 2 \\
        Microsoft & 5  & 1 & 2 \\
                  & 10 & 1 & 2 \\  
        \midrule
                  & 1  & 1 & 2 \\
        Allianz   & 5  & 1 & 2 \\
                  & 10 & 1 & 2 \\  
        \bottomrule
    \end{tabular}
\end{frame}

\end{document}

As you can see, there are lots of details to pay attention to when constructing a tabular! For future reading, you might also like to look at the siunitx which defines (among other useful commands) the S column type.