以下是选项 2 和 3 的解决方法,使用 Markdown 和 CSS 设置图像样式,使用 HTML+CSS 设置文本样式;此外,使用 base64 图像(透明 gif)生成器作为元素之间的空间分隔符。
当心空格! (在每行的末尾 - 放置两个空格并按 ENTER)
这些方法/黑客中的一种对您有用吗?如果不是,最好删除答案,这可能会误导其他人。
---
title: |
{width=300px}|
|:-:|
{width=300px style="display: block; margin:0 auto"}
{width=300px height=90px align=left}
{width=300px height=90px align=center}
{width=300px height=90px align=right}
{width=150px}
R Markdown Title
<center>R Markdown Title</center>
<p style="text-align: right;">R Markdown Title</p>
{width=150px}
author: "Author Name"
date: "08/03/2020"
---
使用 Markdown 表来“样式化”图像|-| (left-aligned), |:-:| (centered) and |-:| (right-aligned) 可以很好地处理简单的 RMarkdown 输出。
我意识到您在页面顶部的# top level heading 下有一张图片 - 带有top:0px。导致图像重复,并可能导致悬停问题:
<img src="https://i.imgur.com/GiViTbA.png" style="position:absolute;top:0px;height:100px;" />
替换为:
{width=50px style="display: block; margin:0 auto;"}
看看会发生什么。
---
title: |
{width=300px style="display: block; margin:0 auto;"}
{width=50px}
R Markdown Title
{width=50px}
output:
html_document: default
---
# I'm a top level heading {-}
{width=50px style="display: block; margin:0 auto;"}
Note, you need to replace the image with a local image if you want to show the image in the rstudio viewer.
The image will be visible in the html file created when you knit, if you open in a browser connected to the internet.
```{r echo=FALSE, message=FALSE, warning=FALSE}
plot(cars)
```
编辑:
让我们试着找到一个共同点,A Minimal Book Example,github here。
在index.Rmd进行的调整:
---
title: |
{height=300px}
author: "Author Name"
date: "`r Sys.Date()`"
site: bookdown::bookdown_site
output: bookdown::gitbook
---
# Prerequisites
<img src="https://i.imgur.com/GiViTbA.png" style="position:absolute;top:50px;height:300px;align:center;" />
This is a _sample_ book written in **Markdown**. You can use anything that Pandoc's Markdown supports, e.g., a math equation $a^2 + b^2 = c^2$.
index.Rmd 输出:
在Chapter: Introduction (01-intro.Rmd) 中进行的调整:
# Introduction {#intro}
{height=240px}
<img src="https://i.imgur.com/GiViTbA.png" style="position:absolute;top:50px;height:300px;align:center;" />
You can label chapter and section titles using `{#label}` after them, e.g., we can reference Chapter \@ref(intro). If you do not manually label them, there will be automatic labels anyway, e.g., Chapter \@ref(methods).
01-intro.Rmd 输出:
使用此解决方案,我们将使用 .png 图像“屏蔽”顶级标题 (# Introduction),该图像将作为文本显示在目录中。
缺点:此外显而易见的 hack,图片width 必须至少等于或大于顶级标题标题。