如何定位和设置表格标题的长度[R Markdown,pander包] [英] How to position and format length of a table's title [R Markdown, pander package]

查看:164
本文介绍了如何定位和设置表格标题的长度[R Markdown,pander包]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在准备pdf格式的R Markdown文件.在文档中,我有几个表.我使用了 pander 包来格式化表格.假设我有数据框DF,我想将其转换为pdf输出中的表格.为了在r代码块中实现此目的,我为表标题前缀更改了 panderOptions 以便以非英语语言打印它,并在下一行中使用指定的标题参数调用pander函数.

I am preparing R Markdown document in the pdf format. In the document I have a couple of tables. I used pander package to format tables. Suppose that I have data frame, DF, that I want to transform into table in the pdf output. To achieve that in a r code chunk I changed panderOptions for table caption prefix in order to print it in NON-English language and in the next line I call pander function with specified caption argument.

以下是R Markdown代码的相关部分:

Here is relevant part of R Markdown code:

---
title: "Let's try!"
author: "Newbie_R"
date: "Monday, December 15, 2014"
output: pdf_document
---


```{r setoptions, echo = F, message=FALSE}
library (knitr)
library (pander)
opts_chunk$set(echo = F)
```


```{r DF}
    vm <- 3/2 + 4/2
    jl <- vm
    ik <- 2+4
    sr <- 3 + 4/2
    lb <- 4
    dk <- 3
    zb <- 3
    ss <- 2

    DF <- data.frame (VM = vm,
                       JL = jl,
                       IK = ik,
                       SR = sr,
                       LB = lb,
                       DK = dk,
                       ZB = zb,
                       SS = ss)

```
Try to make a table!!!



```{r panderTable}
    panderOptions("table.caption.prefix", "XXXXXX 1: ")
    pander (DF, caption = "This is a very long table's title that should be printed above the table; Also, I would like format it to match boundaries of a length of the table")
```

输出不是我想要的方式.我要:

The output is not the way I would like. I want to:

  1. 表上方位置表的标题(标题)

  1. position table's title (caption) above the table

以与表格长度匹配的方式设置表格标题的长度(在表格边界内换行)

format length of table's title in a way that matches length of the table (wrap text within table's boundaries)

将桌子移到下面,尝试做一张桌子!!!"不属于r代码块的文本.请注意,与表格标题相比,尝试制作表格"文本离表格更近.

move table a bit bellow "Try to make a table!!!" text which is not a part of the r code chunk. Note that the "Try to make a table" text is more closer to the table compared to the table's title.

UPDATE1:

此链接将直接指向原始输出.与此相反,我希望做类似的事情.

This link will direct to the original output. Instead to that one, I want to make something like this.

UPDATE2:

此GitHub网页,您可以找到有关将标题放在表格顶部的选项的问题. @daroczig 说,这不是与pander相关的问题.但是他建议如何实现.我应该在哪里将代码行放在@daroczig建议的下面?

On this GitHub web page, one can find issue regarding option to place title on the top of a table. @daroczig said that it is not an issue connected with pander. However he suggested how it could be achieved. Where should I put code lines provided below which @daroczig suggested?

\usepackage{floatrow}
\floatsetup[table]{capposition=top}
\floatsetup[figure]{capposition=top}

推荐答案

好吧,这不是pander甚至不是降价问题,因为Pandoc的mardown有

Well, this is not a pander and not even a markdown issue as Pandoc's mardown has a definite syntax on where to put the caption: it should be placed below the table in markdown.

但是在将markdown转换为HTML或PDF之后,您可以自由地将标题替换(重新)到任何地方,因为Pandoc将markdown表转换为常规的table LaTeX环境,可以通过上述方法轻松地对其进行自定义引用的floatrow程序包.

But after transforming markdown to HTML or PDF, you had the freedom to (re)place that caption wherever you wish, as Pandoc converted the markdown table to a regular table LaTeX environment, which could be easily customized by the above referenced floatrow package.

不幸的是,这不再可能了,因为Pandoc使用longtable而不是tablectable,其中标题的位置由Pandoc的版本定义:它用于将标题放置在表格下方,但是由于最近提交,标题位于表格上方.有关更多详细信息,请参阅Pandoc邮件列表上的相关主题.

Unfortunately this is no longer possible, as Pandoc uses longtable instead of table or ctable, where the placement of caption is defined by Pandoc's version: it used to put the caption below the table, but since a recent commit, captions are placed above tables. For more details, see the related thread on Pandoc's maillist.

这篇关于如何定位和设置表格标题的长度[R Markdown,pander包]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆