How to break long toc entries?

2,683 views
Skip to first unread message

cibercitizen1

unread,
Sep 15, 2009, 5:52:04 AM9/15/09
to LaTeX Users Group
Long titles for sections or subsections
aren't broken by latex when shown in
the table of contents. Only
a long line appears, exceeding
the page format or even going
out of the page.

How could this be fixed?
Of course, I dont' want to
write shorter titles.

Thanks,

Ariovaldo V Garcia

unread,
Sep 15, 2009, 7:56:49 AM9/15/09
to latexus...@googlegroups.com
Hi,

I don't know if this solve your question. You can put a short line in
toc without changing the section title:

\section[Title that will appear in toc]{Title that will appear in the
body of the article}


Ariovaldo

cibercitizen1

unread,
Sep 15, 2009, 10:53:11 AM9/15/09
to LaTeX Users Group


On 15 Set, 13:56, Ariovaldo V Garcia <garcia...@gmail.com> wrote:
> Hi,
>
> I don't know if this solve your question. You can put a short line in
> toc without changing the section title:
>
> \section[Title that will appear in toc]{Title that will appear in the
> body of the article}
>

Thanks Ariovaldo but I really need the long title in the toc.
I'm writing a faq. The titles are questions. And I want
the full question sentence to be shown in the toc, so anyone
can read the list of questions there, and then go
to the page with the solution.

Vahid Damanafshan

unread,
Sep 15, 2009, 11:30:11 AM9/15/09
to latexus...@googlegroups.com
Latex does this automatically. see the attached files.
--
--------------------------------------
وحید دامن‌افشان
Vahid Damanafshan
vdaman...@yahoo.com
vdaman...@gmail.com
test.pdf
test.tex

cibercitizen1

unread,
Sep 15, 2009, 4:25:34 PM9/15/09
to LaTeX Users Group

On 15 Set, 17:30, Vahid Damanafshan <mathon...@gmail.com> wrote:
> Latex does this automatically.

Thanks for your observation Vahid.
I have to check it further.
The case is that latex isn't breaking
long lines for me. But, now I realize
that is surely because
I redefined \section and \subsection
to change the color. The redefinition
is apparently trivial since I'm finally
using the original \section with
the argument given to my \section
definition. Perhaps the fact
that the title is passed through
as an argument makes latex
think it is a single line. I don't
know. I'll be investigating it tomorrow.

cibercitizen1

unread,
Sep 16, 2009, 4:41:29 AM9/16/09
to LaTeX Users Group

Finally I found the bug.
The guilty is the hyperref package.
When I use it, it makes long lines
don't be broken in the toc.

Vahid Damanafshan

unread,
Sep 16, 2009, 4:50:42 AM9/16/09
to latexus...@googlegroups.com
Dear cibercitizen1,
I don't think so. See the attached files. If you want your problem to be solved, send your preamble lines till I test them too.
test.pdf
test.tex

cibercitizen1

unread,
Sep 16, 2009, 5:41:26 AM9/16/09
to LaTeX Users Group

Vahid, thanks indeed for your help. I wouldn't like
you loose to much time with this.

Following (I don't know how to add attachments)
you can find a simple version of my .tex file.

In POINT-1 I redefine \subsection.
In POINT-2 I let \Question to be \subsection
In POINT-3 I use hyperref
In POINT-4 There is a dummy chapter.

With thinks like that the toc is wrong.
But if I otherwise comment the use of hyperref,
then the toc is OK.

That plus your evidence, implies that the problem
should be my redefinition of subsection (POINT-1)
or a strange interaction of it & hyperref,
since my redefinition is OK without hyperref.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% FILE : index.tex
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\documentclass{book}

%----------------------------------------------------------------
% font
%----------------------------------------------------------------
\usepackage{bookman}

%----------------------------------------------------------------
% accents and language
%----------------------------------------------------------------
%\usepackage[spanish]{babel}
%\usepackage[utf8]{inputenc} % iso-8859-1

%----------------------------------------------------------------
% colors
%----------------------------------------------------------------
\usepackage{color}

%----------------------------------------------------------------
% packages that must be include after changing page layout
%----------------------------------------------------------------

%----------------------------------------------------------------
% rich PDF (hyperref)
%----------------------------------------------------------------
%\usepackage{thumb pdf}
% 1$ pdflatex index.tex
% 2$ thumbpdf index.pdf
% 3$ pdflatex index.tex

% POINT-3
\usepackage
[a4paper,ps2pdf,hyperindex,colorlinks,linkcolor=blue,bookmarksnumbered]
{hyperref}

%----------------------------------------------------------------
% colors
%----------------------------------------------------------------
\definecolor{Blue1}{rgb}{0.1, 0.1, 0.5}
\definecolor{Blue2}{rgb}{0.0, 0.0, 0.4}
\definecolor{Blue3}{rgb}{0.0, 0.0, 0.5}

\definecolor{Green1}{rgb}{0.1, 0.5, 0.1}
\definecolor{Green2}{rgb}{0.0, 0.4, 0.0}
\definecolor{Green3}{rgb}{0.0, 0.5, 0.0}

\definecolor{Red1}{rgb}{0.5, 0.1, 0.1}
\definecolor{Red2}{rgb}{0.4, 0.0, 0.0}
\definecolor{Red3}{rgb}{0.5, 0.0, 0.0}
\definecolor{Red4}{rgb}{0.8, 0.1, 0.1}

\definecolor{jDarkRed}{rgb}{0.5,0.0,0.0}
\definecolor{jBrown}{rgb}{0.6,0.4,0.1}

\definecolor{Grey1}{rgb}{0.1,0.1,0.1}
\definecolor{Grey2}{rgb}{0.2,0.2,0.2}


%----------------------------------------------------------------
% commands for sectioning with colors
% (sembla que no es gaste en este faq de programació
%----------------------------------------------------------------

%----------------------------------------------------------------
% POINT-1
%----------------------------------------------------------------
\makeatletter
\renewcommand{\subsection}{%
\@startsection{subsection}% name
{2}% level
{-1cm}% indent
{-\baselineskip}% beforeskip
{2pt}% afterskip
{\normalfont\large\bf}% skip
}

\renewcommand{\section}{%
\newpage%
\@startsection{section}% name
{1}% level
{-1.5cm}% indent
{-\baselineskip}% beforeskip
{1ex}% afterskip
{\normalfont\huge\bf}% skip
}

\makeatother

%----------------------------------------------------------------
% Question & Answer
%----------------------------------------------------------------

% POINT-2
\let\Question\subsection


%----------------------------------------------------------------
\newcommand{\Answer}[1]{\vspace{2em}{\color{Blue3}\subsubsection*
{\hspace{-1cm}#1}}\vspace{-0.5em}}


%----------------------------------------------------------------
% layout of paragraphs
%----------------------------------------------------------------
\parskip=1ex
\parindent=0pt
\sloppy

%----------------------------------------------------------------
% title
%----------------------------------------------------------------
\title{Programming FAQ}
\author{Me}
\date{\today}

%================================================================
% DOCUMENT STARTS HERE
%================================================================
\begin{document}

%----------------------------------------------------------------
% first page
%----------------------------------------------------------------

\maketitle

%\begin{abstract}
%
%\end{abstract}

%----------------------------------------------------------------
\tableofcontents

%----------------------------------------------------------------
% chapters
%----------------------------------------------------------------
% POINT-4

%***********************************************************************
\chapter{Introduction}
%***********************************************************************

\section{Basics}

%==========================================================
\begin{Question}{¿How do I write very long lines that can
be correctly shown in the table of contents}

bla, bla, bla, bla, bla, bla, bla
bla, bla, bla, bla, bla, bla, bla
bla, bla, bla, bla, bla, bla, bla
bla, bla, bla, bla, bla, bla, bla
bla, bla, bla, bla, bla, bla, bla
bla, bla, bla, bla, bla, bla, bla
bla, bla, bla, bla, bla, bla, bla
bla, bla, bla, bla, bla, bla, bla

\Answer{In C++}

I don't know right now.
\end{Question}
%==========================================================


%================================================================
\end{document}
%================================================================

%----------------------------------------------------------------
% the file ends here
%----------------------------------------------------------------

Vahid Damanafshan

unread,
Sep 16, 2009, 6:29:44 AM9/16/09
to latexus...@googlegroups.com

cibercitizen1,

You are welcome, I'm so sorry, I don't know. However see the attached files, those are the exact your file with no error. Meantime, for adding attachments, login to your Gmail and go to Compose Mail and then use  Attach a file.

Good luck.

jon

unread,
Sep 16, 2009, 8:42:15 PM9/16/09
to LaTeX Users Group
On Sep 16, 5:41 am, cibercitizen1 <cibercitiz...@gmail.com> wrote:
> Vahid, thanks indeed for your help. I wouldn't like
> you loose to much time with this.
>
> Following (I don't know how to add attachments)
> you can find a simple version of my .tex file.
>
> In POINT-1 I redefine \subsection.
> In POINT-2 I  let \Question to be \subsection
> In POINT-3 I use hyperref
> In POINT-4 There is a dummy chapter.
>
> With thinks like that the toc is wrong.
> But if I otherwise comment the use of hyperref,
> then the toc is OK.
>
> That plus your evidence, implies that the problem
> should be my redefinition of subsection (POINT-1)
> or a strange interaction of it & hyperref,
> since my redefinition is OK without hyperref.

your basic problem is that you aren't using the 'breaklinks' option of
hyperref. add that to your list of options and everything should
compile ok, /if/ you also fix the way you are using \Question (see
below).
>
> %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
> % FILE : index.tex
> %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

[snip]

> \makeatletter
> \renewcommand{\subsection}{%
> \@startsection{subsection}% name
> {2}% level
> {-1cm}% indent
> {-\baselineskip}% beforeskip
> {2pt}% afterskip
> {\normalfont\large\bf}% skip
>
> }
>
> \renewcommand{\section}{%
> \newpage%
> \@startsection{section}% name
> {1}% level
> {-1.5cm}% indent
> {-\baselineskip}% beforeskip
> {1ex}% afterskip
> {\normalfont\huge\bf}% skip
>
> }
>
> \makeatother

don't leave an empty line in your redefinition of these sectioning
commands. and use \bfseries, not \bf to get bold fonts.


> \let\Question\subsection

[snip]

> %==========================================================
> \begin{Question}{¿How do I write very long lines that can
> be correctly shown in the table of contents}

[snip]

> \end{Question}

since you've let \Question = \subsection, you can't then say:
\begin{Question}
...
\end{Question}

you need to write:

\Question{How do I write very long lines...}

cheers,
jon.
Reply all
Reply to author
Forward
0 new messages