Text FormattingTable of Contents Formatting

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
Post Reply
samirandam
Posts: 7
Joined: Sat Oct 10, 2015 7:47 pm

Table of Contents Formatting

Post by samirandam »

Dear All,

I want to enclose the "Part" in Table of Contents of a book type document by under and over lines. However, the other texts (such as, chapters, sections, subsections etc.) should remain as it is with default formatting). I am pasting the minimal working code in this post. Could anybody please help me to achieve what I am looking for?


Code: Select all

\documentclass{book}

\begin{document}

\author{Author A and Author B}
\title{Book Title}
\maketitle

\tableofcontents

\part{First Part}
\chapter{Chapter 1}

\end{document}

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

Johannes_B
Site Moderator
Posts: 4182
Joined: Thu Nov 01, 2012 4:08 pm

Table of Contents Formatting

Post by Johannes_B »

Hi and welcome,

you can do something like the following:

Code: Select all

\documentclass{book}

\newcommand{\tocline}{\addtocontents{toc}{\protect\begingroup%
	\protect\centering\protect\huge\protect\rule{.8\textwidth}{.6pt}\protect\par
\protect\endgroup}}
\begin{document}


\tableofcontents

\tocline
\part{First Part}
\tocline
\chapter{Chapter 1}
\part{Second Part}
\chapter{Chapter 2}
\part{Third Part}
\chapter{Chapter 3}

\end{document}
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.
samirandam
Posts: 7
Joined: Sat Oct 10, 2015 7:47 pm

Table of Contents Formatting

Post by samirandam »

Hi Johannes_B,

Thank you. The solution you provided is working fine with minor modification according to my requirement. I changed \huge to \small to reduce the gap.

Thank you once again.

Thanks
Samiran
Last edited by Stefan Kottwitz on Sun Oct 11, 2015 11:29 am, edited 1 time in total.
User avatar
Stefan Kottwitz
Site Admin
Posts: 10335
Joined: Mon Mar 10, 2008 9:44 pm

Table of Contents Formatting

Post by Stefan Kottwitz »

Hi Samiran,

welcome to the forum!

Nice to see that Johannes could provide a solution. By the way, I prefer the scrbook class over book, as it is much more flexible. We can even make headings with a colored background there.

Let us know if there would be further challenges with writing such a larger book like document. I'm always interested in how good or hard is LaTeX for us users.

Stefan
LaTeX.org admin
samirandam
Posts: 7
Joined: Sat Oct 10, 2015 7:47 pm

Table of Contents Formatting

Post by samirandam »

Hi Stefan,

It is very nice to be greeted into the group and thanks for your thoughtful suggestion.

Actually, I am writing a book based on Springer's svmono (http://resource-cms.springer.com/spring ... monographs) document class. So, according to your suggestion, it is not possible for me to use standard class like scrbook.

Ever since I started preparing my academic documents in LaTeX, I have been using BibTeX to produce bibliographies for all of my documents (thesis, papers, technical documents, etc.). And this way it used to generate the bibliography at the end of the document either in form of a chapter (in case of Thesis) or in form of a section (in case of paper). However, with my current assignment, I need to include the Reference section at the end of each chapter. I have a single ref.bib file which contains all of the references. Now I want to use that ref.bib and Springer's bibliography style file (spmpsci.bst) to generate separate reference section at the end of each chapter. Could you please help me out?

Thanks
SAMIRAN.

P.S. If required I shall create a different thread for this question.
User avatar
Johannes_B
Site Moderator
Posts: 4182
Joined: Thu Nov 01, 2012 4:08 pm

Re: Table of Contents Formatting

Post by Johannes_B »

A new thread will indeed be good, it is easier for others to find solutions using google.


A little remark: Springer has a quite strict layout, i think you are not allowed to add lines to the toc.
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.
User avatar
Stefan Kottwitz
Site Admin
Posts: 10335
Joined: Mon Mar 10, 2008 9:44 pm

Table of Contents Formatting

Post by Stefan Kottwitz »

Hi Samiran,

sounds like chapterbib or bibunits would be good for that case.

Stefan
LaTeX.org admin
samirandam
Posts: 7
Joined: Sat Oct 10, 2015 7:47 pm

Re: Table of Contents Formatting

Post by samirandam »

Hi Stefan,

I have created a separate thread (http://latex-community.org/forum/viewto ... 44&t=26793). Could you please provide me a step-by-step guide. Actually I am not sure about the series of commands that have to executed in order to generate the PDF having chapter-wise reference list.


Hi Johannes,

Thank you for your suggestion. I didn't know it. I saw one of the books from Springer which has this type formatting in TOC which provide a very clear segregation between the different parts in ToC. So I thought of implementing the same in my write-up.

Thanks
Samiran.
Post Reply