I am trying to typeset a title with titleformat as in the following 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.
Best Answer
Use a
\parbox
giving it a width of\textwidth
minus 10 points.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
.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 nameeur
; you want bold seriesb
and normal shapen
, 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
.