Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using ftext function for fig.cap #19

Closed
RichardMeyer-Eppler opened this issue May 5, 2020 · 1 comment
Closed

Using ftext function for fig.cap #19

RichardMeyer-Eppler opened this issue May 5, 2020 · 1 comment
Labels
question Further information is requested

Comments

@RichardMeyer-Eppler
Copy link

Thank you for this awesome package, a lot of the new features are real game changers for me!

Is it possible to use the styling options provided by officer::ftext within the figure caption (fig.cap) of a code chunk?

My unsuccessful attempt was to first create a caption object:
test_caption <- officer::fpar(officer::ftext("hello", officer::shortcuts$fp_bold()))

which I then tried referencing in a chunk like this:
r, echo=FALSE, fig.cap=test_caption, fig.id='sinus', fig.width=6, fig.height=4, fig.align='center'

I know that you have added Math latex support to captions, but I would love combining, for example, two colors within one figure caption. At the moment, I am only aware of Claus Wilke's ggtext package for multi-colored captions - which have to be included as part of the figure. However, I would prefer a way of combining Word's image captions (for the numbering and so on) with officer's advanced formatting options (that exceed changing the "Image Caption" style in the reference.docx).

@davidgohel
Copy link
Owner

Yes, but you will have to recreate the caption from scratch. You will find below an example:

---
output: officedown::rdocx_document
---

```{r setup, include=FALSE}
library(officedown)
library(officer)
library(flextable)
fp_1 <- fp_text(color = "red")
fp_2 <- fp_text(color = "pink", bold = TRUE)
```

<!---BLOCK_TOC{seq_id: 'fig'}--->


::: {custom-style="Image Caption"}

<caption>
`r run_autonum(seq_id = 'fig', bkm = 'coco', pre_label = "Figure ")` `r ftext("This is red ",fp_1)` and `r ftext("this is pink ",fp_2)`
</caption>

:::

\@ref(fig:coco)


This is famous `mtcars` dataset:

```{r tab.cap='cars', tab.id='cars', first_column = TRUE}
qflextable(cars[1:10,])
```

aaaa

```{r tab.cap='mtcars', tab.id='mtcars', first_column = TRUE}
head(mtcars, n = 10)
```

This is a linked reference to a table: \@ref(tab:mtcars), its number is computed by Word 
and it's linked to the corresponding table when clicking on it.

This is a linked reference to an image: \@ref(fig:tsplot), its number is computed by Word 
and it's linked to the corresponding table when clicking on it.



```{r fig.cap="economics plot", fig.id = "tsplot", fig.cap.style="Image Caption"}
year <- function(x) as.POSIXlt(x)$year + 1900
with(ggplot2::economics, plot(date, unemploy / pop, type = "l"))
```


Capture d’écran 2020-05-12 à 13 58 33

@davidgohel davidgohel added the question Further information is requested label Feb 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants