Forum How do I...?

Table of content: page number in the last line of the chapter title

ixgal
hi,

by default, on the table of content, if a chapter title has more than 1 line, the page number on the right will be at the same line as the first line of the chapter title. Is it possible to put the page number in the last line of the chapter title? Please see the examples below:

1) (now)

This is a chapter title with a 19
second line

2) (what I would need)

This is a chapter title with a
second line 19


thanks!
mikeday
Yes you can do this. How are you making the table of contents?
ixgal
hi Michael, thanks. Please find below the styles for the table of content we are using:
--------------
/* TABLE OF CONTENTS
======================= */

.toc h1 {
text-align: center
}
#toc a {
border: none;
}
#toc ul, #toc li {
list-style: none;
margin: 0;
padding: 0;
text-align: left;
}
#toc li {
position: relative;
}
#toc a::after {
content: leader(' ') target-counter(attr(href), page);
font-style: normal;
position: absolute;
top: 0;
right: 0;
text-decoration: none;
}
#toc .front-matter a::after {
content: leader(' ') target-counter(attr(href), page);
}
#toc .introduction a::after {
content: leader(' ') target-counter(attr(href), page);
}
#toc .part {
margin: .6cm 0 .7em;
/*text-align: center;*/
page-break-after: avoid;
}
#toc .part.invisible {
display: none;
}
#toc {
page-break-before: right;
counter-reset: part;
font-size: 10pt;
}
#toc ul {
counter-reset: chapter;
line-height: 1.2em;
}
#toc ul li {
margin-bottom:5px;
}
#toc .part a::before {
content: " ";
counter-increment: part;
}
#toc .chapter a {
padding-left: 25px;
}
#toc .chapter a::before {
content: counter(chapter) ". ";
counter-increment: chapter;
margin-right: 7pt;
position: absolute;
left: 0;
top: 0;
}
#toc .chapter.numberless a::before {
content:'' ;
counter-increment: none;
margin-right: 0;
}
#toc .part a::after {
content:'' ;
}
/*
#toc .chapter + .back-matter {
margin-top: 1.3em;
}
*/
#toc span {
hyphens: none;
}

#toc span.chapter-author,
#toc span.chapter-subtitle {
display: inline-block;
font-style: italic;
margin-left: 2em;
width: 80%;
}
#toc span.toc-chapter-title {
display: inline-block;
width: 80%;
}
#toc span.chapter-author,
#toc span.chapter-subtitle {
/*margin-bottom: 5px;*/
margin-bottom:0px;
}
#toc span.chapter-subtitle +
span.chapter-author {
margin-top:5px;
margin-bottom:0px;
}
/*
#toc span.chapter-subtitle +
span.chapter-author {
margin-bottom: 5px;
position: relative;
top: -5px;
}
*/
/*end toc*/
mikeday
I don't think you need the absolute positioning, you can just keep it inline and use a leader to push it to the right.
ixgal
hi Michael, thanks. So, I should replace absolute by relative here?
#toc a::after {
content: leader(' ') target-counter(attr(href), page);
font-style: normal;
position: absolute;
top: 0;
right: 0;
text-decoration: none;
}


Please let me know about the leader too (I don't know how to implement it)
mikeday
What if you just remove the "position", "top", and "right" properties?
ixgal
hi Michael, I am almost there. I managed to add the dotted line and to add the page number in the last line of the title. But now the page number appear repeted on titles with more than 1 line. Please see screenshot enclosed.
Just in case, the code am using is:

#toc a::after { content: leader(' ') target-counter(attr(href), page); font-style: normal; position: absolute; top: 0; right: 0; text-decoration: none; }

If I remove the "position", "top" and "right" properties, then I get all page numbers repeated like this: 9393 (page number being 93).

thanks again
  1. toc.png22.0 kB
mikeday
Are there two link elements? I don't see why you are getting the page number twice.
ixgal
hi Michael, I found it, there was another line. Problem solved!
mikeday
Great! :)