使用DiagrammeR和Xaringan演示文稿居中显示图形

3
fig.align='center'不能使Xaringan演示中的Diagrammer图表居中。有什么想法吗?
请参见下面的reprex。
---
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]

这个 https://stackoverflow.com/questions/58689080/mermaid-diagrams-not-rendering-correctly-in-rmarkdown-xaringan-presentations 似乎适用于你的例子 - 虽然从下面的评论中可以看出颜色可能有限制。但是 jys 的答案有效。 - user20650
1个回答

5

我刚刚试过了:HTML标签<center>是有效的,并且应该是一个可行的解决方案。

只需在R代码之前添加它,并在末尾用</center>关闭即可。 虽然这在CSS术语上可能不太优雅,但它可以工作!

# TITLE

.center[Some text]

<center>

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

</center>

这是关于 Quarto Revealjs 演示文稿的问题,Quarto v 1.2.258 和 DiagrammeR v 1.2.258,上述修复方法解决了这个问题! - Elliot

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接