23

I am using Lyx and Layout report for my thesis. I would like to change the colour of chapters sections and subsections (only the headings) from black to blue.

I attach a screenshot in order to understand what colours i am trying to achieve only on headings (Chapter /section and subsection )

Also is it possible to change the colour of table of contents to blue ? (again only the heading)

33

You can use the package sectsty to do change the headings, and xcolor to get the colour definitions.

For example, add to your preamble (Document --> Settings --> LaTeX preamble) the following:

\usepackage{xcolor}
\usepackage{sectsty}
\chapterfont{\color{blue}}  % sets colour of chapters
\sectionfont{\color{cyan}}  % sets colour of sections

enter image description here

You can use colours predefined in xcolor (see manual), or define your own, e.g.

\definecolor{MyBlue}{rgb}{0.1,0.1,1}

Put such definitions in the preamble as well.

  • Thanks i'll try this and ill come back if i have problems by using xcolor :) – ALdaperan Oct 7 '12 at 9:03
  • 1
    @ALdaperan I forgot to mention that the TOC heading is just an unnumbered chapter, so that will also be influenced by \chapterfont{\color{blue}}. – Torbjørn T. Oct 7 '12 at 9:19
  • @TorbjørnT. does this also work with chapters in book style? I have changed sections with ease but it did not work for chapters... – Enthusiastic Engineer Oct 30 '14 at 20:36
  • @EnthusiasticStudent Yes, it does. Do you use Book (Standard Class)? – Torbjørn T. Oct 30 '14 at 20:42
  • @TorbjørnT. this is in my preamble: \documentclass[a4paper,12pt,twosided,openright]{book} – Enthusiastic Engineer Oct 30 '14 at 20:45
8

This thread seems to be closed for quite a while, but as I found it right after searching for a solution some minutes ago, I just thought I could add the solution I found for solving the problem.

For all those of you who use KOMA Script Classes: its just adding one line if you are going for changing the color of all headlines during your document; be it chapters, sections, subsections and what not alltogether.

By adding

\setkomafont{disposition}{\normalcolor\bfseries}

you change all the headlines to the standard font you are using during your document, and by replacing \normalcolor by anything you whish you change the color for all headlines. It workes for selfdefined colors and as the other solution it applies for the \tableofcontents, too.

Example

\definecolor{schrift}{RGB}{0,73,114}
\setkomafont{disposition}{\color{schrift}\bfseries}

Here we have an example of code in which I used that method

\documentclass[oneside, 12pt]{scrbook}
\usepackage[ngerman]{babel}
\usepackage[utf8x]{inputenc}
\usepackage{cancel, caption, mathtools, subcaption, amsthm}
\usepackage[usenames,dvipsnames]{color}
\usepackage[margin={0.08\paperwidth,0.10\paperheight}, heightrounded]{geometry}

\parindent 0pt
\parskip 6pt

\makeatletter
\renewcommand{\l@section}{\@dottedtocline{1}{1.5em}{2.6em}}
\renewcommand{\l@subsection}{\@dottedtocline{2}{4.0em}{3.6em}}
\renewcommand{\l@subsubsection}{\@dottedtocline{3}{7.4em}{4.5em}}
\makeatother

\fboxrule0pt

\definecolor{rahmen}{RGB}{0,73,114}
\definecolor{grund}{RGB}{238,241,251}          
\definecolor{schrift}{RGB}{0,73,114}

\captionsetup{format=plain, labelfont={color=rahmen,bf}}

\SetSymbolFont{letters}{normal}{OML}{cmbr}{m}{it}
\SetSymbolFont{operators}{normal}{OT1}{cmbr}{m}{n}
\SetSymbolFont{symbols}{normal}{OMS}{cmbr}{m}{n}
\DeclareMathAlphabet{\mathbf} {OT1}{cmbr}{bx}{n}

\setkomafont{disposition}{\color{schrift}\bfseries}

\captionsetup{format=plain, labelfont={color=schrift,bf}}

\allowdisplaybreaks

\hfuzz 100pt
\hbadness 10000

\renewcommand{\chapterheadstartvskip}{\vspace *{-\baselineskip }}

\begin{document}

\chapter{Zentralkraftbewegungen}
\section{Erhaltungsgr\"oßen der Zentralkraftbewegung}
\subsection{Der Lenz-Runge Vektor}

\begin{equation}
    \Lambda =   \frac{1}{m\alpha} \Big( \mathbf{p} \times \mathbf{L} \Big) - \mathbf{e}_r
\end{equation}

Zu zeigen:

\begin{equation*}
    \Lambda = \mathrm{~const.} \leftrightarrow \frac{\mathrm{d}}{\mathrm{d}t} ~\Lambda = 0
\end{equation*}

Zur Diskussion des Problems sind Zylinderkoodinaten mit konstanter Höhe erforderlich. Wähle also als Höhe $z=0$. Der Nabla-Operator in Zylinderkoordinaten hat die Form

\begin{equation}
    \boldsymbol\nabla   = \mathbf{e}_r \frac{\partial}{\partial r} + \mathbf{e}_{\varphi} \frac{1}{r} \frac{\partial}{\partial \varphi} + \mathbf{e}_z \frac{\partial}{\partial z} 
\end{equation}

Das Keplerpotential hat die Form

\begin{equation}
    V = -\frac{\alpha}{r}
\end{equation}

\begin{proof}[Beweis für den Lenz-Runge Vektor als Erhaltungsgröße des Keplerproblems]
\begin{align*}
    \frac{\mathrm{d}}{\mathrm{d}t} \Lambda      &= \frac{\mathrm{d}}{\mathrm{d}t} \bigg\{ \frac{1}{m\alpha} \Big(\mathbf{p} \times \mathbf{L} \Big) \bigg\} - \dot{\mathbf{e}}_r \\
                                                &= \frac{1}{m\alpha} \frac{\mathrm{d}}{\mathrm{d}t} \bigg\{ \mathbf{p} \times \mathbf{L} \bigg\} - \dot{\mathbf{e}}_r \\
                                                &= \frac{1}{m\alpha} \bigg\{ \dot{\mathbf{p}} \times \mathbf{L} + \cancel{\mathbf{p} \times \dot{\mathbf{L}}} \bigg\} - \dot{\mathbf{e}}_r 
\end{align*}

\noindent\fcolorbox{rahmen}{grund}{\parbox{\linewidth -2\fboxsep -2\fboxrule}{%
Für die Kraft $\mathbf{F}$ folgt aus der Konservativität und dem Keplerpotential

\begin{equation}
    \mathbf{F}  = -\boldsymbol\nabla V 
                = - \bigg[\Big( \mathbf{e}_r \frac{\partial}{\partial r} + \mathbf{e}_{\varphi} \frac{1}{r} \frac{\partial}{\partial \varphi} + \mathrm{e}_z \frac{\partial}{\partial z}  \Big) \cdot \Big(-\frac{\alpha}{r} \Big) \bigg] 
                = -\mathbf{e}_r \frac{\alpha}{r^2}
\end{equation}
}}

\begin{align*}
    \frac{\mathrm{d}}{\mathrm{d}t} \Lambda      &= \frac{1}{m\alpha} \bigg\{ \mathbf{F} \times \mathbf{L} \bigg\} - \dot{\mathbf{e}}_r \\
                                                &= -\frac{1}{mr^2} \bigg\{ \mathbf{e}_r \times \mathbf{L} \bigg\} - \dot{\mathbf{e}}_r \\
\end{align*}
\end{proof}
\end{document}

Which produces the output

page one of two of that document

  • 1
    Welcome to TeX.SX! Could you provide a complete example and a screen shot, to make this a real answer? – user31729 Aug 22 '14 at 10:56

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.