1

I would like to increase the font size of my chapter titles. I am producing a pdf using bookdown package in rmarkdown. I have followed this answer, but I get the result that my chpater headings are now spread across the page with large gaps between words.

This is my code:

---
output: 
  bookdown::pdf_document2:
    toc: false
    latex_engine: xelatex
header-includes:
- \usepackage{lmodern}
- \pagenumbering{gobble}
- \usepackage{titlesec}
- \titleformat{\section}{\Huge\bfseries}{\thesection\hspace{20pt}}{20pt}{}
mainfont: Times New Roman
fontsize: 12pt
linestretch: 1.5
geometry: "left=2.5cm,right=2cm,top=2cm,bottom=2cm"
---
\center
Title page contents

\raggedright
\newpage
\pagenumbering{roman}

# Preface {.unlisted .unnumbered}
Preface contents

\newpage

``` {=latex}
\setcounter{tocdepth}{3}
\tableofcontents
\listoffigures
\listoftables
```
\newpage
\pagenumbering{arabic}

# Chapter 1 Heading

## First sub-section

# Another example chapter heading

And here is result:

enter image description here enter image description here

How can I increase the font size of my chapter (level 1 section) headings without causing all section titles to have added spaces between words?

1
  • To me, those headings look more like they are right and left justified, when realistically, the headings should be \raggedright. I don't have access to the titlesec manuals right now, but I would suggest adding \raggedright just after (or before) \Huge\bfseries in the title definition.
    – enkorvaks
    Commented Jan 23 at 1:35

1 Answer 1

0
  1. Is is always a good idea use keep-tex to know what are you doing really in LaTeX.

  2. You have not chapters here, you are making article-like documentclass (scrartcl) that have no chapter but sections as first header level and trying to simulate the book format. Suggestion: switch to a book-like document class.

  3. You are trying to use Times New Roman and Latin Modern Roman together. Times is strongly discouraged in this site, and I have not this font, so the example is set to Latin Modern.

  4. The geometry changes are just to crop the height of screeshot (irrelevant for the issue).

  5. Finally, but not less important, The issue is caused by:

    \center % <--- This is the problem 
    Title page contents
    \raggedright

But you can make better you title page in this way:

MWE

---
output: 
  bookdown::pdf_document2:
    toc: false
    latex_engine: xelatex
    keep-tex: yes
header-includes:
- \pagenumbering{roman}
- \usepackage{titlesec}
- \titleformat{\section}{\Huge\bfseries}{\thesection\hspace{20pt}}{20pt}{}
mainfont: Latin Modern Roman
fontsize: 12pt
linestretch: 1.5
geometry: paperheight=14cm,left=2.5cm,right=2cm,top=.5cm,bottom=1.5cm
---



```{=tex}
\begin{titlepage}
\centering
\Huge Title page contents
\end{titlepage}
```
# Preface {.unlisted .unnumbered}
Preface contents
    
``` {=tex}
\newpage
\setcounter{tocdepth}{3}
\tableofcontents
\listoffigures
\listoftables
\newpage
\pagenumbering{arabic}
```
# ~~Chapter~~ Section 1 Heading

## First sub-section

# Another ~~chapter~~ section heading

## Second sub-section

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .