3

fig.align='center' won't center Diagrammer plots in Xaringan presentation. Any thoughts?

See reprex below.

---
title: "Title"
encoding: "UTF-8"
output:
  xaringan::moon_reader:
    self_contained: true
    lib_dir: libs
    css: [default]
    nature:
      highlightStyle: github
      highlightLines: true
      countIncrementalSlides: false
      ratio: "16:9"
---

exclude: true

```{r setup, include=FALSE}
knitr::opts_chunk$set(
  echo = FALSE,
  warning=FALSE,
  message=FALSE,
  comment = NA)
```

---

# TITLE

.center[Some text]

```{r title, out.height='50%', fig.align='center'}

DiagrammeR::grViz("

digraph {

  # a 'graph' statement
  graph [layout = twopi, overlap = false]

  # several 'node' statements
  node [shape = circle,
        fontname = 'Century Gothic',
        style = filled,
        color = white,
        fontcolor = white]
        
  node [fillcolor = steelblue]
  Hello; How; You; Doing
  
  node [label =
'Im a reprex']
  reprex1
  
  node [label =
'im also a reprex']
  reprex2
  
  node [fillcolor = coral,
        label =
'thats weird,
im a reprex too!']
  reprex3
  
  edge [color = grey]
  reprex1 -> {Hello; How; You; Doing; reprex2; reprex3}
  reprex3 -> reprex1

}
")
```

.center[yet another text]
Alberson Miranda
  • 1,248
  • 7
  • 25
  • This https://stackoverflow.com/questions/58689080/mermaid-diagrams-not-rendering-correctly-in-rmarkdown-xaringan-presentations seems to work for your example -- although from the comments underneath there may be limitations on colours. But answer fom jys works. – user20650 Jul 13 '20 at 21:24

1 Answers1

5

I just tried: the HTML <center> tag works and should be a workable solution.

Just add it before the R code and close with at the end. This is perhaps not elegant (in CSS term) but it works!

# TITLE

.center[Some text]

<center>

```{r title, out.height='50%', fig.align='center'}
ETC.

</center>
jys
  • 121
  • 7
  • This is an issue with quarto revealjs presentations, quarto v `1.2.258` and DiagrammeR v `1.2.258`, and the above fix does the trick! – Elliot Nov 09 '22 at 01:01