我正在尝试寻找一个可以在 Windows 上使用的电子表格,该电子表格带有将图表导出到 LaTeX 的选项。如果能直接从 Excel 导出就好了,但我读到这是不可能的,而且我找不到可以在 Windows 上使用的带有 LaTeX 导出选项的电子表格,有吗?或者除了将简单的图像放入 TeX 文档之外,还有其他方法可以解决我的问题吗?
答案1
我只回答表格部分,而不是图表部分:
我知道有三种导出的可能性:
其他相关问题和套餐
- 将 csv 文件作为表格导入到 latex 中(包裹
csvsimple
) - 在 Latex 中将 CSV 文件导入为表格但文件太长(包裹
csvsimple
) pgfplotstable
属于该包的一部分的包pgfplots
(关联到文档)。- 包裹
datatool
(关联)——取自Mike的评论。 - 重要的:用于表格生成的工具大列表(关联,简化 LaTeX 表格生成的工具综合列表)
答案2
以下是将 Excel 移至 LaTeX 的示例。首先使用复制和粘贴,然后使用 R。使用 tikzDevice 和 knitr 构建完成图形的方法在 Adam Liter 的出色回答中有所展示使用 tikzDevice 进行良好布局的最佳实践
我已经实现了一个非常简单的演示,使用 Excel 电子表格中的数据创建使用当前 LaTeX 字体的图形。这是使用 R 输入 Excel 数据并使用 tikzDevice 控制字体完成的。
\documentclass{article}
\usepackage{graphicx}
\begin{document}
\begin{center}\LARGE
\textbf{Using data contained in an Excel spreadsheet to create data tables and graphics in \LaTeX{} generated PDF}
\end{center}
An Excel spreadsheet has been saved as \textbf{dataandgraph.xlsx}. Now to get the data and the graphics into a PDF using \LaTeX{}.
\section{Copy and Paste Methods}
This approach is only useful for one-time graphics inclusions into \LaTeX. And you are very, very sure that there will be no editing or changes of the graphics. (This is rarely true for Excel graphics.)
\subsection{Copy graphic, paste to PowerPoint, Save as *.png}
This is quick and fairly easy to do. It is expecially useful if your workflow requires \LaTeX{} for the paper and PowerPoint for the presentations.
\includegraphics[width=.45\linewidth]{copypastetopptsaveaspng}
\subsection{Copy Data Table, paste to PowerPoint, Save as *.png}
This is quick and fairly easy to do. It is expecially useful if your workflow requires \LaTeX{} for the paper, Excel for data collection, and PowerPoint for the presentations.
\includegraphics[width=.45\linewidth]{CopyDataToPPTsaveAspng}
\section{Using the \textbf{R package xlsx} to read the \textit{*.xlsx} file and Knitr to move to \LaTeX{}}
\verb+http://www.sthda.com/english/wiki/+ \\
\verb+r-xlsx-package-a-quick-start-guide-to-manipulate-excel-files-in-r+.
Note: there is also a package \textbf{openxlsx} which offers more control on writing and reading of xlsx files from R.
\subsection{Using R to move the data table to \LaTeX{}}
This requires that the computer has R installed with the needed R packages. And that the user knows how to integrate the knitr and \LaTeX{} compile process. \verb+http://yihui.name/knitr/+
<<>>=
library(xlsx)
tt<- data.frame(read.xlsx('dataandgraph.xlsx',1))
str(tt)
tt
@
Using the Excel data to plot a graph.
<<out.width='3in'>>=
attach(tt)
plot(a,b,type="l")
@
\subsection{Now using the current \LaTeX{} font for the table}
Now the data output can be made to use \LaTeX{} fonts by xtable. Note: In the R-chunk all code output has been turned off.
<<echo=FALSE,results='asis'>>=
library(xtable)
tt<- data.frame(read.xlsx('dataandgraph.xlsx',1))
xtable(tt)
@
\clearpage
\subsection{Now using the current \LaTeX{} font for the graphics}
First a demo using a dataset built in to R and the packages ggplot2 and tikzDevice.
\begin{figure}[!h]
<<fig1,eval=TRUE,out.height='3in',echo=FALSE,dev='tikz'>>=
library(ggplot2)
library(tikzDevice)
qplot(displ, hwy, data = mpg, colour = factor(cyl))
@
\end{figure}
Now a plot from the data read in from the Excel spreadsheet. Note: the command \textit{library(tikzDevice)} only needs to be used once in a given *.Rnw file.
\begin{figure}[!h]
<<fig2,eval=TRUE,out.width='3in',echo=FALSE,dev='tikz'>>=
library(tikzDevice)
boxplot(tt$b~tt$number, col=rainbow(4),main="Using \\LaTeX{} Fonts")
@
\end{figure}
\end{document}