# Fix ToC entries created by a custom sectioning command

CHAPTER ONE
INTRODUCTION


produced with the following code

\newcommand{\mychapter}[2]{

\setcounter{chapter}{#1}

\setcounter{section}{0}
\chapter*{#2}
}
\usepackage{indentfirst} % to make indent from first paragraph
\begin{document}

\titlespacing*{\chapter}{10pt}{0pt}{10pt}
\titleformat{\chapter}[display]
{\centering\normalfont\large\bfseries}{ \chaptertitlename\ \thechapter}{40pt}{\large}
\tableofcontents

\mychapter{1}{CHAPTER ONE\\INTRODUCTION}
\end {document}


So, the question is: How can I have "CHAPTER ONE" and "INTRODUCTION" in one line?

• Please post a full MWE. – Ingmar Dec 6 '13 at 13:12
• Welcome to TeX.SX! You can have a look at our starter guide to familiarize yourself further with our format. The usual way to this would be to let your command accept an optional argument for the title as it should appear in the table of contents and running heads. This is what the standard \chapter command does. (In memoir there are two optional arguments, one of each of the uses.) – Andrew Swann Dec 6 '13 at 13:32
• Many thanks Andrew, But i didn't get it . how can i put chapter one and introduction which CONTENTS in one line – user1873093 Dec 6 '13 at 14:04
• Why do you need the custom chapter command in the first place? It seems to me that there might be a better way to do what want to achieve with the custom command, and if so, your current problem might not arise. – Alan Munn Dec 6 '13 at 14:14

The heading elements end up in two lines because you tell them to be in two lines (i.e. \\ is responsable for that). The problem is that your \mychapter macro lacks a certain ability that standard commands of LaTeX have:

Normally in LaTeX the sectioning commands have an optional argument that take the heading which will be written to the ToC. If it is not specified the heading given in the mandatory argument will be written to the ToC. (This is what @AndrewSwann tried to explain to you in his comment.)

Although it is not clear to me how you profit from defining the \mychapter macro, you could add the above described functionality by saying:

\newcommand{\mychapter}[3][]{%
\setcounter{chapter}{#3}
\setcounter{section}{0}
\chapter*{#2}
\if\relax\detokenize{#1}\relax
\else

Note that I swapped your parameter design a little. You can now use your macro like \mychapter[CHAPTER ONE INTRODUCTION]{CHAPTER ONE\\INTRODUCTION}{1} -- just to summarize: in general the synopsis is
\mychapter[<ToC heading>]{<body heading>}{<chapter number>}

where <body heading> is equal to <ToC heading>` if the optional argument is not given.