How to emphasize column names (header) when using pandoc in R
Asked Answered
D

1

5

I know of the emphasize.rownames argument but have not been able to find its equivalent for column names. Attempted to look into panderOptions --> header.style to no avail.

Please find some test code below that emphasizes the first column but not its header. Ideally, I'd be able to specify which column names I'd like to emphasize but will be happy enough if I can at least emphasize the entire header. Thanks.

library(pander)
test = data.frame(Model = 1:3, Score = c(87,32,98), IQ = c(110,180,98))

# Print out the dataframe as a table using pander
pandoc.table(test, emphasize.strong.cols = 1)

EDIT To clarify - I am looking to create a table in a PDF document using rmarkdown, knitr and pander. Here is example code - I'd like the header to be emphasized, but it is not by default on my machine:

---
title: "myexample"
output: pdf_document
---

```{r myexamp_setup, message = FALSE, echo=FALSE}
require(pander)
require(knitr)
test = data.frame(Model = 1:3, Score = c(87,32,98), IQ = c(110,180,98))
```

```{r myexamp_tab, echo = FALSE, results = 'asis'}
pandoc.table(test, emphasize.strong.cols = 1)
```

A screenshot of the resulting PDF table: pandocexample

Deil answered 16/6, 2015 at 12:1 Comment(1)
There is no option to emphasize the column names as the header automatically gets highlighted when exporting to HTML or PDF etc. when using pandoc. If not, it depends on the stylesheet you are using. Can you share some more details on your use case?Folkway
F
7

Please consider opening a ticket on GitHub for this feature request -- but until this is not supported, I hope the following workaround might help:

> names(test) <- pandoc.strong.return(names(test))
> pander(test, emphasize.strong.cols = 1)

--------------------------------
 **Model**   **Score**   **IQ** 
----------- ----------- --------
   **1**        87        110   

   **2**        32        180   

   **3**        98         98   
--------------------------------

Also, I grab the chance to suggest using the generic pander method instead of pandoc.table. You save 6 characters each time you type it :) And it has some very cool extra features.

Folkway answered 17/6, 2015 at 6:28 Comment(1)
I found this useful when exporting to docx -- thanks!Fusain

© 2022 - 2024 — McMap. All rights reserved.