# Customize a section title with Tikz

I am trying to get this kind of result with tikz. However I don' have any idea how to align the text with the bottom of the rectangles or how to anchor the 2nd rectangle with the line of the title

In this example, the fist title is a section title, the 2nd, a subsection title.

%!TEX program = xelatex
\documentclass{memoir}
\usepackage$paperwidth=10.5cm,paperheight=15.5cm, margin=0.9cm${geometry}
\usepackage{xcolor}
\usepackage$explicit${titlesec}
\usepackage{lipsum}
\definecolor{sec}{HTML}{DD5C14}
\definecolor{band}{HTML}{EE9C52}

\usepackage{fontspec}
\newfontfamily{\helveticacdb}{Helvetica-CondensedBlack}
% \newfontfamily{\helveticacdl}{Helvetica-CondensedLight}

\usepackage$T1${fontenc}

\titleformat{\section}$hang${\helveticacdb\fontsize{1.2cm}{0.95cm}\bfseries}{}{0.5ex}%
{\begin{minipage}{0.975\textwidth}%
\noindent
\color{band}%
\llap{\vrule width0.7cm height 0.7cm depth0ex\hskip0.25ex}%
\textcolor{sec}{\unskip#1}%
\hskip0.25ex%
\rlap{\vrule width\textwidth height 0.7cm    depth0ex}%
\end{minipage}}$\smallskip$

\titleformat{\subsection}$hang${\helveticacdb\fontsize{0.45cm}{0.5cm}\bfseries}{}{0.5ex}%
{\noindent%
\color{band}%
\raisebox{0.222ex}{\hbox to \textwidth{%
\vrule width1.3ex height1ex depth0ex\hskip0.5ex%
\raisebox{-0.222ex}{\textcolor{sec}{#1}}%
\hskip0.75ex%
\leaders\vrule height 0.2cm depth0ex\hfil}}}$\smallskip$

\titleformat{\subsubsection}$hang${\helveticacdb\fontsize{0.3cm}{0.3cm}\bfseries}{}{0.5ex}{
\textcolor{sec}{\unskip#1}%
}%

% Remove the header while starting a new section
\let\footruleskip\undefined
\usepackage{fancyhdr}
% \renewcommand{\sectionmark}$1${\markright{#1}{}}
\renewcommand{\footrulewidth}{0pt}
\fancyhf{}
\renewcommand{\sectionmark}$1${\markboth{\chaptername \ \thesection. #1}{}}

% Start sections on a new page
\usepackage{etoolbox}
\patchcmd{\section}{plain}{empty}{}{}
\pretocmd{\section}{%
\ifnum\value{section}=0 \else\clearpage\fi
}{}{}
% manage multicolumns after each section title
\usepackage{multicol}

\AtBeginDocument{\begin{multicols}{2}}
\AtEndDocument{\end{multicols}}

\makeatletter
\let\subsection@orig\subsection
\renewcommand\subsection$1${\endmulticols\subsection@orig{#1}\multicols{2}}
\makeatother

\begin{document}
\section$Politique et économie${Politique\\ et économie}
\subsection{POLITIQUE}
\subsubsection{First subsub}
\lipsum$1-2$

\end{document}


Remaining issues:

• Clear the page number each time a new section appears.
• Stick the left orange square to the left border page.
• You can create them with overlay pictures that are positioned relative to the start and end of the text and the current page. Have a look at overlays in the TikZ picture. The following draws an arrow from the current position, to the left margin. \begin{tikzpicture}[overlay,remember picture] \draw[->] coordinate (here) (here) -- (current page.west|-here); \end{tikzpicture} When you implement this, make sure the rectangles bleed into the margin. – user10274 Aug 27 '15 at 4:24
• How can I get the coordinates of the point at the west part of the page and under the header ? – celli Aug 27 '15 at 5:25
• Additionally to Marc van Dongen (using page. coordinates) you can use titlesec to change font sizes of the section/subsection and the TikZ option baseline (see e.g. here tex.stackexchange.com/a/89827/8042) to align the boxes with respect to the bottom line or the center line of the text accordingly. – Ronny Aug 27 '15 at 6:33
• After \tikz coordinate (first reference point);Your section title here\tikz coordinate (second reference point); You can then add your rectangles using the labels first reference pint and second reference point and positioning relative to current page.east and current page.west. – user10274 Aug 27 '15 at 6:39
• @Ronny I'm sure this is possible but that's not what the OP was asking. I just wanted to show something to get started with. – user10274 Aug 27 '15 at 6:41

Without TikZ. Still far from perfect though.

\documentclass{memoir}
\usepackage{xcolor}
\usepackage[explicit]{titlesec}

\definecolor{sec}{HTML}{DD5C14}
\definecolor{band}{HTML}{EE9C52}

\titleformat{\section}[hang]{\sffamily\Huge\bfseries}{}{0.5ex}%
{\begin{minipage}{0.975\textwidth}%
\noindent
\color{band}%
\llap{\vrule width\textwidth height1ex depth0ex\hskip0.75ex}%
\textcolor{sec}{\unskip#1}%
\hskip0.75ex%
\rlap{\vrule width\textwidth height1ex depth0ex}%
\end{minipage}}[\smallskip]

\titleformat{\subsection}[hang]{\sffamily\Large\bfseries}{}{0.5ex}%
{\noindent%
\color{band}%
\raisebox{0.222ex}{\hbox to 0.975\textwidth{%
\vrule width2ex height1ex depth0ex\hskip0.5ex%
\raisebox{-0.222ex}{\textcolor{sec}{#1}}%
\hskip0.75ex%

\begin{document}
\section[Politique et \'economie]{Politique \\ et \'economie}

Blablabla \ldots le politique et l'\'economie

\subsection{POLITIQUE}

Quelle horreur!

\end{document}


• One remaining issue: how can I get a left square collapsing the left border of the page. – celli Aug 29 '15 at 1:28