2015-07-07 16 views
13

Tôi đang sử dụng bản ghi âm-tufte (http://mirrors.ibiblio.org/CTAN/macros/latex/contrib/tufte-latex/sample-handout.pdf) để tạo một báo cáo nhỏ bằng latex. Tôi có một tập tin code.Rnw mà tôi đan thành code.tex. Dưới đây là code.Rnw tôi:Cách căn giữa đầu ra LaTeX xtable với chiều rộng toàn văn

\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} 

này tạo ra kết quả như sau:

this is my output

Những gì tôi đang cố gắng làm là để cho phép đầu ra xtable (Bảng 1) được tập trung trên toàn văn. Theo mặc định, trong gói tufte-handout, nó dường như là trung tâm của bảng ở bên trái không lề.

Tôi đã tham khảo một số nguồn, bao gồm một nguồn được nêu trong câu đầu tiên của bài đăng hiện tại này. Theo tham chiếu đó, "Các số liệu và chiều rộng toàn trang có thể được đặt trong các môi trường hình * hoặc bảng *." Tôi không chắc chắn làm thế nào để thực hiện điều này, cho rằng tôi cũng đan báo cáo này.

Trả lời

5

Bạn có thể khắc phục sự cố này bằng cách gói longtable trong môi trường tufte fullwidth. Cách giải quyết này cũng dường như yêu cầu một hack nhỏ (trong dòng 2) để sửa lỗi hsize, nhưng nó dường như hoạt động như dự định.

\begin{fullwidth} 
\makeatletter\setlength\hsize{\@[email protected]}\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} 
+0

Chỉ cần lưu ý cho người khác rằng giải pháp này có thể không hoạt động như mong đợi nếu sử dụng \ usepackage {floatrow}. Tôi đã có điều đó trong phần mở đầu của tôi, và đang đối mặt với một số vấn đề. Một khi tôi gỡ bỏ nó, nó hoạt động tốt. Cảm ơn bạn! – LanneR

+0

Đối với bất kỳ ai quan tâm, tôi đã đăng một bài tiếp theo cho bài đăng hiện tại. Vì tôi đã phải xóa \ usepackage {floatrow} để lấy bảng ở giữa, sau đó tôi cũng mất các chức năng mong muốn với các số liệu và chú thích của chúng. Bây giờ tôi đã cố gắng để xác định làm thế nào để thành công trung tâm cả một bảng và hình trong tufte-handout. Bài tiếp theo, nơi bài viết này được khám phá có tại đây: http://stackoverflow.com/questions/31709966/how-to-center-latex-xtable-and-figure-output-in-full-text-width – LanneR

Các vấn đề liên quan