1

I face a problem with my table of contents: The look of my first chapter heading is

CHAPTER ONE 
INTRODUCTION

produced with the following code

\newcommand{\mychapter}[2]{

\setcounter{chapter}{#1}

\setcounter{section}{0}
\chapter*{#2}
\addcontentsline{toc}{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}

But, in the table of contents "CHAPTER ONE" and "INTRODUCTION" do not appear in one line:

enter image description here

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
2

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
  \addcontentsline{toc}{chapter}{#2}
\else
  \addcontentsline{toc}{chapter}{#1}
\fi
}

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.

  • If i want to do the same thing also for figure , Please can you show me the code – user1873093 Dec 7 '13 at 13:10
  • Please specify what do you exactly mean. The list of figures? And what is the concrete situation? You may also just ask another question on this site. – Ruben Dec 7 '13 at 18:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.