6

I am trying to typeset a title with titleformat as in the following example:

Example

I like the overall result, but when the title wraps around it is not left-aligned. Is there any way to indent the second line accordingly? This is the code that generates the example:

\documentclass[12pt]{book}

\usepackage{titlesec}
\usepackage{xcolor}

\newfont{\chapterNumber}{eurb10 scaled 5000}

\titleformat{\chapter}[block]%
        {\relax}%
        {\llap{\color{gray}\chapterNumber\thechapter%
        \hspace{10pt}\vline}  }{10pt}%
        {\raggedright\LARGE\textsc}

%% Using this instead, the text is left-aligned but the
%% vertical line is not aligned with the body text
% \titleformat{\chapter}[block]%
%         {\relax}%
%         {\llap{\color{gray}\chapterNumber\thechapter%
%         \hspace{10pt}\vline\hspace{10pt}}}{0pt}%
%         {\raggedright\LARGE\textsc}

\begin{document}
\chapter{Long long long long long long long long long long title}
\end{document}

There is an alternative definition that makes the title aligned by putting the \hspace inside the \llap, but this way the vertical line is shifted left while I'd like it to be aligned with the body text.

3
  • Welcome to TeX.sx! Apr 28 '13 at 19:53
  • Using \newcommand{\chapterNumber}{\fontsize{50}{50}\usefont{U}{eur}{b}{n}} instead of \newfont is better.
    – egreg
    Apr 28 '13 at 19:57
  • @egreg thanks, can you explain why it is better? Apr 28 '13 at 20:09
5

Use a \parbox giving it a width of \textwidth minus 10 points.

\documentclass[12pt]{book}

\usepackage{titlesec}
\usepackage{xcolor,lipsum}

\titleformat{\chapter}[block]
  {}
  {\llap{\color{gray}\chapterNumber\thechapter
   \hspace{10pt}\vline}}
  {10pt}
  {\formatchaptertitle}

\newcommand{\formatchaptertitle}[1]{%
  \parbox[t]{\dimexpr\textwidth-10pt}{\raggedright\LARGE\scshape#1}}

\newcommand{\chapterNumber}{%
  \fontsize{50}{50}\usefont{U}{eur}{b}{n}}


\begin{document}
\chapter{Long long long long long long long long long long title}

\lipsum[1]
\end{document}

The lipsum package is just for producing text that shows how the \vline is aligned with the left margin.

Don't use \newfont, but the command I suggest for defining \chapterNumber.

enter image description here


The command \newfont is still in LaTeX for backward compatibility, because old document written with LaTeX 2.09 could have used it. With the introduction of the New Font Selection Scheme (NFSS), back in the early 90's, some new concepts in font management have been included in LaTeX and fonts defined with \newfont simply ignore them, so the result could be surprising.

The Euler font is available in "unspecified" encoding U, with family name eur; you want bold series b and normal shape n, so \usefont{U}{eur}{b}{n}; the size must be set independently: the first argument to \fontsize is the font size proper, the second is the baselineskip (which is almost irrelevant here, so I use the same as the size). No unit means unit "points". After \fontsize{x}{y} a \selectfont command is necessary, but it's provided automatically by \usefont.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.