Page LayoutToC --- how to add margins around?

Information and discussion about page layout specific issues (e.g. header and footer lines, page formats, page numbers).
Post Reply
neGODnick
Posts: 35
Joined: Mon Jun 16, 2008 9:31 pm

ToC --- how to add margins around?

Post by neGODnick »

Hello, people!

I'm writing two-column article with table of content before the main text, enclosed in \begin{strip}. . . \end{strip}. ToC looks too wide, so I want left & right margins around it like quotations etc. have. How to do this with tocloft package?

Recommended reading 2024:

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

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

User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

ToC --- how to add margins around?

Post by localghost »

Since this is not your first post, you should already noticed that providing a minimal working example (MWE) can be essential in some cases to get help. For example, I personally can't figure out where this strip environment comes from. Hence I can't give you any advice at this moment. If you would provide a MWE, this state may change.


Best regards
Thorsten¹
neGODnick
Posts: 35
Joined: Mon Jun 16, 2008 9:31 pm

ToC --- how to add margins around?

Post by neGODnick »

localghost, I'm very sorry!

Code: Select all

\documentclass[a4paper,12pt]{article}
\usepackage{lipsum}
\usepackage{tocloft} 

\renewcommand{\cftsecleader}{\cftdotfill{\cftdotsep}}

\begin{document}
\tableofcontents{}
\section{The First Section}
\lipsum[1-4]

\section{Very-very-very long, \emph{very-very-very} long and strange title only to demonstrate how it looks in \textsc{The Table of Contents}}
\lipsum[1-4]

\section{The Last Section}
\lipsum[1]
\end{document}
There is no matter of two-column or strip environment — I need the principial solution for both one or two-column layouts.
Last edited by neGODnick on Mon Mar 30, 2009 11:09 am, edited 1 time in total.
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Re: ToC --- how to add margins around?

Post by localghost »

Whatever the problem is, your MWE doesn't show it. The ToC looks normal. You have to specify what is going wrong with your document. Perhaps it only depends on the point of view what you describe as "too wide". At the moment I can't really figure out what you want. Is it only to have the ToC with wider margins?
neGODnick
Posts: 35
Joined: Mon Jun 16, 2008 9:31 pm

ToC --- how to add margins around?

Post by neGODnick »

I'm sorry again, may be, my english is too bad and poor.
Yes, I just want to have the ToC with wider margins :—)

I want to make ToC more narrow than the main text. I want to indent ToC from left and right page edges, like quotations. Now ToC is normal but looks too wide for my taste.
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

ToC --- how to add margins around?

Post by localghost »

neGODnick wrote:I'm sorry again, may be, my english is too bad and poor. [...]
Perhaps it's also a little bit me because English isn't my mother tongue, too.

The epslatex document introduces the narrow environment which we can use here. Consider the following example.

Code: Select all

\documentclass[11pt,a4paper,english]{article}
\usepackage[T1]{fontenc}
\usepackage[latin1]{inputenc}
\usepackage{babel}
\usepackage[includeheadfoot,margin=2cm]{geometry}
\usepackage{lmodern}
\usepackage{blindtext}

\newenvironment{narrow}[2]{%
  \begin{list}{}{%
    \setlength{\topsep}{0pt}%
    \setlength{\leftmargin}{#1}%
    \setlength{\rightmargin}{#2}%
    \setlength{\listparindent}{\parindent}%
    \setlength{\itemindent}{\parindent}%
    \setlength{\parsep}{\parskip}
  }%
  \item[]
}{\end{list}}

\begin{document}
  \begin{narrow}{1cm}{1cm}
    \tableofcontents
  \end{narrow}
  \Blinddocument
\end{document}
I'm not sure if this is what you want because the heading of the ToC is also indented. I didn't find out yet how to do that with tocloft.
neGODnick
Posts: 35
Joined: Mon Jun 16, 2008 9:31 pm

ToC --- how to add margins around?

Post by neGODnick »

Mmm…

Yes, it's not good that the heading of the ToC is also indented… In my running document it bring no influence because I do the ToC title centered, but for future it seems to need the correction.

I think, your code can solve my problem, thank you!

So, we have only one way — to put \tableofcontents into any environment based on “list”, as I see?

I have tried to add some space after the page number using the tocloft’s commands like

Code: Select all

\newcommand{\cfttocafterpnum}{\hspace{1.5em}}
but with no effect. Preps, I misunderstood the tocloft manual how to use it.

(To get the left margin, respectively, may be used

Code: Select all

\cftsetindents{section}{indent}{numwidth}
where “indent” is the distance from left page edge to ToC entry, this command works fine in my example.)
neGODnick
Posts: 35
Joined: Mon Jun 16, 2008 9:31 pm

ToC --- how to add margins around?

Post by neGODnick »

localghost wrote:…the heading of the ToC is also indented. I didn't find out yet how to do that with tocloft.
neGODnick wrote:Yes, it's not good that the heading of the ToC is also indented… In my running document it bring no influence because I do the ToC title centered, but for future it seems to need the correction.
Now I found how to fix it. Use the folowing to get the ToC title indented as other titles:

1. Without tocloft:

\let\OldContentsname\contentsname
\def\contentsname{\OldContentsname}
\addto\captionsenglish{\def\contentsname{\hspace{-\leftmargin}\OldContentsname}}


localghost’s example:

Code: Select all

\documentclass[11pt,a4paper,english]{article}
\usepackage[T1]{fontenc}
\usepackage[latin1]{inputenc}
\usepackage{babel}
\usepackage[includeheadfoot,margin=2cm]{geometry}
\usepackage{lmodern}
\usepackage{blindtext}

\newenvironment{narrow}[2]{%
  \begin{list}{}{%
    \setlength{\topsep}{0pt}%
    \setlength{\leftmargin}{#1}%
    \setlength{\rightmargin}{#2}%
    \setlength{\listparindent}{\parindent}%
    \setlength{\itemindent}{\parindent}%
    \setlength{\parsep}{\parskip}
  }%
  \item[]
}{\end{list}}

\let\OldContentsname\contentsname 
\def\contentsname{\OldContentsname}
\addto\captionsenglish{\def\contentsname{\hspace{-\leftmargin}\OldContentsname}}

\begin{document}
  \begin{narrow}{1cm}{1cm}
    \tableofcontents
  \end{narrow}
  \Blinddocument
\end{document}
2. With tocloft we must remove additional space “\cftsecnumwidth”:

\let\OldContentsname\contentsname
\def\contentsname{\OldContentsname}
\addto\captionsenglish{\def\contentsname{\hspace{-\cftsecnumwidth}\hspace{-\leftmargin}\OldContentsname}}


localghost’s example + tocloft:

Code: Select all

\documentclass[11pt,a4paper,english]{article}
\usepackage[T1]{fontenc}
\usepackage[latin1]{inputenc}
\usepackage{babel}
\usepackage[includeheadfoot,margin=2cm]{geometry}
\usepackage{lmodern}
\usepackage{blindtext}
\usepackage{tocloft} 

\newenvironment{narrow}[2]{%
  \begin{list}{}{%
    \setlength{\topsep}{0pt}%
    \setlength{\leftmargin}{#1}%
    \setlength{\rightmargin}{#2}%
    \setlength{\listparindent}{\parindent}%
    \setlength{\itemindent}{\parindent}%
    \setlength{\parsep}{\parskip}
  }%
  \item[]
}{\end{list}}

\let\OldContentsname\contentsname 
\def\contentsname{\OldContentsname} 
\addto\captionsenglish{\def\contentsname{\hspace{-\cftsecnumwidth}\hspace{-\leftmargin}\OldContentsname}}

\begin{document}
  \begin{narrow}{1cm}{1cm}
    \tableofcontents
  \end{narrow}
  \Blinddocument
\end{document}
or my 1st example + new environment:

Code: Select all

\documentclass[a4paper,12pt]{article}
\usepackage{lipsum}
\usepackage{tocloft} 

\renewcommand{\cftsecleader}{\cftdotfill{\cftdotsep}}

\newenvironment{narrow}[2]{%
  \begin{list}{}{%
    \setlength{\topsep}{0pt}%
    \setlength{\leftmargin}{#1}%
    \setlength{\rightmargin}{#2}%
    \setlength{\listparindent}{\parindent}%
    \setlength{\itemindent}{\parindent}%
    \setlength{\parsep}{\parskip}
  }%
  \item[]
}{\end{list}}

\let\OldContentsname\contentsname 
\def\contentsname{\hspace{-\cftsecnumwidth}\hspace{-\leftmargin}\OldContentsname}
\addto\captionsenglish{\def\contentsname{\hspace{-\leftmargin}\OldContentsname}}

\begin{document}
\begin{narrow}{1cm}{1cm}
\tableofcontents{}
\end{narrow}	

\section{The First Section}
\lipsum[1-4]

\section{Very-very-very long, \emph{very-very-very} long and strange title only to demonstrate how it looks in \textsc{The Table of Contents}}
\lipsum[1-4]

\section{The Last Section}
\lipsum[1]
\end{document}
:—)
neGODnick
Posts: 35
Joined: Mon Jun 16, 2008 9:31 pm

ToC --- how to add margins around?

Post by neGODnick »

neGODnick wrote:Yes, it's not good that the heading of the ToC is also indented… In my running document it bring no influence because I do the ToC title centered, but for future it seems to need the correction.
Unfortunately, it affects centered ToC title, too. So, the last one may be given as folowing:

With babel:

Code: Select all

\let\OldContentsname\contentsname 
\addto\captionsenglish{\def\contentsname{\centerline{\hspace{-2\leftmargin}\OldContentsname}}}
Without babel:

Code: Select all

\let\OldContentsname\contentsname 
\def\contentsname{\centerline{\hspace{\cftsecnumwidth}\hspace{-2\leftmargin}\OldContentsname}}
The values “-2\leftmargin” (here) and “-\leftmargin” (below) I have got by exhaustion, they are suitable approximately. This commands works fine with LaTeX original ToC, but with tocloft package can bring wrong formatting in the 1st ToC’s line:

localghost’s example + tocloft; for this the “-\leftmargin” is suitable value

Code: Select all

\documentclass[11pt,a4paper,english]{article}
\usepackage[T1]{fontenc}
\usepackage[latin1]{inputenc}
\usepackage{babel}
\usepackage[includeheadfoot,margin=2cm]{geometry}
\usepackage{lmodern}
\usepackage{blindtext}
\usepackage{tocloft} 

\newenvironment{narrow}[2]{%
  \begin{list}{}{%
    \setlength{\topsep}{0pt}%
    \setlength{\leftmargin}{#1}%
    \setlength{\rightmargin}{#2}%
    \setlength{\listparindent}{\parindent}%
    \setlength{\itemindent}{\parindent}%
    \setlength{\parsep}{\parskip}
  }%
  \item[]
}{\end{list}}

\let\OldContentsname\contentsname 
\addto\captionsenglish{\def\contentsname{\centerline{\hspace{-\leftmargin}\OldContentsname}}}

\begin{document}
  \begin{narrow}{1cm}{1cm}
    \tableofcontents
  \end{narrow}
  \Blinddocument
\end{document}
R-r-r!!!
neGODnick
Posts: 35
Joined: Mon Jun 16, 2008 9:31 pm

ToC --- how to add margins around?

Post by neGODnick »

neGODnick wrote:This commands works fine with LaTeX original ToC, but with tocloft package can bring wrong formatting in the 1st ToC’s line
<…>
R-r-r!!!
To fix that, the tocloft package must be loaded with option “titles”:

Code: Select all

\usepackage[titles]{tocloft} 
:—)
Post Reply