[Tex/LaTex] Add colour to margin notes

colorfontspecmarginpar

I'm using LyX with XeTeX and the KOMA-script article class. I'm trying secsty and fontspec for the first time.

I'm trying to do a unique layout with large outer margins. On some pages I will put key points or quotes from the main text in the outer margin.

I assumed the best way is to use margin notes. It's important for me to customise the look of these notes – specific colours and font sizes.

Is there a way to change the colour/size of all margin notes in the latex preamble? Is there a completely different solution to what I want to do?

Best Answer

First of all you should load "mparhack", that fixes some problems with marginal notes. Then you should define your command for inserting marginal notes:

\newcommand{\annotation}[1]{\marginpar{#1}}

or maybe

\newcommand{\annotation}[1]{%
  \marginpar{\small\itshape\color{blue}#1}}

if you want to experiment with color. It will be easier for you to change the formatting of all marginal notes without going into the details of the implementation of \marginpar.

For XeLaTeX, if the main font has the Color feature activated, a different trick should be used:

\setmainfont[Color=4C4C4C,Ligatures=TeX]{Linux Libertine O}
\newfontfamily{\annfont}[Color=0000FF,Ligatures=TeX]{Linux Libertine O}

\newcommand{\annotation}[1]{%
  \marginpar{\annfont\small\itshape#1}}

In other words, we duplicate the main font family with a different color. If other families are used in marginal notes, they should be duplicated as well. If there is a small number of marginal notes, also

\newcommand{\annotation}[1]{%
  \marginpar{\addfontfeature{Color=0000FF}\small\itshape#1}}

can be used, without duplicating the font families; note, however, that this causes a big overhead, since a new font families will be defined on the fly for each marginal note.