使用 R `bookdown::gitbook` 我可以居中数字而不是标题吗?

With R `bookdown::gitbook` can I center figures but not the captions?

我正在尝试使用 bookdown::gitbook: 复制教科书的一部分。为了匹配它,我想让我的数字居中,但标题左对齐。当我指定 fig.align="center" 时,它还会将标题文本居中。字幕太长了,居中看起来很糟糕。有没有办法指定我想将图像居中但左对齐标题的文本?这是我拥有的:

---
title: "Notes for An Introduction to Statistical Learning with Applications in R, Second Edition"
author: "me"
date: "`r Sys.Date()`"
site: bookdown::bookdown_site
documentclass: book
output:
  bookdown::gitbook: 
    config: 
      toc:
        collapse: false
    fig_caption: true
    number_sections: true
    global_numbering: true

description: "Notes for ISLR2"
---

第 1 章

字数……更多字数……还有更多作品……

```{r fig1-3, cache=FALSE, echo=FALSE, fig.align="center", fig.cap="_We fit a quadratic discriminant analysis model to the subset of the `Smarket` data corresponding to the 2001–2004 time period, and predicted the probability of a stock market decrease using the 2005 data. On average, the predicted probability of decrease is higher for the days in which the market does decrease. Based on these results, we are able to correctly predict the direction of movement in the market 60% of the time._"}

knitr::include_graphics("./images/fig1_2.jpg", error = FALSE)

```

knitr 输出生成一个带有 class='caption' 的 html 元素,因此我们可以添加少量自定义 css 代码使其左对齐(我最喜欢的技巧之一在 html 输出中!):

```{r echo=F, results='asis'}
cat("<style>.caption{text-align:left;}</style>")
```

再次感谢@all-downhill-from-here。我通过添加 .css 文件让它工作。我不知道为什么带有“asis”或 css 块的 r chuck 不起作用。

我得到了这样的对齐和其他细节:

p.caption {
  text-align: left; 
  color: gray; 
  font-style: italic; 
}