Fábio Salles
Fábio Salles

Reputation: 365

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

I´m not a LaTex user...actually started learning something about it as consequence of dynamic document I´m working with for a book document class I´m writing in R and knitr.

I´ve tried to customize the chapter headings, but meanwhile I did not get....I found the way to do this by LaTex (https://tex.stackexchange.com/questions/73421/how-to-create-specific-chapter-style-in-book-documentclass) however I´m not knowing how to address by RMardkown.

Does anybody could help me with that? How can I arrange the below LaTex commands to be triggered by RMarkdown (by .sty file?) or something similar way to customize the chapter heading in output 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]

Thanks

Fabio

Upvotes: 3

Views: 1804

Answers (1)

Jan van der Laan
Jan van der Laan

Reputation: 8105

You can put the stuff you want in the header, except the documentclass line, in a seperate tex file (I use header.tex below). You can then specify in the header of your R-markdown file that you want to include this file in the header. The documentclass van also be set in the header of your R-markdown file. More info on this can be found on the rstudio site.

Below an example:

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

\chapter{Introduction}


Section
=======

This is an R Markdown document. 

header.tex looks like:

\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]

Upvotes: 4

Related Questions