10

I was trying to personalize the chapter and section headings using titlesec for my master thesis using the following code

\documentclass{book}
\usepackage{tikz}
\usepackage{titlesec}
\usepackage{lipsum}

\makeatletter
\titleformat{\chapter}[display]
{}% format
{\raggedleft \@chapapp{} \thechapter}% label
{1ex}           % sep
{\raggedleft \Huge \scshape \bfseries}  % before
[\normalfont {\tikz \shade[left color=blue!20,right color=blue, shading angle=45] (0,0) rectangle (\textwidth,5pt);}]% after
\makeatother

\begin{document}
\chapter{Introduction}
\lipsum[1]
\end{document}

Which gives the following output

result

What I want is simply to remove the space between the chapter name and the TikZ drawing and define the vertical space between the drawing and the text (the only one I can get to work is between the chapter and the chapter name). Also which is best for this, titlesec or define all of this as a class file?

I've also tried the second option with similar problems:

\documentclass{book}
\makeatletter
\usepackage{tikz}
\usepackage{palatino}
\usepackage[T1]{fontenc}
\usepackage{titlesec}
\def\@makechapterhead#1{%
\vspace*{10\p@}%
{\parindent \z@ \raggedleft \reset@font%
\@chapapp{} \thechapter\par\nobreak%
{\Huge \scshape \bfseries #1\par\nobreak%
\vspace{5pt}
{\tikz \shade[left color=blue!20,right color=blue, shading angle=45] (0,0) rectangle (\textwidth,5pt);}}\par\nobreak%
\vspace{40pt}
}}%
\begin{document}
\chapter{Introduction}
\chapter{Internal Structure}
\section{Internal Strut}
%\section{part 1}
\end{document}
1
  • The vertical space is I think just the line height of \Huge. Maybe not the most elegant solution, but you can simply add negative \vspaces: [\vspace{-0.8em}\normalfont {\tikz \shade[left color=blue!20,right color=blue, shading angle=45] (0,0) rectangle (\textwidth,5pt);}\vspace{-1.5em}]
    – Caramdir
    Commented Jun 26, 2012 at 15:40

1 Answer 1

13

Insert the line directly in the vertical list:

\makeatletter
\def\@makechapterhead#1{%
  \vspace*{10\p@}%
  {\parindent \z@ \raggedleft \reset@font
   \@chapapp{} \thechapter\par\nobreak
   {\Huge \scshape \bfseries #1\vadjust{\putline}\par\nobreak}%
   \vspace{40pt}
  }}
\makeatother
\newcommand{\putline}{%
  \kern10pt %%% <-- adjust here
  \hbox{\tikz \shade[left color=blue!20,right color=blue, shading angle=45] (0,0) rectangle (\textwidth,5pt);}%
}

Adjust the amount of kerning as you like.

enter image description here

1
  • Thank you very much, works perfectly and I learned something new: kern :D
    – D.Silva
    Commented Jun 26, 2012 at 22:07

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .