0

I am using "article" class to write a report. Instead of using conventional section and subsections, I have defined new commands which I want to use in table of contents.

\newcommand{\CentreHeading}[1]{\begin{center} \begin{large} \MakeUppercase{\textbf{#1}} \end{large} \end{center} \vspace*{28pt} \addcontentsline{toc}{section}{#1}}

Now, instead of using section command, I want to use \CentreHeading command to define sections and their arguments to appear in the table of contents.

A minimal MWE is given below:

\documentclass{article}
\usepackage{titlecaps}

\newcommand{\CentreHeading}[1]{\begin{center} \begin{large} \MakeUppercase{\textbf{#1}} \end{large} \end{center} \vspace*{28pt} \addcontentsline{toc}{chapter}{#1}}

\begin{document}
    \tableofcontents
    \newpage
    
    \CentreHeading{First Section}
    Foo bar boo bar
    
    \CentreHeading{Second Section}
    Again foo bar  boo bar
\end{document}
2
  • In the \addcontentsline command, replace chapter by section. The article class has no chapters.
    – gernot
    Nov 8, 2020 at 17:26
  • @gernot Thank you.
    – Ali Baig
    Nov 8, 2020 at 17:35

1 Answer 1

1

You are using the article class which knows nothing about chapters.

% tocentryprob.tex  SE 570050

\documentclass{article}
\usepackage{titlecaps}

\newcommand{\CentreHeading}[1]{\begin{center} \begin{large}
  \MakeUppercase{\textbf{#1}} \end{large} \end{center} \vspace*{28pt}
  %%% \addcontentsline{toc}{chapter}{#1}}  % not that but this
  \addcontentsline{toc}{section}{#1}}

\begin{document}
    \tableofcontents
    \newpage
    
    \CentreHeading{First Section}
    Foo bar boo bar
    
    \CentreHeading{Second Section}
    Again foo bar  boo bar
\end{document}

In the \addcontentsline change chapter to section.

1
  • Thank you for you answer.
    – Ali Baig
    Nov 8, 2020 at 17:36

You must log in to answer this question.

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