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:

1st solution, just using tikz
Here's a solution that renews the \marginpar command and uses TikZ to provide very flexible decorations

\documentclass{article}
\usepackage{tikz}
\usepackage{lipsum}
\let\oldmarginpar\marginpar
% 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]{%
\oldmarginpar{%
\tikz \node at (0,0) [#1]{#2};}%
}
\begin{document}
\marginpar{margin text here}
\lipsum[1]
\marginpar[fill=red,text=yellow,circle]{margin text here}
\lipsum[2]
\end{document}
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

\documentclass{article}
\usepackage[xcolor]{mdframed}
\usepackage{lipsum}
%====================================
% shamelessly copied from tufte documentclass
%====================================
\makeatletter
% Margin float environment
\newsavebox{\@my@margin@floatbox}
\newenvironment{@my@margin@float}[1][-1.2ex]%
{%
\begin{lrbox}{\@my@margin@floatbox}%
\begin{minipage}{\marginparwidth}%
\hbox{}\vspace*{#1}%
\noindent%
}
{\end{minipage}%
\end{lrbox}%
\marginpar{\usebox{\@my@margin@floatbox}}%
}
% marginpar environment
\newenvironment{mymarginpar}[1][-1.2ex]%
{\begin{@my@margin@float}[#1]%
\begin{mdframed}[backgroundcolor=black!30,linecolor=red]%
}%
{\end{mdframed}\end{@my@margin@float}}
\makeatother
\begin{document}
\begin{mymarginpar}
margin text here
\end{mymarginpar}
\lipsum
\end{document}
If you want rounded corners, you can investigate the tikz-method of the mdframed, see the documentation for details.
mymarginparwithmarginpar? – cmhughes Aug 23 '12 at 19:01tikz, perhaps you'll prefer this anyway :) – cmhughes Aug 23 '12 at 22:14\node[text width=1in]to the Tikz if you want margin to wrap – Algeboy Aug 10 '23 at 12:54