表格创建包的建议

表格创建包的建议

本文介绍了R/LaTeX 表格创建包的建议的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用 xtable 包很长时间了,并期待在 R 中编写我的第一个包......所以我认为如果我有一些很酷"的想法值得携带出去,很有可能有人在我之前到达那里...... =)

I've been using xtable package for a long time, and looking forward to writting my first package in R... so I reckon that if I have some "cool" idea that's worth carying out, there's a great chance that somebody got there before me... =)

我对专门用于创建 LaTeX 表的函数/包感兴趣(当然是通过 R).我碰到了具有 latex.table 功能的 quantreg 包.对类似功能/包有什么建议吗?

I'm interested in functions/packages specialized for LaTeX table creation (through R, of course). I bumped on quantreg package which has latex.table function. Any suggestion for similar function(s)/package(s)?

附:我正在考虑构建一个 web 应用程序,用户可以在其中定义自己的表格预设/模板、选择样式、统计信息等.不过,这是一个早期的想法...... =)

P.S.I'm thinking about building a webapp in which users can define their own presets/templates of tables, choose style, statistics, etc. It's an early thought, though... =)

推荐答案

我有时将创建 LaTeX 表格的任务分为两部分:

I sometimes divide the task of creating LaTeX tables into two parts:

  1. 我将直接在我的 LaTeX 文档中编写表格环境、标题和表格环境命令.
  2. 我将使用自定义函数从 R 中仅导出表格的主体.

R导出部分涉及几个步骤:从包含任何标题的整个表格的矩阵开始:

The R export part involves several steps:Starting with a matrix of the whole table including any headings:

  1. 将任何 LaTeX 特定格式添加到表格中.例如,将数字括在美元符号中,以确保正确显示负数.
  2. 通过将单独的列替换为与号 (&) 并添加行尾符号\",将行合并为单个字符值
  3. 添加要在表格中显示的任何水平线.我使用 booktabs LaTeX 包.
  4. 使用 write 函数导出生成的字符向量
  1. Add any LaTeX specific formatting to the table. E.g., enclose digits in dollar symbols to ensure that negative numbers display correctly.
  2. Collapse rows into a single character value by replacing separate columns with the ampersand (&) and adding ends-of-row symbols "\"
  3. Add any horizontal lines to be displayed in the table. I use the booktabs LaTeX package.
  4. Export the resulting character vector using the write function

然后使用 LaTeX 中的 input 命令导入导出的文本文件.我确保文件名与表格标签相对应.

The exported text file is then imported using the input command in LaTeX. I ensure that the file name corresponds to the table label.

我在撰写期刊文章时使用了这种方法.在这些情况下,有很多不同类型的表格(例如,多页表格、横向表格、需要扩展边距的表格、需要特定对齐的表格、我想要更改表格标题措辞的表格).在这个设置中,我发现从 R 中导出数据更容易.这样,结果是可重复的研究,但更容易在 LaTeX 文档中调整表格设计的各个方面.而在期刊文章的上下文中,通常没有太多的表格和特定的格式要求.

I have used this approach in the context of writing journal articles.In these cases, there are a lot of different types of tables (e.g., multi-page tables, landscape tables, tables requiring extended margins, tables requiring particular alignment, tables where I want to change the wording of the table title). In this setting, I've mostly found it easier to just export the data from R. In this way, the result is reproducible research, but it is easier to tweak aspects of table design in the LaTeX document. And in the context of journal articles, there are usually not too many tables and rather specific formatting requirements.

但是,我想如果我要生成大量批处理报告,我会考虑直接从 R 导出更多方面.

However, I imagine if I were producing large numbers of batch reports, I'd consider exporting more aspects directly from R.

这篇关于R/LaTeX 表格创建包的建议的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-30 00:44