2

I try to style the chapters (sections) of an article document (documentclass: article) using the latex titlesec package, but I don't get any results, I mean that when I configure the document there is no change.

In the YAML header of rmarkdown

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

Outside the YAML header


<!-- 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}{\thesection\hsp\textcolor{gray75}{|}\hsp}{0pt}{\Huge\bfseries}

In the .tex file the code of the chapter (section):


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


3
  • Welcome to TeX.SE!
    – Mensch
    Oct 30, 2021 at 22:27
  • Please provide an MWE (from \documentclass... to `\end{document}) that we can compile that shows your problem. Why should you expect us to try and assemble what you have done from your snippets? --- GOM Oct 31, 2021 at 18:50
  • sorry. the document is very long. I thought it was enough. I don't want to cause any inconvenience to anyone. I thought it could be a common configuration problem. Oct 31, 2021 at 19:30

1 Answer 1

1

As you noted, there are no chapters but sections in an article document class. Therefore, it's funny that you try to redefine a command that does not exist. On the other hand, it is not clear to me what are you trying to do with \titleformat, but I guess that you are searching for some like this:

mwe

---
docummentclass: article
output:
  pdf_document: 
    number_sections: yes
header-includes:
- \usepackage{titlesec, xcolor, lipsum}
# \titleformat{command}[shape]{format}{label}{sep}{before-code}[after-code]
- \titleformat{\section}{\Huge\bfseries}{\thesection\hspace{20pt}\textcolor{gray!75}{|}}{20pt}{}
---

# Introduction
\lipsum[1][1-5]

# Objectives
\lipsum[1][6-9]
3
  • I used your code above and got a big space between all chapter title words Jan 20 at 14:06
  • @MarkDavies With Rstudio and TexLive this example produces what you see here, that have no chapters (article documents have no chapters without a special tunning). Therefore, seems that you are not using only my code but something else, and that is your problem but that only you know. So what could I tell you more?
    – Fran
    Jan 22 at 12:38
  • Thanks. I have asked a new question: tex.stackexchange.com/questions/707695/… Jan 22 at 22:24

You must log in to answer this question.

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