title: possible to create latex multicolumns in xtable?
body: <p>I am using xtable with R Markdown and knitr to produce .tex files that I call with \input{}. Works great, but I have not figured out how to create multicolumns like the one shown <a href="https://stackoverflow.com/questions/11950703/html-with-multicolumn-table-in-markdown-using-knitr">here</a>. Does anyone know how to to this?</p>
  
  <p>So far I am using:</p>
  
  <pre><code>tbl &lt;- xtable(data, align="l r r r r r")
  colnames(tbl) &lt;- c("Variable", 
                    "Mean", "Std Dev", 
                    "Mean", "Std Dev", 
                    "Difference")
  caption(tbl) &lt;- c("Table Title")
  print(tbl, 
      include.rownames=FALSE,
      caption.placement="top",
      booktabs=TRUE,
      type="latex", 
      file="output.tex")
  </code></pre>
  
  <p>I'd like to have a different grouping header over each "Mean" and "Std Dev" ("Treatment" and "Control"). </p>
  
  <p>Alternatively, is there a better method for using R Markdown/knitr to automatically generate tables? I don't want to manually edit the tables because the report needs to generate automatically.</p>
  
  <p><strong>UPDATE:</strong>
  @agstudy: I'm new to latex, but I think this is the output I am looking to produce automatically with xtable (or something like xtable):</p>
  
  <pre><code>\begin{tabular}{lrrrrr}
    \toprule
        &amp; \multicolumn{2}{c}{Treatment} &amp; \multicolumn{2}{c}{Control} &amp; \\
    \cmidrule(lr){2-3} \cmidrule(lr){4-5}
    Variable &amp; Mean &amp; Std Dev &amp; Mean &amp; Std Dev &amp; Difference \\ 
    \midrule
    var1 &amp; 1 &amp; 2 &amp; 3 &amp; 4 &amp; 5 \\ 
    \bottomrule
  \end{tabular}
  </code></pre>
  
  <p><strong>UPDATE 2:</strong>
  @Jonathan: it took me a few reads to understand what you were suggesting. I took your recommendation, and it worked.</p>
  
  <p>In the R markdown chunk I now use:</p>
  
  <pre><code>tbl &lt;- xtable(data)
  print(tbl,
      only.contents=TRUE,
      include.rownames=FALSE,
      type="latex",
      digits(tbl) &lt;- c(0,1,1,1,1,1),
      file="output/tblout.tex")
  </code></pre>
  
  <p>Then in the text, I use:</p>
  
  <pre><code>\begin{tabular}{lddddd}
  \toprule
      &amp; \multicolumn{2}{c}{Treatment} &amp; \multicolumn{2}{c}{Control} &amp; \\
      \cmidrule(lr){2-3} \cmidrule(lr){4-5}
      Variable  &amp;  \multicolumn{1}{r}{Mean}  &amp;  \multicolumn{1}{r}{Std Dev}  &amp;       \multicolumn{1}{r}{Mean}  &amp;  \multicolumn{1}{r}{Std Dev}  &amp;  \multicolumn{1}{r}{Difference}  \\
  \midrule
  \input{../output/tblout}
  \bottomrule
  \end{tabular}
  </code></pre>
  
  <p>I'll see if anyone has any other suggestions for a native xtable (or other package) solution. Otherwise, I will accept your answer. Thanks!</p>