2

I would like to put the horizontal line below the section title as the figure below:

enter image description here

and the second one I would like to modified the page number by putting it in the rectangular box as the second and third figures below enter image description here enter image description here

Can you instruct me how to do that? Thank you in advance!

  • Dear Gonzalo, if you have time can you give more favor on this issue? I would like to put on the top of odd page is "Chapter xxx Title of the Chapter" and on the even page is "Part xxx Title of the Part xxxx" as illustrated in above figures. In the first page of each chapter, instead of the page number is put in middle bottom of the page. I would like to modify it by moving it to bottom left if the first page is on even number or by moving to the bottom right if the first page is on odd number. I attached link in order make it easy to follow. thanks. – Vũ Võ Jul 26 '15 at 15:30
  • link for the pic so that you can follow: (i.imgur.com/Zw5sYht.png ; imgur.com/tm1u1oy ) thank you so much – Vũ Võ Jul 26 '15 at 15:30
2

The formatting for the section tiles was done using titlesec with its explicit option; the formatting for the page numbers was done using a \fcolorbox, and its placement was done using fancyhdr. Only provission for the page numbers was done. The other elements in the header were not provided since they were not requested, but they can be easily done using fancyhdr features.

\documentclass{book}
\usepackage{xcolor}
\usepackage{fancyhdr}
\usepackage[explicit]{titlesec}
\usepackage{lipsum}

\newsavebox\mybox
\newlength\secnumwd

\definecolor{mydarkblue}{RGB}{0,163,243}
\definecolor{mylightblue}{RGB}{191,233,251}

\titleformat{\section}
  {\normalfont\Large\sffamily\color{mydarkblue}}
  {}
  {-5em}
  {%
    \savebox\mybox{\normalfont\Large\sffamily\color{mydarkblue}\bfseries\thesection}%
    \settowidth\secnumwd{\usebox\mybox}%    
    \parbox[t]{\secnumwd}{{\bfseries\thesection}}\hspace{1em}%
    \parbox[t]{\dimexpr\textwidth+5em-\secnumwd-1em\relax}{#1}%
  }
  [\vskip-1.75ex\hskip-5em{\color{gray!60}\titlerule[2pt]}]
\titleformat{name=\section,numberless}
  {\normalfont\Large\sffamily\color{mydarkblue}}
  {}
  {-5em}
  {#1}
  [\vskip-1.75ex\hskip-5em{\color{gray!60}\titlerule[2pt]}]

\newcommand\FrameBoxL[1]{%
  \fcolorbox{mylightblue}{mydarkblue}{\makebox[3cm][l]{\textcolor{white}{\bfseries#1}}}%
}
\newcommand\FrameBoxR[1]{%
  \fcolorbox{mylightblue}{mydarkblue}{\makebox[3cm][r]{\textcolor{white}{\bfseries#1}}}%
}

\pagestyle{fancy}
\fancyheadoffset[EL]{\dimexpr1in+\evensidemargin+\hoffset\relax}
\fancyheadoffset[OR]{\dimexpr\paperwidth-\oddsidemargin-1in-\textwidth-\hoffset\relax}
\fancyhf{}
\renewcommand\headrulewidth{0pt}
\fancyhead[OR]{\FrameBoxL{\thepage}}
\fancyhead[EL]{\FrameBoxR{\thepage}}

\begin{document}

\chapter{A test chapter}
\section{Test numbered section}
\lipsum[4]
\section*{Test unnumbered section}
\lipsum[1-10]

\end{document}

A zoomed-in image for the section titles:

enter image description here

An image of the result showing the page numbers with the requested formatting:

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.