2

Is there a way to dynamically size titles as part of a \titleformat (from the titlesec package) definition? I'd like to scale titles of different lengths to be the same width (relative to \textwidth) by only changing fontsize.

The answers to this question describe how to resize text in a similar way, but I'm not sure how this could be used to redefine/extend the section titles. (e.g. as a part of \titleformat*{\subsection} ...)

6
  • Did you try to use \resizebox?
    – Sigur
    Commented May 21, 2015 at 10:13
  • @Sigur not sucessfully. how would it work?
    – zzkt
    Commented May 21, 2015 at 11:00
  • 1
    For instance, you'd want that \section{Abc} and \section{Abc def ghi jkl} typeset the text filling the same width?
    – egreg
    Commented May 21, 2015 at 15:14
  • @egreg. correct.
    – zzkt
    Commented May 22, 2015 at 8:24
  • It doesn't seem like a good idea.
    – egreg
    Commented May 22, 2015 at 8:39

1 Answer 1

3

It doesn't seem like a good idea.

\documentclass{article}
\usepackage{titlesec,graphicx}

\titleformat{\section}
 {\Large\bfseries}
 {\thesection}
 {1em}
 {\resizetitle}

\newcommand{\resizetitle}[1]{\resizebox{\sectionwidth}{!}{#1}}
\newlength{\sectionwidth}
\AtBeginDocument{%
  \setlength{\sectionwidth}{.3\textwidth}%
}

\begin{document}

\section{Abc}

\section{Def ghi klm}

\section{Lorem ipsum dolor sit amet}

\end{document}

enter image description here

One could scale also the numbers, but the overall result doesn't seem worthy a try.

1
  • thanks for providing an answer, despite your reservations. it works as expected.
    – zzkt
    Commented May 22, 2015 at 8:57

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .