How to position and format length of a table's

2019-07-20 15:52发布

问题:

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.

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. position table's title (caption) above the table

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

  3. 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:

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}

回答1:

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.

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.

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.