# How can I label marginpars or marginnotes to be able to refer to them? [duplicate]

In a 200 page document I have 20-30 portions, 2-5 sentences long usually, scattered throughout that discuss something about statistics. My thought is to add a marginpar for each statistics portion.

My question is whether I can label each marginpar uniquely so that I am able to ref-er to it (and thus to the few sentences on statistics). [While tagging this question, marginnote appeared, and that might be an alternative to be labelled.)

EDIT: The reference to another question that shows how to number marginpar items, like footnotes are numbered sequentially, is very helpful, but doesn't explain how then to refer to a numbered marginpar later in the document.

If this is possible, it seems it will require a counter (need counter to refer to text that has been labeled). But being a beginner, I don't know whether the basic idea is a dead end let alone how to code it.

I am using R, RStudio, and the knitr package on Windows.

## marked as duplicate by Dr. Manuel Kuehner, Stefan Pinnow, CarLaTeX, Mico, egreg cross-referencing StackExchange.ready(function() { if (StackExchange.options.isMobile) return; $('.dupe-hammer-message-hover:not(.hover-bound)').each(function() { var$hover = $(this).addClass('hover-bound'),$msg = $hover.siblings('.dupe-hammer-message');$hover.hover( function() { $hover.showInfoMessage('', { messageElement:$msg.clone().show(), transient: false, position: { my: 'bottom left', at: 'top center', offsetTop: -7 }, dismissable: false, relativeToBody: true }); }, function() { StackExchange.helpers.removeMessages(); } ); }); }); Apr 1 '17 at 16:47

• Your question leaves all the effort to our community, even typing the essentials of a TeX document such as \documentclass{}...\begin{document} etc. As it is, most of our users will be very reluctant to touch your question, and you are left to the mercy of our procrastination team who are very few in number and very picky about selecting questions. You can improve your question by adding a minimal working example (MWE) that more users can copy/paste onto their systems to work on. If no hero takes the challenge we might have to close your question. – Dr. Manuel Kuehner Apr 1 '17 at 13:26
• Related: tex.stackexchange.com/questions/137546 (googled marginpar latex reference) – Dr. Manuel Kuehner Apr 1 '17 at 13:53

EDIT: As Dr. Manuel Kuehner mentioned in the comments, there is a package called marginnote, therefore the naming of the provided code is perhaps bad. Because of that I changed the \marginnote to \mymarginnote

This is a small setup, which allows what (I think) you want:

\documentclass[]{scrartcl}

\usepackage{lipsum}

\newcounter{marginnotenumber}[section]
\let\themarginbak\themarginnotenumber
\renewcommand{\themarginnotenumber}{\thesection.\themarginbak}
\newcommand{\mymarginnote}[2]{%
\marginpar{%
\refstepcounter{marginnotenumber}\label{#1}\themarginnotenumber: #2%
}%
}

\begin{document}
\section{first section}
\lipsum[1-2]
\mymarginnote{not:mylab}{This is a marginnote}
\section{second section}
\lipsum[1-2]
also see marginnote \ref{not:mylab}.
\end{document}


In a book (containing chapters) you might want to define the counter like this:

\newcounter{marginnotenumber}[chapter]
\let\themarginbak\themarginnotenumber
\renewcommand{\themarginnotenumber}{\thechapter.\themarginbak}

• There is also a package called marginnote(ctan.org/pkg/marginnote). Maybe it's better to choose another name to avoid confusion. It is from the author of the KOMA-Script (ctan.org/author/kohm). – Dr. Manuel Kuehner Apr 1 '17 at 13:28
• Yeah, I guess you're right. I'll edit my answer. And sorry, that I did touch the question despite there is no MWE :) – Skillmon Apr 1 '17 at 13:30