Reputation: 1191
I am trying to knit a document using RMarkdown into a pdf document. I want to remove the section numbers by default. I thought that the number_section:FALSE
would do this, but it isn't. I've stripped down to an MWE and I'm still getting section numbers.
In the knitted report.tex
file, the section that I specifically label as not having a number using {-}
is tagged as \section*{...}
, whereas the other sections are tagged with \section{...}
which is how you would accomplish numbering some sections in LaTeX, however I would like all sections to be knitted as \section*{...}
without having to specify {-}
in each section (or subsection).
I am using pandoc version 2.11.2
, RStudio version 1.4.1103
and R version 4.0.3
Here are my source files:
report.Rmd
:
---
output:
pdf_document:
template: template.tex
keep_tex: TRUE
number_sections: FALSE
---
# Abstract {-}
# Introduction
## A Subsection
# A Second Section
template.tex
:
\documentclass{article}
\usepackage{hyperref}
\begin{document}
$body$
\end{document}
The pandoc call in the RMarkdown output is shown as (I added the newlines to make it easier to read), notice it does not include --number-sections
, which is usually used to tell pandoc to enforce numbering, by default pandoc should not number them.
"C:/Program Files/RStudio/bin/pandoc/pandoc"
+RTS -K512m -RTS report.utf8.md
--to latex
--from markdown+autolink_bare_uris+tex_math_single_backslash
--output report.tex
--lua-filter "C:\Users\MichaelBarrowman\Documents\R\R-4.0.3\library\rmarkdown\rmarkdown\lua\pagebreak.lua"
--lua-filter "C:\Users\MichaelBarrowman\Documents\R\R-4.0.3\library\rmarkdown\rmarkdown\lua\latex-div.lua"
--self-contained
--template template.tex
--highlight-style tango
--pdf-engine pdflatex
This knits to the following report.tex
file:
\documentclass{article}
\usepackage{hyperref}
\begin{document}
\hypertarget{abstract}{%
\section*{Abstract}\label{abstract}}
\addcontentsline{toc}{section}{Abstract}
\hypertarget{introduction}{%
\section{Introduction}\label{introduction}}
\hypertarget{a-subsection}{%
\subsection{A Subsection}\label{a-subsection}}
\hypertarget{a-second-section}{%
\section{A Second Section}\label{a-second-section}}
\end{document}
Which is rendered as report.pdf
and looks like this:
Upvotes: 0
Views: 1276
Reputation: 16920
Your problem here seems to be that you're using a custom LaTeX template, but haven't put anything into that template to deal with turning section numbering on or off. For reference, here's how the pandoc default LaTeX template handles this:
$if(numbersections)$
\setcounter{secnumdepth}{$if(secnumdepth)$$secnumdepth$$else$5$endif$}
$else$
\setcounter{secnumdepth}{-\maxdimen} % remove section numbering
$endif$
(Seen on lines 306--310 here).
So, if you want to deal with this and use your own custom template, you have to handle that yourself (perhaps even just by copy-pasting what the default template does).
When I edit your template.tex
like that:
\documentclass{article}
\usepackage{hyperref}
$if(numbersections)$
\setcounter{secnumdepth}{$if(secnumdepth)$$secnumdepth$$else$5$endif$}
$else$
\setcounter{secnumdepth}{-\maxdimen} % remove section numbering
$endif$
\begin{document}
$body$
\end{document}
I get the result I think you want:
Upvotes: 3