0
votes

I am using RStudio and RMarkdown to generate reports. I now wish to edit parts of the document. My RMarkdown document is as follows:

--
title: <center> <h1>Call Centre Report</h1> </center>
mainfont: Arial
output:
  pdf_document:
    latex_engine: xelatex
sansfont: Arial
fig_crop: false
toc: true
classoption: landscape
fontsize: 14pt
geometry: margin=0.5in
header-includes:
- \usepackage{booktabs}
---
<style>
  .main-container {
    max-width: 1200px !important;
  }
</style>

```{r global_options, R.options=knitr::opts_chunk$set(warning=FALSE, message=FALSE)}
```
\newpage
# Iris 
```{r fig.width=18, fig.height=7, echo=FALSE, comment=" "}
library(ggplot2)
ggplot(data = iris, aes(x = Sepal.Length, y = Sepal.Width, colour = Species)) +
   geom_point() +
   theme_classic()
```
<br>
<br>
```{r, echo=FALSE, results='asis'}
library(knitr)
library(xtable)

t1 <- kable(subset(iris, Sepal.Length=="5.1", select = Petal.Length:Species),
            format = "latex", booktabs = TRUE, row.names = FALSE)
t2 <- kable(subset(chickwts, feed=="horsebean", select = weight:feed), 
            format = "latex", booktabs = TRUE, row.names = FALSE)
t3 <- kable(subset(mtcars, gear=="4", select = disp:wt), 
            format = "latex", booktabs = TRUE, row.names = FALSE, digits=2)

cat(c("\\begin{table}[!htb]
    \\begin{minipage}{.35\\linewidth}
      \\centering",
        t1,
    "\\end{minipage}%
    \\begin{minipage}{.35\\linewidth}
      \\centering",
        t2,
    "\\end{minipage}%
    \\begin{minipage}{.35\\linewidth}
      \\centering",
        t3,
    "\\end{minipage} 
\\end{table}"
)) 
```

Is it possible to remove the heading "Contents" on the TOC page? I wish to keep all other headings on this page but remove only the "Contents" heading.

I know that I can edit the "Table of Contents" by the following line:

- \renewcommand{\contentsname}{Some Text Here}

But simply leaving it blank (below), still takes up space:

- \renewcommand{\contentsname}{}
2
If using Latex you might have to do something like this: tex.stackexchange.com/questions/55080/…Marius
Or just combine \renewcommand{\contentsname}{} with a negative vspace: \vspace{-.5cm}Martin Schmelzer
The command - \renewcommand{\contentsname}{}\vspace{-.5cm} does remove the Table of Contents but it doesn't push the text up into where the heading formally was. Hence, there is still a white space.user2716568

2 Answers

2
votes

I was trying to solve a similar issue, plus some others. Using the comment, I ended up with the below code. Table of contents now can be placed anywhere, without the "Contents" word and without whitespace.

---
output:
  pdf_document:
    fig_caption: true
    number_sections: true
header-includes:
    - \renewcommand{\contentsname}{}

title: Title Name
author: Author Name
---

Some text 

Some more text 

\vspace{-1cm}
\tableofcontents

# Section Name 

Some more text 

\newpage

# Section 2 Name 

## Subsection 2.1
-1
votes

you could try to delete the line toc:true in your YAML metadata. It worked on my case.