RMarkdown生成报告模板

158 阅读1分钟

1.表格的Html写法

Excel表格转换:tableconvert.com/excel-to-ht… 使用的是html的写法,相对简单,容易上手。

这行代码能让标题居中

2.表格美化

<center>Table1.Target gene primer sequences<br/> 


为了将表格的形式丰富一些,可以添加其他参数。

<table class="table-bordered table-striped table-condensed">

table-bordered#加边框
table-striped#奇数行加上灰底
table-condensed#压缩字体及多余空格,适应字体

table-condensed是一个比较有意思的选项,用与不用是有区别的。个人觉得还是加上会更美观一些。具体效果如下所示:

No table-condensed

table-condensed

3.添加目录

    title: "Nanopore_kit"
    author: "Ribosome"
    date: "4/25/2022"
    output: 
      html_document:
        toc: TRUE # table of content true
        toc_depth: 3  # upto three depths of headings (specified by #, ## and ###)
        number_sections: true  ## if you want number sections at each table header
        theme: united  # many options for theme, this one is my favorite.
        highlight: tango  # specifies the syntax highlighting style

 在这里,代码的缩进很重要,而且是严格的缩进两个字符。虽然R对于缩进要求不严格,但是这个代码与yaml格式有关,所以如果没有正确缩进会报错。
 另外,首次添加目录时,在knit的时候,请看清楚,选择knit to HTML这个选项,有时可能会出现knit to TOC这个选项,这里是一个莫名其妙的坑,反正我踩过。

---
title: "TRPV1_proj"
author: "Ribosome"
date: '2023-11-12'
output: 
  html_document:
    toc: TRUE 
    toc_depth: 3  
    number_sections: true 
    toc_float: true
    collapsed: false
    smooth_scroll: false
    theme: united 
    highlight: tango 
    fig_width: 3 
    fig_height: 2
---

这里提供目录折叠和滚轮操作,以及多图拼接时的几种格式限定。其他的还在测试中。