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.
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.
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:
\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}