Page Layoutcustomize chapter name in toc

Information and discussion about page layout specific issues (e.g. header and footer lines, page formats, page numbers).
slinux
Posts: 8
Joined: Fri Jan 14, 2011 10:46 am

customize chapter name in toc

Post by slinux »

Hi,
If it has been asked before, i'm sorry but i couldnt find any solution for my problem. Default numbered chapters are added to toc as fallows:

Code: Select all

1  Chapter_name                    1
But i want it to be something like that.. it also should have empty line before every chapter line in toc. to add dotted line is easy but i couldnt find any solution for the others.

Code: Select all


Chapter 1.
Chapter_name ......................1

In the end table of contents should be seen as Table I.
Table I. I want to

Code: Select all

Dedication .....................ii
Contents .......................iii
List of tables .................iv
List of figures ................v
Summary ........................vi

Chapter 1.
Chapter_name ...................1
    1.1. Section_title..........1
    1.2. Section_title..........2

Chapter 2.
Chapter_name ...................3
    2.1. Section_title..........4
    2.2. Section_title..........5

Chapter 3.
Last_Chapter_name ..............7

References ....................20
Appendix A ....................21
Last edited by slinux on Mon Jan 24, 2011 3:55 pm, edited 2 times in total.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

frabjous
Posts: 2064
Joined: Fri Mar 06, 2009 12:20 am

customize chapter name in toc

Post by frabjous »

Questions like this are very hard to answer without a minimal working example. We don't even know what document class you're using, nor how things like "Dedication" are coded (and so whether steps need to be taken to prevent changes to how chapters are handled in the TOC affecting them as well). Without an example of your usage, I can only suggest looking at the tocloft or titletoc packages and their documentation, and cross my fingers that you're not using a document class that is incompatible with them.
slinux
Posts: 8
Joined: Fri Jan 14, 2011 10:46 am

customize chapter name in toc

Post by slinux »

I dont use any special class, just added report class. Table I. only to better understand for you.. I have explained main issue at the beginning of my post. Just imagine default chapter line in toc

Code: Select all

1  Chapter_name                    1
convert into

Code: Select all

Chapter 1.
Chapter_name                       1
User avatar
frabjous
Posts: 2064
Joined: Fri Mar 06, 2009 12:20 am

customize chapter name in toc

Post by frabjous »

Well, I'm going to try to help, even though I am a little annoyed with you for not taking my questions seriously. See the Post on Avoidable Mistakes.

I was asking for a reason. Without knowing how things like the Dedication, Contents, etc., are being added to the list, I have no way of knowing how the code I suggest will affect them. You've also claimed to have solved the issue with the leader dots, yet you don't say how, so I have no way of knowing whether my way of doing it is the same as yours. You also claimed to need a space between chapters in the TOC, yet this is the default behavior in the report class, so why mention it, unless something in your document is conflicting with it?

And in general, by not providing a minimal example, you force the person trying to help you to create one of his/her own, from scratch, which may or may not be close enough to yours to help you. This is frankly rather rude when people are helping you for free. You could at least make it easy on them to do so.

Anyway, without you meeting me half-way, here's the best I can suggest:

Code: Select all

\documentclass{report}
\usepackage{tocloft}
\setlength{\cftchapnumwidth}{0pt}
\renewcommand{\cftchappresnum}{\chaptername\ }
\renewcommand{\cftchapaftersnum}{.}
\renewcommand{\cftchapaftersnumb}{\newline}
\renewcommand{\cftchapdotsep}{\cftdotsep}
\begin{document}
\tableofcontents
\chapter{A Chapter}
\chapter{Another Chapter}
\end{document}
The output looks like this.
contents.png
contents.png (2.32 KiB) Viewed 17165 times
slinux
Posts: 8
Joined: Fri Jan 14, 2011 10:46 am

customize chapter name in toc

Post by slinux »

I'm really sorry for a little annoyed you :( I'm new here and not familiar with latex syntax too much but nonetheless i can explain you what i done so far..

I redefined \chapter, \section, \subsection commands only to change fonts, size and some extra stuff such as \vspace, \vskip. Meanwhile i changed internal command @makechapterhead instead of directly \chapter command.

Code: Select all

\def\@makechapterhead#1%
{
	\vspace*{2cm}
	\thispagestyle{empty}
	{
		\parindent 0pt
		\Chfont \MakeUppercase \@chapapp{} \thechapter.   
		\hskip 10pt
		\Chfont \uppercase{#1}%
		\par
		\nobreak
		\vskip 2.5cm
   }
}

\def\section%
{
	\@startsection{section}
	{1}
	{\z@}%
	{3ex}
	{3ex}
	{\Scfont}%
}

for example if you dont want chapter name to appear in the table of contents you can use \chapter* command but just the opposite i want it to appear in toc and so redefined internal command @schapter used by \chapter* as fallows:

Code: Select all

\def\@schapter#1%
{
	\addcontentsline{toc}{chapter}{#1}
	\@makeschapterhead{\Chfont #1}
	\@afterheading
}
so that i used \chapter* command to create Dedication and Summary pages.

You know there isnt dotted line between chapter name and page number in toc and to overcome with this problem i used this

Code: Select all

\renewcommand*\l@chapter{\@dottedtocline{0}{0.5em}{1.5em}}
but this last command wipe out spaces before chapter lines in the toc. in fact i dont want chapter lines in toc created by \chapter* to have space but if it created by \chapter should have space. as i said before the last command wipe out all spaces in toc.

also i dont know why but when i add tocloft package all layout were corrupted and that's why i dont prefer using tocloft pakage. if there is internal commands to change appearence of chapter line in toc, maybe i can use them.

i hope, it's clear now...
User avatar
frabjous
Posts: 2064
Joined: Fri Mar 06, 2009 12:20 am

customize chapter name in toc

Post by frabjous »

No, no, no, no. It is not "all clear", and will be "all clear" until you produce a minimal working example as you have already been instructed, twice.

I have already wasted time on your case trying to come up with a solution using tocloft which is not compatible with the rest of your set-up. I would have known it was incompatible with the rest of your setup if you had provided it the first time I asked. I am not wasting any more time trying to produce another solution which probably won't work because of something else in your set-up you haven't made plain.

The re-definitions you provided are not the sort that someone not familiar with LaTeX syntax could have produced on his/her own, so either you got these redefinitions from somewhere/someone else, or else you are not as inexperienced as you pretend.

Perhaps your minimal example is little over and above what you've already posted, just stitched together to make one document. If that's the case, then I am not asking for very much, but it's the least you could do when asking for help from others.
slinux
Posts: 8
Joined: Fri Jan 14, 2011 10:46 am

customize chapter name in toc

Post by slinux »

First of all i can understand why you are so sensitive about my way of asking questions. I hope you understand i'm trying to adapt myself here. Thank you in advance for any help.

Maybe i'm not familiar with latex syntax but i'm a programmer at the same time and if i find right manuals or help documentations by searching with google and read them, at least i can do something. For example this website help me to figure out some internal commands which arent used by directly users.

This is my simple class file

Code: Select all

\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{simplecls}[2011/01/10 v0.1 my simple class file]
\LoadClass{report}

\RequirePackage[english]{babel}
\RequirePackage[T1]{fontenc}
\RequirePackage[latin5]{inputenc}

\def\@makechapterhead#1%
{%
	\vspace*{2cm}
	\thispagestyle{empty}
	{
		\parindent 0pt
		\fontsize{14}{14}\fontfamily{phv}\selectfont\bfseries \MakeUppercase \@chapapp{} \thechapter.
		\hskip 10pt
		\fontsize{14}{14}\fontfamily{phv}\selectfont\bfseries \uppercase{#1}%
		\par
		\nobreak
		\vskip 2.5cm
  }
}

\def\@schapter#1%
{
	\addcontentsline{toc}{chapter}{#1}
	\@makeschapterhead{\fontsize{14}{14}\fontfamily{phv}\selectfont\bfseries #1}
	\@afterheading
}

\renewcommand{\thesection}{\thechapter.\arabic{section}.}
\renewcommand{\thesubsection}{\thechapter.\arabic{section}.\arabic{subsection}.}
\renewcommand{\thesubsubsection}{\thechapter.\arabic{section}.\arabic{subsection}.\arabic{subsubsection}.}

\def\section%
{%
	\@startsection{section}
	{1}
	{\z@}%
	{3ex}
	{3ex}
	{\fontsize{12}{12}\fontfamily{phv}\selectfont\bfseries}%
}

\def\subsection%
{
	\@startsection{subsection}
	{2}
	{\z@}%
	{3ex}
	{3ex}
	{\fontsize{12}{12}\fontfamily{phv}\selectfont\bfseries}%
}

\def\subsubsection%
{
	\@startsection{subsubsection}
	{2}
	{\z@}%
	{3ex}
	{3ex}
	{\fontsize{12}{12}\fontfamily{phv}\selectfont\bfseries}%
}

%\renewcommand\l@chapter{\@dottedtocline{0}{0.5em}{1.5em}}
if i doesnt misunderstand what you said, here you are my minimal working example

Code: Select all

\documentclass{simplecls}

\begin{document}
\chapter*{Dedication}
bla bla bla
\chapter*{Summary}
bla bla bla
\tableofcontents
\chapter{Chapter Name}
\section{Section title}
\subsection{Subsection title}
\chapter*{Reference}
\end{document}
This code produces a table of contents as fallows:
table of contents
table of contents
toc.png (8.5 KiB) Viewed 17153 times
As you see, i created summary and dedication pages with \chapter* and also they are seen in the table of contents because of redefination of @schapter. either \chapter or \chapter* command latex puts empty lines by default between chapter lines in toc. actually i want dedication, contents and summary lines to come closer no space between them and then table sould have one empty line and next numbered chapter comes.. if i use \chapter* command as though it shoudnt have an empty line after itself in toc, but if use \chapter everything is done by default.

also it should have dotted line between chapter name and page number which doesnt comes with latex by default. And the last one chapter name should seen as fallows:

Code: Select all

Chapter 1.
Chapter Name ...................... 5
Please look at Table I in my firt post.

i hope it's clear now :)
User avatar
frabjous
Posts: 2064
Joined: Fri Mar 06, 2009 12:20 am

customize chapter name in toc

Post by frabjous »

Well, we're getting closer. I still have some questions, like whether you want the chapter entries in bold, and if so, which ones, and whether the dots should be in bold for those as well, etc.

But try keeping tocloft but use the titles option so it doesn't overwrite your title redefinitions for the contents itself. Keeping your definitions, I can only think of some tricks to make lines before entries produced by \chapter* but not by \chapter, but here goes a suggested change of the document class:

Code: Select all

\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{simplecls}[2011/01/10 v0.1 my simple class file]
\LoadClass{report}

\RequirePackage[english]{babel}
\RequirePackage[T1]{fontenc}
\RequirePackage[latin5]{inputenc}

\def\@makechapterhead#1%
{%
   \vspace*{2cm}
   \thispagestyle{empty}
   {
      \parindent 0pt
      \fontsize{14}{14}\fontfamily{phv}\selectfont\bfseries \MakeUppercase \@chapapp{} \thechapter.
      \hskip 10pt
      \fontsize{14}{14}\fontfamily{phv}\selectfont\bfseries \uppercase{#1}%
      \par
      \nobreak
      \vskip 2.5cm
  }
}

\def\@schapter#1%
{
   \addtocontents{toc}{\vspace{-1\baselineskip}}
   \addcontentsline{toc}{chapter}{#1}
   \@makeschapterhead{\fontsize{14}{14}\fontfamily{phv}\selectfont\bfseries #1}
   \@afterheading
}

\renewcommand{\thesection}{\thechapter.\arabic{section}.}
\renewcommand{\thesubsection}{\thechapter.\arabic{section}.\arabic{subsection}.}
\renewcommand{\thesubsubsection}{\thechapter.\arabic{section}.\arabic{subsection}.\arabic{subsubsection}.}

\def\section%
{%
   \@startsection{section}
   {1}
   {\z@}%
   {3ex}
   {3ex}
   {\fontsize{12}{12}\fontfamily{phv}\selectfont\bfseries}%
}

\def\subsection%
{
   \@startsection{subsection}
   {2}
   {\z@}%
   {3ex}
   {3ex}
   {\fontsize{12}{12}\fontfamily{phv}\selectfont\bfseries}%
}

\def\subsubsection%
{
   \@startsection{subsubsection}
   {2}
   {\z@}%
   {3ex}
   {3ex}
   {\fontsize{12}{12}\fontfamily{phv}\selectfont\bfseries}%
}

\usepackage[titles]{tocloft}
\setlength{\cftchapnumwidth}{0pt}
\setlength{\cftbeforechapskip}{\baselineskip}
\renewcommand{\cftchappresnum}{\chaptername\ }
\renewcommand{\cftchapaftersnum}{.}
\renewcommand{\cftchapaftersnumb}{\newline}
\renewcommand{\cftchapdotsep}{\cftdotsep}
(Using this with your sample document, unmodified...)
newcontents.png
newcontents.png (5.66 KiB) Viewed 17152 times
slinux
Posts: 8
Joined: Fri Jan 14, 2011 10:46 am

customize chapter name in toc

Post by slinux »

frabjous wrote:Well, we're getting closer. I still have some questions, like whether you want the chapter entries in bold, and if so, which ones, and whether the dots should be in bold for those as well, etc.
Yes good point, I don't want chapter entries to be in bold font and also the dots shouldn't be in bold as well. Every entries should be in normal font.. Beside reference line should have one empty line before itself but i think it's easy. I can put extra command at the end of last chapter like that

Code: Select all

\addtocontents{toc}{\vspace{1\baselineskip}}
Thank you in advance, your answers help to figure out tocloft package and its usage. There is only one left thing is to make normal font all of them.
slinux
Posts: 8
Joined: Fri Jan 14, 2011 10:46 am

customize chapter name in toc

Post by slinux »

well, i solved it on my own. add these commands make all entries normal font

Code: Select all

\renewcommand{\cftchapleader}{\cftdotfill{\cftchapdotsep}}
\renewcommand{\cftchappagefont}{}
\renewcommand{\cftchapfont}{}
Can I use this package for list of tables and figures?

Default as fallows

Code: Select all

1.1 figure_name bla bla bla ........... 4

1.1 table_name bla bla bla ............ 4
but should be like that

Code: Select all

Figure 1.1. figure_name bla bla bla .......... 4

Table 1.1. table_name bla bla bla ............ 4
Post Reply