1

I am using the book class to write a document. I have a long chapter title that only fits in two lines. I'm using a custom chapter heading font and the justification of the chapter title in the second line is hidden by the black box.

what I have what I want

\documentclass[12pt, twoside]{book}

\usepackage{lipsum}

\usepackage{titlesec,calc,xcolor}
\usepackage{lmodern}


\titleformat{\chapter}[display]{\fontsize{18}{16}\usefont{OT1}{phv}{m}{n}\bfseries}{}{0pt}{
    \raisebox{-5mm}[0pt][0pt]{%<<
        \begin{minipage}{20mm}
            \centering{\mdseries\footnotesize\normalsize\textsc{Chapter}}\\[5pt]%
            \rule{10mm}{30mm}\hspace{-10mm}%
            \raisebox{23mm}{\parbox{10mm}{\centering\LARGE\textcolor{white}{\thechapter}}}%
        \end{minipage}
    }%
    \rule{\textwidth-20mm}{.4pt}\\%
    \hspace*{20mm}  
}[\vspace*{10mm}]


\begin{document}

\chapter{This is an example of a very long title that only fits in two lines}

    \section{Section 1}
    \lipsum[1]

\end{document}

How do I do this please ?

Amedo
  • 43

2 Answers2

2

You could put the chapter title in a minipage.

\documentclass[12pt, twoside]{book}
\usepackage{lipsum}
\usepackage{titlesec,calc,xcolor}
\usepackage{lmodern}

\titleformat{\chapter}[display]{\fontsize{18}{16}\usefont{OT1}{phv}{m}{n}\bfseries}{}{0pt}{
    \raisebox{-5mm}[0pt][0pt]{%<<
        \begin{minipage}{20mm}
            \centering{\mdseries\footnotesize\normalsize\textsc{Chapter}}\\[5pt]%
            \rule{10mm}{30mm}\hspace{-10mm}%
            \raisebox{23mm}{\parbox{10mm}{\centering\LARGE\textcolor{white}{\thechapter}}}%
        \end{minipage}
    }%
    \rule{\textwidth-22mm}{.4pt}\\%
    \hspace*{22mm}\begin{minipage}{\textwidth-22mm}
}[\end{minipage}\vspace*{10mm}]

\begin{document}

\chapter{This is an example of a very long title that only fits in two lines}
    \section{Section 1}
    \lipsum[1]

\end{document}

Vincent
  • 20,157
2

Here is a variant: I changed the chapterstyle to block, put the chapter title in a \parbox of width \linegoal, which measures the length from the current point to the right margin and used \titlerule, which simply fills the line from the current point to the right margin.

\documentclass[12pt, twoside]{book}
\usepackage{lmodern}
\usepackage{lipsum}
\usepackage{calc,xcolor}
\usepackage{linegoal}
\usepackage{titlesec}%

\titleformat{\chapter}[block]{\fontsize{18}{16}\usefont{OT1}{phv}{m}{n}\bfseries}{}{0pt}{
    \raisebox{-5mm}[0pt][0pt]{%<<
        \begin{minipage}{20mm}
            \centering{\mdseries\footnotesize\normalsize\textsc{Chapter}}\\[5pt]%
            \medskip\rule{10mm}{30mm}\hspace{-10mm}%
            \raisebox{23mm}{\parbox{10mm}{\centering\LARGE\textcolor{white}{\thechapter}}}%
        \end{minipage}
}%
 \titlerule\\%
    \hspace*{\dimexpr20mm +0.5em}
\parbox{\linegoal} }[\vspace*{10mm}]

\begin{document}

\chapter{This is an example of a very long title that only fits in two lines}

    \section{Section 1}
    \lipsum[1]

\end{document} 

enter image description here

Bernard
  • 271,350