【问题标题】:In RMarkdown, can a floating TOC be placed on the right side of page在 RMarkdown 中,是否可以在页面右侧放置浮动 TOC
【发布时间】:2020-03-02 15:36:56
【问题描述】:

当我向我的R-Markdown 文档添加浮动目录时,它始终位于页面的左侧(内容在右侧),如下所示:

---
title: "some title"
author: "me"
date: "3/2/2020"
output: 
  html_document:
    toc: TRUE
    toc_float: TRUE
---


但是,我想将浮动目录移动到页面的右侧。我怎样才能做到这一点?下图就是我想要的:


【问题讨论】:

    标签: html r r-markdown


    【解决方案1】:

    R HmischidingTOC 功能做到了这一点,允许更改显示的一些特性,并提供标记为 1 2 3 的按钮,读者可以单击以将目录显示到级别 1,级别1-2,1-3级。不需要特殊的yaml;只需在您的设置块中添加require(Hmisc) 并在该块之后的某个时间添加内联文本:r hidingTOC(buttonLabel="Outline") 或仅使用默认值。您也可以只说r Hmisc::hidingTOC() 作为内联 R 代码。不需要将这些命令放在一个块中;它们呈现自动包含在文档中的 HTML。

    【讨论】:

      【解决方案2】:

      在下方插入 CSS 块(在 YAML 之后)并尝试增加/减少 px 的值(rightmargin-left)进行微调:

      ---
      title: "some title"
      author: "me"
      date: "3/2/2020"
      output: 
        html_document:
          toc: TRUE
          toc_float: TRUE
      ---
      
      ```{css toc-content, echo = FALSE}
      #TOC {
        right: 270px;
        margin: 20px 0px 25px 0px;
      }
      
      .main-container {
          margin-left: 200px;
      }
      ```
      

      【讨论】:

      • 行得通,谢谢!当我在 github 上打开 RMarkdown 包的功能请求时,我将链接到这篇文章,如果在 yaml 中有一个像 toc_side: right 这样的简单选项,那就太好了
      • 这将是一个方便的功能。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-03-09
      • 2023-03-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-12-05
      • 2021-10-12
      相关资源
      最近更新 更多