[Tex/LaTex] Manually Break line in custom chapter title

chaptersline-breakingsectioning

\documentclass[openany, 10pt]{book}
\usepackage[utf8]{inputenc}
\usepackage[MeX]{polski}
\usepackage{titleps}

\usepackage{lipsum}
\usepackage{tocloft}
 \renewcommand\cftchapaftersnum{.}% adds dot after chapter title in ToC
 \renewcommand\cftchapdotsep{\cftdotsep}% adds leader dots from chapter titles to page numbers
\frenchspacing

\usepackage{pstcol}
\makeatletter
  \def\LigneVerticale{\vrule height 5cm depth 2cm\hspace{0.1cm}\relax}
  \def\LignesVerticales{
  \let\LV\LigneVerticale\LV\LV\LV\LV\LV\LV\LV\LV\LV\LV}
  \def\GrosCarreAvecUnChiffre#1{%
  \rlap{\vrule height 0.8cm width 1cm depth 0.2cm}%
  \rlap{\hbox to 1cm{\hss\mbox{\white #1}\hss}}%
  \vrule height 0pt width 1cm depth 0pt}

  \def\@makechapterhead#1{\hbox{%
  \Huge 
  \LignesVerticales
  \hspace{-0.5cm}%
  \GrosCarreAvecUnChiffre{\thechapter.}% the final dot adds a dor after the chapter number in the document

  \hspace{0.2cm}\hbox{#1}%
  \renewcommand\numberline[1]{#1.\hskip0.7em}
 }\par\vskip 2cm}

  \def\@makeschapterhead#1{\hbox{%
  \Huge 
  \LignesVerticales
  %\hspace{0.5cm}%
  \hbox{#1}%
 }\par\vskip 2cm}


 \begin{document}
 \chapter{Much too long chapter title with linebreak}
 \lipsum[1-10]
 \end{document}

Hello,

my problem is that chapter dosen't fit the text on a page. I have tried many things such as:

\protect

How to make (force) line-break in Chapter Title (in ToC, Chapter, Header) – if possible?

chapter title long and necessity to cut it

How to make title of chapter to fit the page size?

Best Answer

In the definition of \@makechapterhead and \@makeschapterhead replace the \hbox in which the title will be typeset with a \parbox of the appropriate length:

\documentclass[openany, 10pt]{book}
\usepackage[utf8]{inputenc}
\usepackage[MeX]{polski}
\usepackage{titleps}

\usepackage{lipsum}
\usepackage{tocloft}
 \renewcommand\cftchapaftersnum{.}% adds dot after chapter title in ToC
 \renewcommand\cftchapdotsep{\cftdotsep}% adds leader dots from chapter titles to page numbers
\frenchspacing

\usepackage{pstcol}
\makeatletter
  \def\LigneVerticale{\vrule height 5cm depth 2cm\hspace{0.1cm}\relax}
  \def\LignesVerticales{
  \let\LV\LigneVerticale\LV\LV\LV\LV\LV\LV\LV\LV\LV\LV}
  \def\GrosCarreAvecUnChiffre#1{%
  \rlap{\vrule height 0.8cm width 1cm depth 0.2cm}%
  \rlap{\hbox to 1cm{\hss\mbox{\white #1}\hss}}%
  \vrule height 0pt width 1cm depth 0pt}

  \def\@makechapterhead#1{\hbox{%
  \Huge 
  \LignesVerticales
  \hspace{-0.5cm}%
  \GrosCarreAvecUnChiffre{\thechapter.}% the final dot adds a dor after the chapter number in the document

  \hspace{0.2cm}\parbox[t]{\dimexpr\linewidth-2.2cm\relax}{\raggedright#1}%
  \renewcommand\numberline[1]{#1.\hskip0.7em}
 }\par\vskip 2cm}

  \def\@makeschapterhead#1{\hbox{%
  \Huge 
  \LignesVerticales
  %\hspace{0.5cm}%
  \parbox[t]{\dimexpr\linewidth-1.6cm\relax}{\raggedright#1}%
 }\par\vskip 2cm}


 \begin{document}
 \chapter[A test chapter]{A Test Numbered Chapter with a Really Really Long Title}
 \lipsum[1-10]
 \end{document}

enter image description here