Hello,
This is perhaps a simple question -- I'm trying to calculate the width of a section title so that I can make a \rule of the appropriate width. I'm using titlesec, and tried doing:
But the width ends up as 0. I can use \thesection instead, and it'll give me the width of the section label. Which is nice, because I'll be able to add that value to the section title value and have the width I need! But getting the section title value is proving very difficult.
Page Layout ⇒ Calculating the Width of a Section Title
NEW: TikZ book now 40% off at Amazon.com for a short time.

Calculating the Width of a Section Title
Hi,
the titlesec package offers the \titlewidth command; refer to the package documentation for further information.
the titlesec package offers the \titlewidth command; refer to the package documentation for further information.
1,1,2,3,5,8,13,21,34,55,89,144,233,...
Re: Calculating the Width of a Section Title
\titlewidth is one of the first things I tried, but it seems to return 0 -- the \rule ends up not drawing at all.
Calculating the Width of a Section Title
It seems that you forgot to load titlesec with the calcwidth option. In the following example the section title is centered, with a dotted rule above it (the length of the rule depends on \titlewidth), and the length given by \titlewidth will be typeset just below the tile:onidavin wrote:\titlewidth is one of the first things I tried, but it seems to return 0 -- the \rule ends up not drawing at all.
Code: Select all
Code, edit and compile here:
\documentclass{article}\usepackage[calcwidth]{titlesec}\titleformat{\section}[block]{\filcenter\large\titleline*[c]{\titlerule*[.6pc]{\tiny\textbullet}}%\addvspace{6pt}%\normalfont\sffamily}{\thesection}{1em}{}[\addvspace{10pt}\the\titlewidth]\titlespacing{\section}{5pc}{*2}{*2}[5pc]\begin{document}\section{Some short title}\section{Some not so short title}\section{Some really long, long title}\end{document}
1,1,2,3,5,8,13,21,34,55,89,144,233,...
Re: Calculating the Width of a Section Title
Works like a charm. Thanks!