4

我正在使用 tufte R 包创建带有边注的 html 文档。我的一些边注是相当高的数字。例如:


    ---
    title: Big sidenote
    output:
      tufte::tufte_html: default
    ---

    ```{r setup, include=FALSE}
    library(tufte)
    # invalidate cache when the tufte version changes
    knitr::opts_chunk$set(tidy = FALSE, cache.extra = packageVersion('tufte'))
    options(htmltools.dir.version = FALSE)
    ```


    ```{r fig.margin = TRUE, fig.cap="Fig1. My margin figure is kind of tall.", echo=FALSE}

    plot(mtcars)

    ```

    Here is paragraph 1. It's pretty short and it's associated with Fig 1.

    ```{r fig.margin = TRUE, fig.cap="Fig 2. Related to the second paragraph.", echo=FALSE}

    plot(subset(mtcars, cyl==6))

    ```

    I'd like this paragraph to start in line with Fig 2.
    ```

     I would like the paragraph in the main body to begin below the bottom of the figure in the margin.

问题说明

这可能在降价中吗?我的 CSS 技能/理解是有限的。

4

1 回答 1

3

我想通了。对于那些熟悉 CSS 的人来说很简单,但对于那些不了解 CSS 的人来说。边注是使用浮动属性创建的。您可以使用 float 属性来禁止浮动元素位于文本的一侧。

我创建了一个新的“已清除”类来清除右侧的元素:

<style>
  .cleared {clear: right;}
</style>

然后,每当我希望文本跳到下一个图时,我创建了一个已清除类的 div:

<div class = "cleared"></div>

这是完整的示例:

---
title: Big sidenote
output:
  tufte::tufte_html: default
---

<style>
  .cleared {clear: right;}
</style>

```{r setup, include=FALSE}
library(tufte)
# invalidate cache when the tufte version changes
knitr::opts_chunk$set(tidy = FALSE, cache.extra = packageVersion('tufte'))
options(htmltools.dir.version = FALSE)
```


```{r fig.margin = TRUE, fig.cap="Fig1. My margin figure is kind of tall.", echo=FALSE}
plot(mtcars)
```

Here is paragraph 1. It's pretty short and it's associated with Fig 1.

<div class = "cleared"></div>

```{r fig.margin = TRUE, fig.cap="Fig 2. Related to the second paragraph.", echo=FALSE}
plot(subset(mtcars, cyl==6))
```

I'd like this paragraph to start in line with Fig 2.

结果:

在此处输入图像描述

于 2020-01-02T18:12:42.913 回答