I often use \marginpar{} which is boring to me. Is there a way to add grey background and round black edges so it would look like this:

Wanted marginpar


1st solution, just using tikz

Here's a solution that renews the \marginpar command and uses TikZ to provide very flexible decorations

enter image description here


% renew the \marginpar command to draw 
% a node; it has a default setting which 
% can be overwritten
\renewcommand{\marginpar}[2][rectangle,draw,fill=orange,rounded corners]{%
        \tikz \node at (0,0) [#1]{#2};}%

\marginpar{margin text here}

\marginpar[fill=red,text=yellow,circle]{margin text here}

2nd solution, using mdframed

This one uses the mdframed package for the framing, and defines an environment rather than a command. I've copied some code from the tufte document class to define an environment mymarginpar


%   shamelessly copied from tufte documentclass
% Margin float environment

% marginpar environment

  margin text here

If you want rounded corners, you can investigate the tikz-method of the mdframed, see the documentation for details.

  • Nice to see my package ;-) However I don't know whether a standard TikZ implementation is easier. – Marco Daniel Aug 23 '12 at 18:47
  • This example you provided returns an error: "! LaTeX Error: Command \marginpar already defined." – 71GA Aug 23 '12 at 18:58
  • @71GA not for me- are you sure you're using it as-is? Or have you tried to replace mymarginpar with marginpar? – cmhughes Aug 23 '12 at 19:01
  • I am sure tried it once more. It doesnt work. I literally copied your example. – 71GA Aug 23 '12 at 21:03
  • @71GA not sure what's going on, perhaps an update is in order. Meanwhile, I've added another solution that uses tikz, perhaps you'll prefer this anyway :) – cmhughes Aug 23 '12 at 22:14

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.