如何在动态文档 R 和 knitr 中创建自定义章节标题

How to create customized chapter heading in a Dynamic Document R and knitr

我不是 LaTex 用户...实际上开始学习一些关于动态文档的结果是我正在为书籍文档工作 class 我正在写 Rknitr

我试过自定义章节标题,但同时我没有得到....我通过 LaTex (https://tex.stackexchange.com/questions/73421/how-to-create-specific-chapter-style-in-book-documentclass) 找到了这样做的方法,但是我不知道如何解决通过 RMardkown

有人可以帮我吗?如何安排以下 LaTex 命令由 RMarkdown(由 .sty 文件触发?)或类似的方式来自定义输出 pdf 中的章节标题?

\documentclass{book}
\usepackage{titlesec} 
\usepackage{lipsum} % just to generate text for the example

\titleformat{\chapter}[display]
  {\bfseries\Large}
  {\filright\MakeUppercase{\chaptertitlename} \Huge\thechapter}
  {1ex}
  {\titlerule\vspace{1ex}\filleft}
  [\vspace{1ex}\titlerule]

谢谢

法比奥

你可以把你想要的东西放在 header 中,除了 documentclass 行,放在一个单独的 tex 文件中(我在下面使用 header.tex)。然后,您可以在 R-markdown 文件的 header 中指定要将此文件包含在 header 中。 documentclass 货车也可以在 R-markdown 文件的 header 中设置。有关这方面的更多信息,请访问 rstudio site.

下面举例:

---
title: "Untitled"
output: 
  pdf_document:
    includes:
      in_header: header.tex
documentclass: book
---

\chapter{Introduction}


Section
=======

This is an R Markdown document. 

header.tex 看起来像:

\usepackage{titlesec} 
\usepackage{lipsum} % just to generate text for the example

\titleformat{\chapter}[display]
  {\bfseries\Large}
  {\filright\MakeUppercase{\chaptertitlename} \Huge\thechapter}
  {1ex}
  {\titlerule\vspace{1ex}\filleft}
  [\vspace{1ex}\titlerule]