Page Layout ⇒ ToC --- how to add margins around?
ToC --- how to add margins around?
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?
Learn LaTeX easily with newest books:
The LaTeX Beginner's Guide: 2nd edition and perfect for students writing a thesis
The LaTeX Cookbook: 2nd edition full of practical examples for mathematics, physics, chemistry, and more
LaTeX Graphics with TikZ: the first book about TikZ for perfect drawings in your LaTeX thesis
- localghost
- Site Moderator
- Posts: 9202
- Joined: Fri Feb 02, 2007 12:06 pm
ToC --- how to add margins around?
Best regards
Thorsten¹
Board Rules
Avoidable Mistakes
¹ System: TeX Live 2025 (vanilla), TeXworks 0.6.10
ToC --- how to add margins around?
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}
- localghost
- Site Moderator
- Posts: 9202
- Joined: Fri Feb 02, 2007 12:06 pm
Re: ToC --- how to add margins around?
Board Rules
Avoidable Mistakes
¹ System: TeX Live 2025 (vanilla), TeXworks 0.6.10
ToC --- how to add margins around?
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}
Board Rules
Avoidable Mistakes
¹ System: TeX Live 2025 (vanilla), TeXworks 0.6.10
ToC --- how to add margins around?
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}