Document ClassesColored chapter titles

Information and discussion about specific document classes and how to create your own document classes.
Post Reply
tweeg
Posts: 22
Joined: Tue Jun 24, 2008 5:12 pm

Colored chapter titles

Post by tweeg »

Hey,

I made my section titles into blue using this in my sty file:

Code: Select all

\definecolor{bl}{rgb}{0,0.2,0.6}
\let\LaTeX@startsection\@startsection 
\renewcommand{\@startsection}[6]{\LaTeX@startsection%
{#1}{#2}{#3}{#4}{#5}{\color{bl}\raggedright #6}} 
But now, everything is blue except my chapter titles, im not to good at latex, so does anyone know how to color these also ? I use the color package ofc.
Last edited by tweeg on Fri Oct 10, 2008 8:57 pm, edited 1 time in total.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org
LaTeX books
User avatar
Stefan Kottwitz
Site Admin
Posts: 10308
Joined: Mon Mar 10, 2008 9:44 pm

Colored chapter titles

Post by Stefan Kottwitz »

Hi tweeg,

which document class do you use? Try this compilable example including your code:

Code: Select all

\documentclass{article}
\usepackage{color}
\makeatletter
\definecolor{bl}{rgb}{0,0.2,0.6}
\let\LaTeX@startsection\@startsection
\renewcommand{\@startsection}[6]{\LaTeX@startsection%
{#1}{#2}{#3}{#4}{#5}{\color{bl}\raggedright #6}} 
\makeatother
\begin{document}
\section{One}
text
\subsection{Sub}
text
\end{document}
I'm getting blue section titles and black text.

Stefan
LaTeX.org admin
tweeg
Posts: 22
Joined: Tue Jun 24, 2008 5:12 pm

Re: Colored chapter titles

Post by tweeg »

Im soooo stupid, i just edited my text :oops: :oops: I ment chapter titles, not section titels, the code i showed works fine for section titles.
User avatar
Stefan Kottwitz
Site Admin
Posts: 10308
Joined: Mon Mar 10, 2008 9:44 pm

Colored chapter titles

Post by Stefan Kottwitz »

Ah, after the edit I understand. \chapter is not using \@startsection, you could redefine \@makechapterhead and \@makeschapterhead or consider to use the titlesec package.

Stefan
LaTeX.org admin
tweeg
Posts: 22
Joined: Tue Jun 24, 2008 5:12 pm

Colored chapter titles

Post by tweeg »

Stefan_K wrote:Ah, after the edit I understand. \chapter is not using \@startsection, you could redefine \@makechapterhead and \@makeschapterhead or consider to use the titlesec package.

Stefan
Im a total noob when it comes to this :oops: i got the code for the section from someone else, how do i redefine the \@makechapterhead and \@makeschapterhead to change the colour ?
User avatar
Stefan Kottwitz
Site Admin
Posts: 10308
Joined: Mon Mar 10, 2008 9:44 pm

Re: Colored chapter titles

Post by Stefan Kottwitz »

You can get the original code directly from the source of your document class. Which class do you use?

Stefan
LaTeX.org admin
tweeg
Posts: 22
Joined: Tue Jun 24, 2008 5:12 pm

Colored chapter titles

Post by tweeg »

Code: Select all

\documentclass[a4paper, 10pt, oneside]{report}
User avatar
Stefan Kottwitz
Site Admin
Posts: 10308
Joined: Mon Mar 10, 2008 9:44 pm

Colored chapter titles

Post by Stefan Kottwitz »

Just take the original code from report.cls, redefine it while including \color{bl}:

Code: Select all

\renewcommand*\@makechapterhead[1]{%
  \vspace*{50\p@}%
  {\parindent \z@ \raggedright \normalfont
    \ifnum \c@secnumdepth >\m@ne
        \huge\bfseries\color{bl} \@chapapp\space \thechapter
        \par\nobreak
        \vskip 20\p@
    \fi
    \interlinepenalty\@M
    \Huge \bfseries #1\par\nobreak
    \vskip 40\p@
  }}
\renewcommand*\@makeschapterhead[1]{%
  \vspace*{50\p@}%
  {\parindent \z@ \raggedright
    \normalfont
    \interlinepenalty\@M
    \Huge \bfseries\color{bl}  #1\par\nobreak
    \vskip 40\p@
  }}
Of course it could have been done differently.

Stefan
LaTeX.org admin
tweeg
Posts: 22
Joined: Tue Jun 24, 2008 5:12 pm

Re: Colored chapter titles

Post by tweeg »

Thx a lot, worked like a charm :D
Post Reply