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

1.9k views Asked by At

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

1

There are 1 answers

1
daroczig On BEST ANSWER

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.