> For the complete documentation index, see [llms.txt](https://overleaf-pro.ayaka.space/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://overleaf-pro.ayaka.space/latex/formatting/15-margin-notes.md).

# Margin notes

## Introduction

This article explains how to create margin notes, a popular alternative to footnotes as a device for adding supplementary information to support the main text of a document. We also have a [help page on the `todonotes` package](/latex/questions-and-answers/04-can-i-add-inline-or-margin-comments-to-the-pdf.md) which provides alternative solutions to those presented in this article.

## The \marginpar command

Without loading any additional packages you can use the built-in LaTeX `\marginpar` command to add margin notes to your document. The general form of the `\marginpar` command is

`\marginpar[*left text*]{*right text*}`

where `*left text*` will be used if the margin note appears on the left of a document page and `*right text*` if appears on the right. To be more specific, marginal notes are normally put on the “outside” of the page—although the meaning of “outside” depends on the document class you are using and whether you have specified the `twoside` package option:

* `book` class (`\documentclass{book})` documents are two-sided by default (design)
* `report` class (`\documentclass{report}`) and `article` class (`\documentclass{article}`) documents are, by default, single-sided. To make them two-sided you have to specify the `twoside` option:
  * `\documentclass[twoside]{report}`, or
  * `\documentclass[twoside]{article}`

For single-sided documents, excluding right-to-left languages, such as Arabic, the “outside” is always the right-hand edge of the text and for two-sided documents it is the left-hand edge of the text for left-hand pages and the right-hand edge of the text for right-hand pages.

### Reversing placement of margin notes

The command `\reversemarginpar` reverses the side on which margin notes are typeset; its effect can be undone by the command `\normalmarginpar`. As stated in the LaTeX source code documentation “These commands have no effect for two-column output.”

### Commands affecting margin note typesetting

Typesetting of `\marginpar` notes makes use of several dimension commands which store values that can be changed, if required:

* `\marginparwidth`: determines the width of margin notes and thus the length of lines typeset in the margin note.
* `\marginparsep`: sets the gap (distance) between margin notes and the text of your document.
* `\marginparpush`: defines the minimum separation (vertical) distance between `\marginpar` notes.

### Changing the typesetting of margin notes: ragged right and ragged left

By default, the text of a margin note is typeset is a box which produces typeset lines of width `\marginparwidth`. This can result in unsightly gaps between typeset words as the TeX engine tries to find the “best” line breaks. You can use the commands `\raggedright` and `\raggedleft` to alter the typeset style of the text.

### Example

Here is an example which uses several `\marginpar` commands to demonstrate some of the features listed above. The example also loads the [`geometry`](https://ctan.org/pkg/geometry) package to create a small page size and the [`hyperref`](https://ctan.org/pkg/hyperref) package which provides the `\url` command used to credit the source of the text (in the footnote).

```latex
\documentclass[twoside]{article} % Note: uses twoside option
\usepackage[a4paper, marginparwidth=75pt, total={10cm, 10cm}]{geometry} % To create a small page
\usepackage{hyperref} % To use the \url command (in the footnote)
\usepackage{marginnote}
\begin{document}
\section{Lorem Ipsum}
\footnote{Source text: Wikipedia (\url{https://en.wikipedia.org/wiki/Lorem_ipsum})}But I must explain to you how all this mistaken idea of reprobating pleasure and extolling pain arose. To do so, I will give you a complete account of the system, and expound the actual teachings of the great explorer of the truth, the master-builder of human happiness. \marginpar[Note 1: text for left-hand side text]{Note 1: text for right-hand side of pages, it is set justified.} No one rejects, dislikes or avoids pleasure itself, because it is pleasure, but because those who do not know how to pursue pleasure rationally encounter consequences that are extremely painful. Nor again is there anyone who loves or pursues or desires to obtain pain of itself, because it is pain, but occasionally circumstances occur in which toil and pain can procure him some great pleasure.  \marginpar[Note 2: text for left-hand side text]{\raggedright Note 2: text for right-hand side of pages, it is not justified, but uses \texttt{\string\raggedright}.} To take a trivial example, which of us ever undertakes laborious physical exercise, except to obtain some advantage from it? But who has any right to find fault with a man who chooses to enjoy a pleasure that has no annoying consequences, or one who avoids a pain that produces no resultant pleasure? [33] On the other hand, we denounce with righteous indignation and dislike men who are so beguiled and demoralized by the charms of pleasure of the moment, so blinded by desire, that they cannot foresee the pain and trouble that are bound to ensue; and equal blame belongs to those who fail in their duty through weakness of will, which is the same as saying through shrinking from toil and pain. These cases are perfectly simple and easy to distinguish. In a free hour, when our power of choice is untrammeled and when nothing prevents our being able to do what we like best, every pleasure is to be welcomed and every pain avoided. \marginpar[\raggedleft Note 3: text for left-hand side of pages, it is not justified, but uses \texttt{\string\raggedleft}]{Note 3: text for left-hand side of pages}But in certain circumstances and owing to the claims of duty or the obligations of business it will frequently occur that pleasures have to be repudiated and annoyances accepted.  The wise man therefore always holds in these matters to this principle of selection: he rejects pleasures to secure other greater pleasures, or else he endures pains to avoid worse pains.
\end{document}
```

Open this `\marginpar` example in Overleaf

This example produces the following (two pages) of output:

Page 1:

![Example of the \marginpar command](/files/nuEVPECCGMd7nZcR88Y7)

Page 2:

![Example of the \marginpar command](/files/IQm3dq7kiPkQf1s4WQuU)

### The mparhack package: fixing the wrong margin

Internally, LaTeX processes margin notes as a type of “floating” component of your document—similar to the way LaTeX handles floating figures and tables. Due to being "floats", margin notes produced by `\marginpar` can occasionally appear in the wrong margin. The [`mparhack` package](https://mirror.ox.ac.uk/sites/ctan.org/macros/latex/contrib/mparhack/mparhack.pdf) was written to fix this problem so it may be worth using it if you encounter that.

## An alternative to \marginpar: the marginnote package

The [`marginnote` package](https://www.ctan.org/pkg/marginnote) offers a versatile alternative to the `\marginpar` command. `marginnote` implements margin notes using a non-float mechanism, which is different to how `\marginpar` works: `marginnote` resolves some problems but, as its documentation notes, it can introduce others.

### Example

The following example demonstrates the `\marginnote` command provided by the `marginnote` package:

```latex
\documentclass{article}
\usepackage[a5paper, total={3in, 6in}]{geometry} % to create a small page
\usepackage{hyperref} % To use the \url command (in the footnote)
\usepackage{marginnote}
\begin{document}
\section{Lorem Ipsum}
\footnote{Source text: Wikipedia (\url{https://en.wikipedia.org/wiki/Lorem_ipsum})}But I must explain to you how all this mistaken idea of reprobating pleasure and extolling pain arose. To do so, I will give you a complete account of the system, and expound the actual teachings of the great explorer of the truth, the master-builder of human happiness. \marginnote{This is a margin note shifted 2cm, \textit{down} the page, relative to the line in which it is typeset.}[2cm] No one rejects, dislikes or avoids pleasure itself, because it is pleasure, but because those who do not know how to pursue pleasure rationally encounter consequences that are extremely painful. Nor again is there anyone who loves or pursues or desires to obtain pain of itself, because it is pain, but occasionally circumstances occur in which toil and pain can procure him some great pleasure. \reversemarginpar\marginnote{This is another margin note but shifted 2cm \textit{up} the page, relative to the line in which it is typeset. It is also in the left-hand margin.}[-2cm] To take a trivial example, which of us ever undertakes laborious physical exercise, except to obtain some advantage from it? But who has any right to find fault with a man who chooses to enjoy a pleasure that has no annoying consequences, or one who avoids a pain that produces no resultant pleasure? [33] On the other hand, we denounce with righteous indignation and dislike men who are so beguiled and demoralized by the charms of pleasure of the moment, so blinded by desire, that they cannot foresee the pain and trouble that are bound to ensue; and equal blame belongs to those who fail in their duty through weakness of will, which is the same as saying through shrinking from toil and pain. These cases are perfectly simple and easy to distinguish. In a free hour, when our power of choice is untrammeled and when nothing prevents our being able to do what we like best, every pleasure is to be welcomed and every pain avoided. But in certain circumstances and owing to the claims of duty or the obligations of business it will frequently occur that pleasures have to be repudiated and annoyances accepted. The wise man therefore always holds in these matters to this principle of selection: he rejects pleasures to secure other greater pleasures, or else he endures pains to avoid worse pains.
\end{document}
```

Open this example in Overleaf

This example produces the following output:

![Using the marginnote package](/files/3E7smH8wxSEOdH38HlQP)

The above example also loads the `geometry` package to create a small page size and the `hyperref` package which provides the `\url` command used to credit the source of the text (in the footnote). After importing the `marginnote` package by writing `\usepackage{marginnote}` you can use the `\marginnote` command as shown by the two instances in the example text:

* `\marginnote{This is a margin note shifted 2cm, \textit{down} the page, relative to the line in which it is typeset.}[2cm]`
* `\marginnote{This is another margin note but shifted 2cm \textit{up} the page, relative to the line in which it is typeset. It is also in the left-hand margin.}[-2cm]`

In these examples we use a second parameter inside brackets `[ ]` which determines vertical alignment relative to the line where the command is used. The first `\margingnote` command uses `[2cm]` to shift the margin note 2cm *down the page*, the second one uses `[-2cm]` to shift the margin note 2cm *up the page*.

The second `\marginnote` command operates after a `\reversemarginpar` was used, causing it to be placed in the left-hand margin of this single-sided document:

```latex
\reversemarginpar\marginnote{This is another margin note but shifted 2cm \textit{up} the page, relative to the line in which it is typeset. It is also in the left-hand margin.}[-2cm]
```

## Further reading

For more information see

* [The `marginnote` package documentation](http://www.ctan.org/pkg/marginnote)
* [The `mparhack` package documentation](http://www.ctan.org/pkg/mparhack)
* [Page size and margins](/latex/formatting/07-page-size-and-margins.md)
* [Footnotes](/latex/formatting/14-footnotes.md)
* [Lengths in LaTeX](/latex/formatting/01-lengths-in-latex.md)
* [Single sided and double sided documents](/latex/formatting/08-single-sided-and-double-sided-documents.md)
* [Multiple columns](/latex/formatting/09-multiple-columns.md)
* [Headers and footers](/latex/formatting/02-headers-and-footers.md)
* [Paragraph formatting](/latex/formatting/04-articles-how-to-change-paragraph-spacing-in-latex.md)
* [Bold, italics and underlining](/latex/latex-basics/03-bold-italics-and-underlining.md)
* [Font sizes, families, and styles](/latex/fonts/01-font-sizes-families-and-styles.md)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://overleaf-pro.ayaka.space/latex/formatting/15-margin-notes.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
