# Fancy Chapter Headings Right for Odd Pages and Left of Left ones

I have those two parts of code:

\documentclass[double,12pt, twoside]{book}
\usepackage{graphics}
\usepackage[a4paper]{geometry}

%--------------first one-----------------
\titleformat{\chapter}[display]
{\normalfont\Large\raggedleft}
{\MakeUppercase{\chaptertitlename}
\rlap{ \resizebox{!}{1.5cm}{\thechapter} \rule{5cm}{1.5cm}}}
{10pt}{\Huge}
\titlespacing*{\chapter}{0pt}{30pt}{20pt}

%--------------second one-----------------
\titleformat{\chapter}[display]
{\normalfont\Large\raggedright}
{\hspace{0cm}\llap{%
\rule{5cm}{1.5cm}\hspace{0.2cm}\resizebox{!}{1.5cm}{\thechapter}\hspace{0.2cm}}%
\MakeUppercase{\chaptertitlename}}
{10pt}{\Huge}
\titlespacing*{\chapter}{0pt}{30pt}{20pt}

\usepackage{lipsum}
\setcounter{chapter}{2}
\begin{document}

\chapter{Implementation}
\lipsum
\end{document}


I want the first one for the odd pages and the second one for the even ones. I am new with latex, and I couldn't figure out from that thread.

PS. I am sorry for duplicate question, how can i delete one question?

• Welcome to TeX.SX! To delete a question simply click on the delete button on the bottom left corner of the question box. The question you've linked to uses a KOMA-Script class, things differ a bit from KOMA and standard classes. – Guilherme Zanotelli Dec 7 '16 at 11:25
• Thank you, any suggestions how to make it work? – taleporos Dec 7 '16 at 11:30
• Yes I do, posted as an answer! ;) – Guilherme Zanotelli Dec 7 '16 at 11:49

You can use the same logic proposed in the question, checking wheter to see if the page is odd or not. KOMA and memoir have built in functions for that, but the book class doesn't. There was already one question about this in the Website: If Then Else for odd page/even page. The package changepage was one of the recomentadions. Then to change the \chapter format, use the titlesec package.

But for this to take effect you have to load the book class with the openany option, as by default it's set to openright, then the chapters headings would never end up on an even page. Also, you don't need the geometry package for setting the paper to A4, you can pass that directly to the class.

\documentclass[a4paper, double, 12pt, twoside, openany]{book}
\usepackage{titlesec}
\usepackage{changepage}
\strictpagecheck

\makeatletter
\titleformat{\chapter}[display]%
{\normalfont\Large\checkoddpage%
\ifoddpage%
\raggedleft%
\else%
\raggedright%
\fi}%
{\checkoddpage%
\ifoddpage%
\MakeUppercase{\chaptertitlename}%
\rlap{ \resizebox{!}{1.5cm}{\thechapter} \rule{5cm}{1.5cm}}%
\else%
\hspace{0cm}\llap{%
\rule{5cm}{1.5cm}\hspace{0.2cm}\resizebox{!}{1.5cm}{\thechapter}\hspace{0.2cm}}%
\MakeUppercase{\chaptertitlename}%
\fi}
{10pt}{\Huge}
\titlespacing*{\chapter}{0pt}{30pt}{20pt}
\makeatother

\usepackage{lipsum}
\begin{document}
\chapter{Odd page}
\lipsum[1-2]

\chapter{Even page}
\lipsum[3-4]
\end{document}


• thnx a lot !!!! – taleporos Dec 7 '16 at 11:59