下面是我的R脚本,以及生成的html,不包括latex表。 我正在使用RStudio和knitr的旋转函数来产生输出。 如果我将输出更改为pdf_document,则表格按预期输出。
#' ---
#' title: "Sample"
#' author: "Joe_Schmoe"
#' output: html_document
#' ---
#+ results='asis'
library(xtable)
data("tli")
xtable(head(tli))
library(knitr)
kable(head(tli), format="latex")
<body>
<style type="text/css">
.main-container {
max-width: 940px;
margin-left: auto;
margin-right: auto;
}
code {
color: inherit;
background-color: rgba(0, 0, 0, 0.04);
}
img {
max-width:100%;
height: auto;
}
</style>
<div class="container-fluid main-container">
<div id="header">
<h1 class="title">Sample</h1>
<h4 class="author"><em>Joe_Schmoe</em></h4>
<h4 class="date"><em>Wed Nov 18 14:17:44 2015</em></h4>
</div>
<pre class="r"><code>library(xtable)
data("tli")
xtable(head(tli))</code></pre>
% latex table generated in R 3.2.2 by xtable 1.8-0 package % Wed Nov 18 14:17:44 2015
<pre class="r"><code>library(knitr)
kable(head(tli), format="latex")</code></pre>
<pre class="r"><code>sessionInfo()</code></pre>
<p>R version 3.2.2 (2015-08-14) Platform: x86_64-w64-mingw32/x64 (64-bit) Running under: Windows 7 x64 (build 7601) Service Pack 1</p>
<p>locale: [1] LC_COLLATE=English_United States.1252 [2] LC_CTYPE=English_United States.1252<br />[3] LC_MONETARY=English_United States.1252 [4] LC_NUMERIC=C<br />[5] LC_TIME=English_United States.1252</p>
<p>attached base packages: [1] stats graphics grDevices utils datasets methods base</p>
<p>other attached packages: [1] knitr_1.10.5 xtable_1.8-0</p>
<p>loaded via a namespace (and not attached): [1] magrittr_1.5 formatR_1.2 tools_3.2.2 htmltools_0.2.6 [5] yaml_2.1.13 stringi_1.0-1 rmarkdown_0.6.1 stringr_1.0.0<br /> [9] digest_0.6.8 evaluate_0.7</p>
</div>
<script>
// add bootstrap table styles to pandoc tables
$(document).ready(function () {
$('tr.header').parent('thead').parent('table').addClass('table table-condensed');
});
</script>
<!-- dynamically load mathjax for compatibility with self-contained -->
<script>
(function () {
var script = document.createElement("script");
script.type = "text/javascript";
script.src = "https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML";
document.getElementsByTagName("head")[0].appendChild(script);
})();
</script>
</body>