TransWikia.com

How to create a multi column multi row table without borders in LaTeX?

TeX - LaTeX Asked by tauhid ullah on February 16, 2021

I just want to create a table like this
enter image description here

but without the in-between line among rows. I also don’t need the line between columns like this
enter image description here

but below the Existing Methods CFNeT multi-column i need a line which doesn’t span the full table. I mean that the line must fit into the content.

3 Answers

documentclass[11pt]{article}
usepackage{graphicx}

begin{document}
  This a multirow and multicolumn table
    begin{tabular}{|c|c|c|}
      hline
       a & b & g
       hline
       b & c & h
       hline
       g & v & a
       hline
   end{tabular}

end{document}

The | represent the vertical lines separating each element of the cell and c is the option to centre the cell's content (there are others like r -> right and l -> left).

Finally hline stands for horizontal line. I hope I was clear enough.

Answered by José Mabuxa on February 16, 2021

You have to compile at least twice with every change in the percentage (last) column (since it uses eqparbox for getting the appropriate alignment).

enter image description here

documentclass{book}

usepackage[
  margin=1in,
  landscape
]{geometry} % Just for this example

usepackage{booktabs,collcell,eqparbox,makecell}


begin{document}

begin{table}
  centering
  newcommand{pa}[1]{eqmakebox[CFNetvsNeuMF][r]{#1}}% Percentage alignment
  newcommand{hlc}{textbf}% Highlight cell
  caption{Comparison results of different methods in terms of NDCG@10 and HR@10.}
  begin{tabular}{ *{9}{c} >{collectcellpa}c<{endcollectcell} }
    toprule
    &
    &
    multicolumn{4}{c}{Existing methods} &
    multicolumn{3}{c}{CFNet} &
    
    cmidrule(lr){3-6}cmidrule(lr){7-9}
    Dataset & % raisebox{.7normalbaselineskip}[0pt][0pt]{Dataset}
    Measures & % raisebox{.7normalbaselineskip}[0pt][0pt]{Measures}
    ItemPop & eALS & DMF & NeuMF &
    CFNet-rl & CFNet-ml & CFNet &
    multicolumn{1}{c}{smash{makecell[b]{Improvement of  CFNet emph{vs.} NeuMF}}} 
    midrule
    ml-1m &  HR  & 0.4535 & 0.7018 & 0.6565 & hlc{0.7210} &
      0.7127 & 0.7073 & hlc{0.7253} &
      0.6% 
          & NDCG & 0.2542 & 0.4280 & 0.3761 & hlc{0.4387} &
      0.4336 & 0.4264 & hlc{0.4416} &
      0.7% 
    addlinespace
    lastfm &  HR  & 0.6628 & 0.8265 & 0.8840 & hlc{0.8868} &
      0.8840 & 0.8834 & hlc{0.8995} &
      1.4% 
           & NDCG & 0.3862 & 0.5162 & 0.5804 & hlc{0.6007} &
      0.6001 & 0.5919 & hlc{0.6186} &
      3.0% 
    addlinespace
    AMusic &  HR  & 0.2483 & 0.3711 & 0.3744 & 0.3891 &
      0.3947 & hlc{0.4071} & hlc{0.4116} &
      5.8% 
           & NDCG & 0.1304 & 0.2352 & 0.2149 & 0.2391 &
      hlc{0.2504} & 0.2420 & hlc{0.2601} &
      8.8% 
    addlinespace
    AToy &  HR  & 0.2840 & 0.3717 & 0.3535 & 0.3650 &
      0.3746 & hlc{0.3931} & hlc{0.4150} &
      13.7% 
         & NDCG & 0.1518 & hlc{0.2434} & 0.2016 & 0.2155 &
      0.2271 & 0.2293 & hlc{0.2513} &
      16.6% 
    bottomrule
  end{tabular}
end{table}

end{document}

Answered by Werner on February 16, 2021

With use of the siunitx package:

documentclass{book}
usepackage[landscape]{geometry} 
usepackage{booktabs, makecell, multirow}
% new
usepackage{siunitx}
usepackage{etoolbox}
newrobustcmdB{DeclareFontSeriesDefault[rm]{bf}{b}bfseries}
usepackage{xparse}
NewExpandableDocumentCommandmcc{O{1}m}
    {multicolumn{#1}{c}{#2}}


begin{document}
    begin{table}
    centering
    sisetup{detect-weight,
             mode=text,
             table-format=1.4}
    setlengthtabcolsep{0pt}
    caption{Comparison results of different methods in terms of NDCG@10 and HR@10.}
  begin{tabular*}{linewidth}{@{extracolsep{fill}}
                               l c 
                          *{7}{S} 
                               S[table-format=2.1,
                                 table-space-text-post=%]<{%} }
    toprule
    &   & mcc[4]{Existing methods} 
            & mcc[3]{CFNet} 
                &  mcc{multirow{2}{*}{makecell{Improvement of  
                                              CFNet emph{vs.} NeuMF}}} 
    cmidrule(lr){3-6}cmidrule(lr){7-9}
Dataset & Measures  
        & {ItemPop} & {eALS}    & {DMF}     & {NeuMF} 
        & {CFNet-rl}& {CFNet-ml}& {CFNet}   & mcc{}        
    midrule
 ml-1m  &  HR       
        & 0.4535    & 0.7018    & 0.6565    &B 0.7210  
        & 0.7127    & 0.7073    &B 0.7253  &   0.6         cr
        & NDCG      
        & 0.2542    & 0.4280    & 0.3761    &B 0.4387  
        & 0.4336    & 0.4264    &B 0.4416  &   0.7         cr
    addlinespace
lastfm  &  HR  
        & 0.6628    & 0.8265    & 0.8840    &B 0.8868
        & 0.8840    & 0.8834    &B 0.8995  &   1.4         cr
        & NDCG 
        & 0.3862    & 0.5162    & 0.5804    &B 0.6007  
        & 0.6001    & 0.5919    &B 0.6186  & 3.0           cr
    addlinespace
AMusic  &  HR  
        & 0.2483    & 0.3711    & 0.3744    & 0.3891 
        & 0.3947    &B 0.4071  &B 0.4116  &   5.8         cr
        & NDCG 
        & 0.1304    & 0.2352    & 0.2149    & 0.2391 
        &B 0.2504  & 0.2420    &B 0.2601  &   8.8         cr
    addlinespace
AToy    &  HR  
        & 0.2840    & 0.3717    & 0.3535    & 0.3650 
        & 0.3746    &B 0.3931  &B 0.4150  & 13.7          cr
        & NDCG 
        & 0.1518    &B 0.2434  & 0.2016    & 0.2155 
        & 0.2271    & 0.2293    &B 0.2513  &   16.6        cr
    bottomrule
  end{tabular*}
end{table}

end{document}

enter image description here

Answered by Zarko on February 16, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP