{"id":139,"date":"2015-05-30T23:22:12","date_gmt":"2015-05-30T23:22:12","guid":{"rendered":"http:\/\/blog.ufes.br\/fabiomolinares\/?p=139"},"modified":"2015-05-31T00:00:48","modified_gmt":"2015-05-31T00:00:48","slug":"booktabs-package-and-sweave","status":"publish","type":"post","link":"https:\/\/blog.ufes.br\/fabiomolinares\/2015\/05\/30\/booktabs-package-and-sweave\/","title":{"rendered":"Booktabs package and Sweave"},"content":{"rendered":"<p>The booktabs package in latex makes really beautiful\u00a0tables. This package provide some additional commands to enhance the quality of table in LaTeX, especially if there is math in your table that might run up against the regular <code>\\hline<\/code> in the tabular environment. I created a table with the following code:<\/p>\n<pre>% file: example.Rnw\r\n% require xtable\r\n\\<a href=\"http:\/\/www.golatex.de\/wiki\/index.php?title=%5Cdocumentclass\">documentclass<\/a>{article}\r\n\\<a href=\"http:\/\/www.golatex.de\/wiki\/index.php?title=%5Cusepackage\">usepackage<\/a>{booktabs}\r\n\r\n\\begin{document}\r\n\r\n\\begin{table}[!h] \r\n\\<a href=\"http:\/\/www.golatex.de\/wiki\/index.php?title=%5Ccentering\">centering<\/a>\r\n\\<a href=\"http:\/\/www.golatex.de\/wiki\/index.php?title=%5Ccaption\">caption<\/a>{This is my table.}\r\n\\<a href=\"http:\/\/www.golatex.de\/wiki\/index.php?title=%5Clabel\">label<\/a>{tab:table1}\r\n&lt;&lt;mytable,echo=F,results=tex&gt;&gt;=\r\nmat &lt;- as.data.frame(matrix(runif(25),nrow=5))\r\ncolnames(mat) &lt;- c(\"$\\\\alpha$\",\"$\\\\beta$\",\r\n\"$\\\\gamma$\",\"$\\\\delta$\",\"$\\\\<a href=\"http:\/\/www.golatex.de\/wiki\/index.php?title=%5Cfrac\">frac<\/a>{\\\\epsilon}{2}$\")\r\nrownames(mat) &lt;- c(\u2018A\u2019,\u2019B\u2019,\u2019C\u2019,\u2019D\u2019,\u2019E\u2019)\r\nmat &lt;- xtable::xtable(mat,digits=rep(5,ncol(mat)+1))\r\nprint(mat, \r\nsanitize.text.function = \r\n    function(x){x},\r\n\u00a0 \u00a0 \u00a0 \u00a0 floating=FALSE, \r\n\u00a0 \u00a0 \u00a0 \u00a0 hline.after=NULL, \r\n\u00a0 \u00a0 \u00a0 \u00a0 add.to.row=list(pos=list(-1,0,\r\n        nrow(mat)), command=c('\\\\toprule\\n',\r\n        '\\\\midrule\\n','\\\\bottomrule\\n')))\r\n@\r\n\\end{table}\r\n\\end{document}\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p>You can use to compile:<\/p>\n<pre>$ R CMD Sweave example.Rnw\r\n$ pdflatex example.tex\r\n<\/pre>\n<p>The definition of <strong>\\toprule<\/strong>,\u00a0<strong>\\midrule<\/strong>\u00a0and\u00a0<strong>\\bottomrule<\/strong> from<br \/>\nbooktabs package is:<\/p>\n<pre>\\def\\toprule{\\noalign{\\ifnum0=`}\\fi\r\n  \\@aboverulesep=\\abovetopsep\r\n  \\global\\@belowrulesep=\\belowrulesep \r\n  \\global\\@thisruleclass=\\@ne\r\n  \\@ifnextchar[{\\@BTrule}{\\@BTrule[\\heavyrulewidth]}}\r\n<\/pre>\n<pre>\\def\\midrule{\\noalign{\\ifnum0=`}\\fi\r\n  \\@aboverulesep=\\aboverulesep\r\n  \\global\\@belowrulesep=\\belowrulesep\r\n  \\global\\@thisruleclass=\\@ne\r\n  \\@ifnextchar[{\\@BTrule}{\\@BTrule[\\lightrulewidth]}}\r\n<\/pre>\n<pre>\\def\\bottomrule{\\noalign{\\ifnum0=`}\\fi\r\n  \\@aboverulesep=\\aboverulesep\r\n  \\global\\@belowrulesep=\\belowbottomsep\r\n  \\global\\@thisruleclass=\\@ne\r\n  \\@ifnextchar[{\\@BTrule}{\\@BTrule[\\heavyrulewidth]}}\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>The booktabs package in latex makes really beautiful\u00a0tables. This package provide some additional commands to enhance the quality of table in LaTeX, especially if there is math in your table that might run up against the regular \\hline in the tabular environment. I created a table with the following code: % file: example.Rnw % require [&hellip;]<\/p>\n","protected":false},"author":38,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_bbp_topic_count":0,"_bbp_reply_count":0,"_bbp_total_topic_count":0,"_bbp_total_reply_count":0,"_bbp_voice_count":0,"_bbp_anonymous_reply_count":0,"_bbp_topic_count_hidden":0,"_bbp_reply_count_hidden":0,"_bbp_forum_subforum_count":0,"_uag_custom_page_level_css":"","footnotes":""},"categories":[3,5],"tags":[],"class_list":["post-139","post","type-post","status-publish","format-standard","hentry","category-latex","category-r"],"uagb_featured_image_src":{"full":false,"thumbnail":false,"medium":false,"medium_large":false,"large":false,"1536x1536":false,"2048x2048":false},"uagb_author_info":{"display_name":"Fabio Fajardo","author_link":"https:\/\/blog.ufes.br\/fabiomolinares\/author\/fabio-molinares\/"},"uagb_comment_info":158,"uagb_excerpt":"The booktabs package in latex makes really beautiful\u00a0tables. This package provide some additional commands to enhance the quality of table in LaTeX, especially if there is math in your table that might run up against the regular \\hline in the tabular environment. I created a table with the following code: % file: example.Rnw % require&hellip;","_links":{"self":[{"href":"https:\/\/blog.ufes.br\/fabiomolinares\/wp-json\/wp\/v2\/posts\/139","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.ufes.br\/fabiomolinares\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.ufes.br\/fabiomolinares\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.ufes.br\/fabiomolinares\/wp-json\/wp\/v2\/users\/38"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.ufes.br\/fabiomolinares\/wp-json\/wp\/v2\/comments?post=139"}],"version-history":[{"count":11,"href":"https:\/\/blog.ufes.br\/fabiomolinares\/wp-json\/wp\/v2\/posts\/139\/revisions"}],"predecessor-version":[{"id":150,"href":"https:\/\/blog.ufes.br\/fabiomolinares\/wp-json\/wp\/v2\/posts\/139\/revisions\/150"}],"wp:attachment":[{"href":"https:\/\/blog.ufes.br\/fabiomolinares\/wp-json\/wp\/v2\/media?parent=139"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.ufes.br\/fabiomolinares\/wp-json\/wp\/v2\/categories?post=139"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.ufes.br\/fabiomolinares\/wp-json\/wp\/v2\/tags?post=139"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}