# How to format only one section of RMarkdown pdf output using sectsy

I am creating a pdf using R-markdown. I want ALL section headings to be centered (using sectsty package),except the first one which should be left aligned. How can I do this ? How do I use sectsty for only one section ?

Here is a minimal working example :

---
date : 2018-April-25
output:
pdf_document:
toc: true
toc_depth: 1
title: "Test document"
fontsize: 12pt

- \usepackage{booktabs}
- \usepackage{sectsty} \allsectionsfont{\centering}
---

\sectionfont{\left}

## This is a second heading.

• Welcome to TeX.SX! – Bobyandbob Apr 25 '18 at 11:48
• There is no \left command (well there is, but it doesn't do what you think it does). Just use \sectionfont{} – Alan Munn Apr 25 '18 at 15:10

What you tried didn't work because the \left macro is a mathmode macro for making an extensible left delimiter. Your document should have generated an error if compiled, but maybe it gets hidden from you.

Try the following:

---
title: "secsty-test"
date: "4/25/2018"
output: pdf_document
- \usepackage{booktabs}
- \usepackage{sectsty} \allsectionsfont{\centering}
---
\allsectionsfont{\raggedright}

• @user2338823 Sorry I tested with a LaTeX document not an Rmd document. I've updated with a sample Rmd. Is this what you want? – Alan Munn Apr 26 '18 at 3:46