gpt4 book ai didi

position - 如何以全文本宽度居中 LaTeX xtable 输出

转载 作者:行者123 更新时间:2023-12-04 01:11:17 25 4
gpt4 key购买 nike

我正在使用 tufte-handout ( http://mirrors.ibiblio.org/CTAN/macros/latex/contrib/tufte-latex/sample-handout.pdf ) 在 latex 中创建一个小报告。我有一个文件 code.Rnw,我将它编入了 code.tex。下面是我的代码。Rnw:

\documentclass[12pt,english,nohyper]{tufte-handout}
\usepackage{longtable}
\usepackage{geometry}

\begin{document}

<<include=FALSE>>=
library(ggplot2)
library(xtable)
@

\centerline{\Large\bf This is my Main Title}

<<echo=FALSE,results='asis'>>=
fname='plot1.pdf'
pdf(fname,width=4,height=4)
print(qplot(mpg,cyl,data=mtcars))
{dev.off();invisible()}
cat(sprintf('\\begin{marginfigure}
\\includegraphics[width=0.98\\linewidth]{%s}
\\caption{\\label{mar:hist}MPG vs CYL in MTCARS dataset.}
\\end{marginfigure}',sub('\\.pdf','',fname)))
@

This is the paragraph in my report. This is the paragraph in my report. This is the paragraph in my report. This is the paragraph in my report. This is the paragraph in my report. This is the paragraph in my report. This is the paragraph in my report.

This is the paragraph in my report. This is the paragraph in my report. This is the paragraph in my report. This is the paragraph in my report. This is the paragraph in my report. This is the paragraph in my report. This is the paragraph in my report. This is the paragraph in my report. This is the paragraph in my report. This is the paragraph in my report. This is the paragraph in my report.
\bigskip{}

<<echo=FALSE,results='asis'>>=
x.big <- xtable(mtcars[1:20,1:4], label ='tab:mtcars',caption ='This is the mtcar dataset head.',align = c("rr|lr|r"))

print(x.big, tabular.environment ='longtable', floating = FALSE, include.rownames=FALSE)
@

\end{document}

这会产生以下输出:

this is my output

我想要做的是允许 xtable 输出(表 1)在全文中居中。默认情况下,在 tufte-handout 包中,它似乎将表格居中放置在左侧非边距中。

我咨询了几个来源,包括本文第一句话中指出的来源。根据该引用资料,“全页宽度的图形和表格可以放置在图形* 或表格* 环境中。”鉴于我也在编写这份报告,我不确定如何实现这一点。

最佳答案

您可以通过包装 longtable 来解决此问题。在一簇簇绒中 fullwidth环境。这个解决方法似乎还需要一个小技巧(在第 2 行)来修复 hsize ,但它似乎按预期工作。

\begin{fullwidth}
\makeatletter\setlength\hsize{\@tufte@fullwidth}\makeatother
<<echo=FALSE,results='asis'>>=
x.big <- xtable(mtcars[1:20,1:4], label ='tab:mtcars',caption ='This is the mtcar dataset head.',align = c("rr|lr|r"))

print(x.big, tabular.environment ='longtable', floating = FALSE, include.rownames=FALSE)
@
\end{fullwidth}

关于position - 如何以全文本宽度居中 LaTeX xtable 输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31258320/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com