Page Layout ⇒ ToC --- how to add margins around?
ToC --- how to add margins around?
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?
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?
NEW: TikZ book now 40% off at Amazon.com for a short time.
- localghost
- Site Moderator
- Posts: 9202
- Joined: Fri Feb 02, 2007 12:06 pm
ToC --- how to add margins around?
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¹
Best regards
Thorsten¹
How to make a "Minimal Example"
Board Rules
Avoidable Mistakes
¹ System: TeX Live 2025 (vanilla), TeXworks 0.6.10
Board Rules
Avoidable Mistakes
¹ System: TeX Live 2025 (vanilla), TeXworks 0.6.10
ToC --- how to add margins around?
localghost, I'm very sorry!
There is no matter of two-column or strip environment — I need the principial solution for both one or two-column layouts.
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}
Last edited by neGODnick on Mon Mar 30, 2009 11:09 am, edited 1 time in total.
- localghost
- Site Moderator
- Posts: 9202
- Joined: Fri Feb 02, 2007 12:06 pm
Re: ToC --- how to add margins around?
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?
How to make a "Minimal Example"
Board Rules
Avoidable Mistakes
¹ System: TeX Live 2025 (vanilla), TeXworks 0.6.10
Board Rules
Avoidable Mistakes
¹ System: TeX Live 2025 (vanilla), TeXworks 0.6.10
ToC --- how to add margins around?
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.
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.
- localghost
- Site Moderator
- Posts: 9202
- Joined: Fri Feb 02, 2007 12:06 pm
ToC --- how to add margins around?
Perhaps it's also a little bit me because English isn't my mother tongue, too.neGODnick wrote:I'm sorry again, may be, my english is too bad and poor. [...]
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}
How to make a "Minimal Example"
Board Rules
Avoidable Mistakes
¹ System: TeX Live 2025 (vanilla), TeXworks 0.6.10
Board Rules
Avoidable Mistakes
¹ System: TeX Live 2025 (vanilla), TeXworks 0.6.10
ToC --- how to add margins around?
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
but with no effect. Preps, I misunderstood the tocloft manual how to use it.
(To get the left margin, respectively, may be used
where “indent” is the distance from left page edge to ToC entry, this command works fine in my example.)
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}}
(To get the left margin, respectively, may be used
Code: Select all
\cftsetindents{section}{indent}{numwidth}
ToC --- how to add margins around?
localghost wrote:…the heading of the ToC is also indented. I didn't find out yet how to do that with tocloft.
Now I found how to fix it. Use the folowing to get the ToC title indented as other titles: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.
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}
\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}
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}
ToC --- how to add margins around?
Unfortunately, it affects centered ToC title, too. So, the last one may be given as folowing: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.
With babel:
Code: Select all
\let\OldContentsname\contentsname
\addto\captionsenglish{\def\contentsname{\centerline{\hspace{-2\leftmargin}\OldContentsname}}}
Code: Select all
\let\OldContentsname\contentsname
\def\contentsname{\centerline{\hspace{\cftsecnumwidth}\hspace{-2\leftmargin}\OldContentsname}}
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}
ToC --- how to add margins around?
To fix that, the tocloft package must be loaded with option “titles”: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!!!
Code: Select all
\usepackage[titles]{tocloft}