[Tex/LaTex] Misalignment chapter titles with hang option of titlesec package and redefined \cleardoublepage

blank-pageformattinghorizontal alignmentsectioningtitlesec

When I redefine the command \cleardoublepage to include the words "This page has been intentionally left blank", the titles of the chapters are misaligned.

\documentclass{book}
\usepackage[a4paper, top=14mm, bottom=10mm, inner=15mm, outer=13mm, bindingoffset=10mm, includefoot, includehead, headsep=14mm, footskip=14mm]{geometry}
\usepackage{titlesec}
\titleformat{\chapter}[hang]{\normalfont\huge\bfseries}{\chaptertitlename\ \thechapter.}{1em}{} 

\newcommand*{\blankpage}{%
\vspace*{\fill}
\centering [This page is intentionally left blank]
\vspace{\fill}}
\makeatletter
\renewcommand*{\cleardoublepage}{\clearpage\if@twoside \ifodd\c@page\else
\blankpage
\thispagestyle{empty}
\newpage
\if@twocolumn\hbox{}\newpage\fi\fi\fi}
\makeatother
\makeatletter

\begin{document}
\chapter{First chapter title.}
\chapter{Misaligned chapter title illustrating the bug I'm experiencing.}
\end{document}

enter image description here

Best Answer

This combines Werner's comment with a modified version of Ian Thompson's answer.

Werner's suggestion

Werner's suggestion resolves the problem mentioned in the question but reveals a further problem:

\documentclass{book}
\usepackage[a4paper, top=14mm, bottom=10mm, inner=15mm, outer=13mm, bindingoffset=10mm, includefoot, includehead, headsep=14mm, footskip=14mm]{geometry}
\usepackage{titlesec}
\titleformat{\chapter}[hang]{\normalfont\huge\bfseries\raggedright}{\chaptertitlename\ \thechapter.}{1em}{}

\newcommand{\blankpage}{%
  \vspace*{\fill}%
  \centering [This page is intentionally left blank]
  \vspace{\fill}}
\makeatletter
  \renewcommand*{\cleardoublepage}{%
    \clearpage%
      \if@twoside
        \ifodd
          \c@page
        \else
          \blankpage\thispagestyle{empty}\newpage
            \if@twocolumn
              \hbox{}\newpage
            \fi
        \fi
      \fi}
\makeatother

\begin{document}
\chapter{First chapter title.}
\chapter{Misaligned chapter title illustrating the bug I'm experiencing.}

Some text.
\end{document}

A further problem

Centring the following text is probably not what was intended here and is therefore problematic.

Ian Thompson's answer

Ian Thompson's solution solves this problem but creates a third:

\documentclass{book}
\usepackage[a4paper, top=14mm, bottom=10mm, inner=15mm, outer=13mm, bindingoffset=10mm, includefoot, includehead, headsep=14mm, footskip=14mm]{geometry}
\usepackage{titlesec}
\titleformat{\chapter}[hang]{\normalfont\huge\bfseries\raggedright}{\chaptertitlename\ \thechapter.}{1em}{}

\newcommand{\blankpage}{%
  \vspace*{\fill}%
  {\centering [This page is intentionally left blank]} % <--- Braces added here
  \vspace{\fill}}
\makeatletter
  \renewcommand*{\cleardoublepage}{%
    \clearpage%
      \if@twoside
        \ifodd
          \c@page
        \else
          \blankpage\thispagestyle{empty}\newpage
            \if@twocolumn
              \hbox{}\newpage
            \fi
        \fi
      \fi}
\makeatother

\begin{document}
\chapter{First chapter title.}
\chapter{Misaligned chapter title illustrating the bug I'm experiencing.}

Some text.
\end{document}

Solving one problem and creating another

This happens because \centering is only effective when the paragraph ends and the grouping prevents the paragraph ending so the code is never actually effective.

Final code

\documentclass{book}
\usepackage[a4paper, top=14mm, bottom=10mm, inner=15mm, outer=13mm, bindingoffset=10mm, includefoot, includehead, headsep=14mm, footskip=14mm]{geometry}
\usepackage{titlesec}
\titleformat{\chapter}[hang]{\normalfont\huge\bfseries\raggedright}{\chaptertitlename\ \thechapter.}{1em}{}

\newcommand{\blankpage}{%
  \vspace*{\fill}%
  {\centering [This page is intentionally left blank]\par}%
  \vspace{\fill}}
\makeatletter
  \renewcommand*{\cleardoublepage}{%
    \clearpage%
      \if@twoside
        \ifodd
          \c@page
        \else
          \blankpage\thispagestyle{empty}\newpage
            \if@twocolumn
              \hbox{}\newpage
            \fi
        \fi
      \fi}
\makeatother

\begin{document}
\chapter{First chapter title.}
\chapter{Misaligned chapter title illustrating the bug I'm experiencing.}

Some text.
\end{document}

Final code

Related Question