TransWikia.com

Adjust a given table to a desired number of columns

TeX - LaTeX Asked on November 16, 2020

should look as this

documentclass[12pt]{article}


usepackage[letterpaper,margin=1in]{geometry} 
usepackage{booktabs}
usepackage{siunitx} 
newcolumntype{T}[1]{S[table-format=#1]} 
begin{document}

noindent
begingroup % localize scope of the next instruction
setlengthtabcolsep{0pt} % let LaTeX figure out intercol. sapce
begin{tabular*}{textwidth}{@{extracolsep{fill}} 
    c *{3}{T{2.1}T{2.1}T{3.0}} }  
toprule
$N_p$ & multicolumn{3}{c}{method_1}
      & multicolumn{3}{c}{method_2}
      & multicolumn{3}{c}{method_3} 
cmidrule{2-4} cmidrule{5-7} cmidrule{8-10}
& {parameter_1} & {parameter_2} & {parameter_3} & 
  {parameter_1} & {parameter_2} & {parameter_3} & 
  {parameter_1} & {parameter_2} & {parameter_3}  
midrule
10 & 13.6 & 98.4 & 113 & 12.4 & 98.7 & 285 & 12.3 & 98.7 & 411 
15 &  8.4 & 99.4 & 135 
20 &  6.2 & 99.7 & 140 
bottomrule
end{tabular*}
endgroup

end{document}

I have seen the following beautiful table which suits exactly what I want to create as well. Unfortunately, there is one difference, I have 5 methods in total and only 2 parameter for which I want to fill in values. I’m rather new to tables so I wasn’t able to adjust this code-snippet accordingly. Any help is appreciated.

One Answer

Does the answer match the sketch

Aditionally -- The cmidrule command of booktabs package allows for an optional argument using parentheses ( ) to specify on which side it should be reduced:

cmidrule(r){3-8} cmidrule(r){9-14} cmidrule{15-18}

would shorten the right end of the first two rules. You can also add an amount in braces, i.e. (r{10pt}) and select both sides (lr), (l{5pt}r{10pt}).

enter image description here

documentclass{article}
usepackage{array, booktabs} 
begin{document}
    setlength{arrayrulewidth}{.8pt}
    newcommand{mc}[1]{multicolumn{2}{c}{Method.#1}}
    begin{table}
        caption{Table showing Feature 5's Functional Tests}
%       hspace*{-0.5in}
        begin{tabular}{ccccccccccc}toprule
             Np &
              mc{1}&
                mc{2}&
                    mc{3}&
                        mc{4}&
                            mc{5} 
            cmidrule(lr){2-3}
             cmidrule(lr){4-5}
              cmidrule(lr){6-7}
               cmidrule(lr){8-9}
                cmidrule(lr){10-11}
             & pm1&pm2&pm1&pm2&pm1&pm2&pm1&pm2&pm1&pm2                
            midrule 
            20&A&A&A&A&A&A&A&A&A&A
            40&A&A&A&A&A&A&A&A&A&A
            60&A&A&A&A&A&A&A&A&A&A
            bottomrule

        end{tabular}
    end{table}
end{document}

Correct answer by js bibra on November 16, 2020

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