首页 > 解决方案 > 使用 knitr PACKAGE LATEX "titlesec" 从 rstudio 更改 .pdf 文档的章节样式

问题描述

我尝试使用latex titlesec包对文章文档(documentclass:article)的章节(sections)进行样式设置,但没有得到任何结果,我的意思是当我配置文档时没有任何变化。

在 rmarkdown 的 YAML 标头中

header-includes:
## Style Chapter - package "TITLESEC"
  - \usepackage[T1]{fontenc}
  - \usepackage{titlesec, blindtext, color}

在 YAML 标头之外


<!-- TITLESEC - Estilo CAPÍTULOS -->
\definecolor{gray75}{gray}{0.75}
\newcommand{\hsp}{\hspace{20pt}}
\titleformat{\chapter}[hang]{\Huge\bfseries}{\thechapter\hsp\textcolor{gray75}{|}\hsp}{0pt}{\Huge\bfseries}
\titleformat{\section}[hang]{\Huge\bfseries}{\thechapter\hsp\textcolor{gray75}{|}\hsp}{0pt}{\Huge\bfseries}

在 .tex 文件中章节(section)的代码:


\hypertarget{name-section}{%
\section{Name Section}\label{name-section}}


标签: ryamllatexr-markdownknitr

解决方案


我为你做了一个工作模板。

您可以根据需要进一步调整它。

---
title: "test"
header-includes: 
- \usepackage[T1]{fontenc}
- \usepackage{titlesec, blindtext, color}
output:
  pdf_document:
    toc: true
    number_sections: true
documentclass: report 
---

\definecolor{gray75}{gray}{0.75}
\newcommand{\hsp}{\hspace{20pt}}
\titleformat{\chapter}[hang]{\Huge\bfseries}{\thechapter\hsp\textcolor{gray75}{|}\hsp}{0pt}{\Huge\bfseries}

\chapter{RMarkdown}

\chapter{Stackoverflow}

推荐阅读