# Add colour to margin notes

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?

-

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]{%


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.

-
Thanks. I've got the following in my preamble: \usepackage{mparhack} \newcommand{\annotation}[1]{% \marginpar{\small\itshape\color{blue}#1}} It is small and italic, but the color will not change to blue. I just checked; it is because I have \setmainfont [Color=4c4c4c]{URW Palladio L} in the preamble before it. What is my workaround? I want 4c4c4c for all body text, but blue for margin notes. How can I make this happen? Thanks! –  oldmankit May 12 '11 at 9:26
@oldmankit: instead of \color{blue} say \addfontfeature{Color=0000FF} –  egreg May 12 '11 at 10:08
Solved. Awesome! Thank you very much. –  oldmankit May 14 '11 at 1:48
I've switched my document to two-sided, and now it's broken! The margin notes still look lovely on odd pages, but on even pages, the colour (and text size change) isn't being applied. Can you guess why that might be? –  oldmankit Jul 11 '11 at 5:04
I've added a better advice; try it. With a two sided document the marginal notes are blue in each page. –  egreg Jul 11 '11 at 9:05

Apart from redefining the \marginpar command, as shown by @egreg, you can have a look at the tufte class which provides a fully customized environment for article and book, featuring large margins where small figures, references, and notes go right away. Included is a redefinition of margin note (in fact everything, including footnotes, are considered as numbered or unumbered "sidenote"), which looks like this:

(Snapshot grabbed from the handout example file.)

You can customize the \marginnote command as you want. For example, using @egreg's example, we would just put the following command in the preamble:

\setmarginnotefont{\small\itshape\color{blue}}


which produces the desired effect:

-
This looks hopefully. Two problems though: first, I can't use a landscape layout with tufte-handout for some reason. It is greyed-out as an option. Second, when I put \setmarginnotefont{\small\itshape\color{blue}} into the preamble, it gives me an xetex error: "Undefined control sequence." It says the control sequence was never \def'ed. –  oldmankit May 12 '11 at 8:48
@oldmankit I used this class for a textbook, compiled with xelatex (not xetex). I tested the above suggestion, and it seems to work. Not sure about the landscape option, but I would not be surprised it doesn't work well with Tufte class. –  chl May 12 '11 at 9:08
Hmmm, landscape is necessary for the layout of this document. I can see that tufte is better suited to my design goals in terms of automatically wide margins etc., but the landscape thing is a show-stopper. –  oldmankit May 14 '11 at 1:50

Try using the todonotes package. It does all that for you: you just have to try to forget that it does that for the purpose of inserting "todo" items. Think of these items in your terms, and ignore the package terminology.

-