TransWikia.com

How do I revise my code to produce the desired output like the one in the picture?

TeX - LaTeX Asked by user235424 on March 22, 2021

How do I revise my code to produce the desired output?
This is my code:

begin{table}[ht]
centering
begin{tabular}{rllllll}
  hline
 & hspace{1cm} Dyads Sample & & & hspace{1cm} Committed Sample & &  
  hline
 & Range & Mean & Sd & Range & Mean & Sd  
  hline
BAA & {0,1} & 0.418 &  & {0,1} & 0.306 &   
  BAF & {0,1} & 0.449 &  & {0,1} & 0.388 &   
  Data Science & {0,1} & 0.550 &  & {0,1} & 0.406 &   
  Life Science & {0,1} & 0.597 &  & {0,1} & 0.509 &   
  Engineer & {0,1} & 0.796 &  & {0,1} & 0.864 &   
  Previous Raised & (0,40.0] & 1.096 & 3.030 & (0,10.0] & 1.101 & 1.754  
  Max Raise & [0.2,27.7] & 2.026 & 2.658 & [0.2,20.0] & 2.947 & 2.947  
  Age & [0,18] & 3.157 & 2.738 & [0,11] & 3.188 & 2.307  
  Patent & {0,1} & 0.171 &  & {0,1} & 0.161 &   
  Committed & {0,1} & 0.0188 &  & {0,1} & 1 &   
  Amount ($K) & [0,350] & 0.273 & 5.154 & [3,350] & 15.408 & 35.627  
   hline
  #Obs & 18618 & 18618 & 18618 & 330 & 330 & 330 
    hline
end{tabular}
end{table}

This is my output:enter image description here

This is the desired output:
enter image description here

One Answer

At a minimum, you need to replace the line

& hspace{1cm} Dyads Sample & & & hspace{1cm} Committed Sample & & 

with

& multicolumn{3}{c}{Dyads Sample} & multicolumn{3}{c}{Committed Sample} 

I would go further, though, and employ the line-drawing macros of the booktabs package -- toprule, midrule, cmidrule, addlinespace, and bottomrule -- instead of hline to provide more structure and visual appeal to the table.

enter image description here

documentclass{article} % or some other suitable document class
usepackage{booktabs}
begin{document}
begin{table}[ht]
centering
begin{tabular}{@{} l ccc ccc @{}}
  toprule
  & multicolumn{3}{c}{Dyads Sample} & multicolumn{3}{c@{}}{Committed Sample} 
  cmidrule(lr){2-4} cmidrule(l){5-7}
  & Range & Mean & Sd & Range & Mean & Sd  
  midrule
  BAA & {0,1} & 0.418 &  & {0,1} & 0.306 &   
  BAF & {0,1} & 0.449 &  & {0,1} & 0.388 &   
  Data Science & {0,1} & 0.550 &  & {0,1} & 0.406 &   
  Life Science & {0,1} & 0.597 &  & {0,1} & 0.509 &   
  Engineer & {0,1} & 0.796 &  & {0,1} & 0.864 &   
  addlinespace
  Previous Raised & (0,40.0] & 1.096 & 3.030 & (0,10.0] & 1.101 & 1.754  
  Max Raise & [0.2,27.7] & 2.026 & 2.658 & [0.2,20.0] & 2.947 & 2.947  
  addlinespace
  Age & [0,18] & 3.157 & 2.738 & [0,11] & 3.188 & 2.307  
  Patent & {0,1} & 0.171 &  & {0,1} & 0.161 &   
  Committed & {0,1} & 0.0188 &  & {0,1} & 1 &   
  Amount ($K) & [0,350] & 0.273 & 5.154 & [3,350] & 15.408 & 35.627  
  midrule
  #Obs & 18618 & 18618 & 18618 & 330 & 330 & 330 
  bottomrule
end{tabular}
end{table}
end{document}

Answered by Mico on March 22, 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