11

I want to have sidenotes (alternate footnotes) in the margin. I found this code on the Latex Community website.

\newcommand{\sidenote}[1]{%
        \refstepcounter{sidenote}\mbox{\textsuperscript{\alph{sidenote}}}%
        \marginpar{\footnotesize \mbox{\textsuperscript{\alph{sidenote}} }#1}%
}
\newcounter{sidenote}

It works, in general, but there is some personalization I would like to make:

  1. I would like to have my sidenotes in the opposite (inner) margin. I tried to change the \marginpar to \reversemarginpar, but it did not work. It actually put my sidenotes into the main body of text!

  2. I would like to have these fit into paragraph style. (I use the fnpara package to accomplish a similar effect with my footnotes.)

MWE (as requested):

\documentclass[letter]{book}

\newcommand{\sidenote}[1]{%
        \refstepcounter{sidenote}\mbox{\textsuperscript{\alph{sidenote}}}%
        \marginpar{\footnotesize \mbox{\textsuperscript{\alph{sidenote}} }#1}%
}
\newcounter{sidenote}

\begin{document}

In the beginning\sidenote{Gn 1:1; Pr 8:22-31; Jn 8:58; 17:5; Cl 1:17-18; He 1:8-12; 7:3; 13:8; 1Jn 1:1; Rv 1:4,8,11,17; 2:8; 3:14; 21:6; 22:13} the Word\sidenote{Is 55:11; Jn 1:14; He 4:12; 1Jn 1:1; 5:7; Rv 1:2; 19:13} was \ldots

\end{document}
cgnieder
  • 66,645

2 Answers2

10

The margins are set differently for odd/even pages. So you need to adjust \marginparwidth in order for the \marginpar to fit inside the inner margin:

enter image description here

\documentclass[letter]{book}

\renewcommand{\verse}[1]{\textsuperscript{#1}}

\newcommand{\sidenote}[1]{% \sidenote{<side note>}
  \refstepcounter{sidenote}\mbox{\textsuperscript{\alph{sidenote}}}%
  \marginpar{\footnotesize\raggedright\strut\mbox{\textsuperscript{\alph{sidenote}} }#1}%
}
\newcounter{sidenote}
\setlength{\marginparwidth}{.8in}
\reversemarginpar
\newcommand{\note}[1]{[#1]}

\begin{document}

\verse{1} \note{\textbf{P}} In the beginning%
  \sidenote{Gn 1:1; Pr 8:22-31; Jn 8:58; 17:5; Cl 1:17-18; He 1:8-12; 7:3; 13:8; 1Jn 1:1; Rv 1:4,8,11,17; 2:8; 3:14; 21:6; 22:13} 
  the Word\sidenote{Is 55:11; Jn 1:14; He 4:12; 1Jn 1:1; 5:7; Rv 1:2; 19:13} 
  was \note{\textit{the Word already existed; there was the Word}}.
\newpage
\verse{2} \note{\textbf{P}} In the beginning%
  \sidenote{Gn 1:1; Pr 8:22-31; Jn 8:58; 17:5; Cl 1:17-18; He 1:8-12; 7:3; 13:8; 1Jn 1:1; Rv 1:4,8,11,17; 2:8; 3:14; 21:6; 22:13} 
  the Word\sidenote{Is 55:11; Jn 1:14; He 4:12; 1Jn 1:1; 5:7; Rv 1:2; 19:13} 
  was \note{\textit{the Word already existed; there was the Word}}.
\end{document}

I've added a \raggedright to the \marginpar alignment to make for better reading.


The following is an implementation using flowfram to manage the flow of text from one page to the next. In fact, flowfram mimics the boundaries set by geometry by setting up frames (static, dynamic and flow). We use the last two to create the solution.

The flow frames contain the text block detail, while dynamic frames contain the side notes. Each odd/even page uses its own flow and dynamic frame, the latter being appended with a new side note as they are used. A supplementary \sidenoteblock is kept to measure the height of the side notes on the page. If the side note addition exceeds the text block height, a \newpage is issued and the side note is reset.

enter image description here

\documentclass{book}
\newlength{\innermargin}\setlength{\innermargin}{\dimexpr1in+2em}
\setlength{\marginparwidth}{.75in}
\usepackage[twoside,hmargin={\innermargin,1.5in}]{geometry}% http://ctan.org/pkg/geometry
\usepackage{flowfram}% http://ctan.org/pkg/flowfram
\usepackage{everyshi}% http://ctan.org/pkg/everyshi
\usepackage{lipsum}% http://ctan.org/pkg/lipsum

% Regular odd/even text blocks
%  \newflowframe[<page list>]{<width>}{<height>}{<x>}{<y>}[<label>]
\newflowframe[odd]{\textwidth}{\textheight}{0pt}{0pt}[oddpage]
\newflowframe[even]{\textwidth}{\textheight}{0pt}{0pt}[evenpage]
% Inner odd/even margin blocks
%  \newdynamicframe[<page list>]{<width>}{<height>}{<x>}{<y>}[<label>]
\newdynamicframe[odd]{\marginparwidth}{\textheight}
  {\dimexpr-\marginparsep-\marginparwidth}{0pt}[oddsidenote]
\newdynamicframe[even]{\marginparwidth}{\textheight}
  {\dimexpr\textwidth+\marginparsep}{0pt}[evensidenote]
\EveryShipout{% At every shipout
  \setdynamiccontents*{oddsidenote}{\rule{0pt}{1em}\footnotesize\raggedright}% Clear odd side notes
  \setdynamiccontents*{evensidenote}{\rule{0pt}{1em}\footnotesize\raggedright}% Clear even side note
  \gdef\sidenoteblock{\footnotesize\raggedright}%
}
\AtBeginDocument{% At \begin{document}
  \setdynamiccontents*{oddsidenote}{\rule{0pt}{1em}\footnotesize\raggedright}% Clear odd side notes
  \setdynamiccontents*{evensidenote}{\rule{0pt}{1em}\footnotesize\raggedright}% Clear even side note
  \gdef\sidenoteblock{\footnotesize\raggedright}%
}
\AtEndDocument{% At \begin{document}
  \appenddynamiccontents*{oddsidenote}{\par}% Finalize odd side notes
  \appenddynamiccontents*{evensidenote}{\par}% Finalize even side notes
}

\makeatletter
\newcounter{sidenote}\renewcommand{\thesidenote}{\arabic{sidenote}}
\newcommand{\sidenoteblock}{}
\newcommand{\sidenote}[1]{% \sidenote{<side note>}
  \refstepcounter{sidenote}%
  \protected@edef\the@sidenote{\textsuperscript{\thesidenote}}% http://tex.stackexchange.com/a/40006/5764
  \expandafter\g@addto@macro\expandafter\sidenoteblock\expandafter{\the@sidenote #1\space}%
  \sbox0{\begin{minipage}{.75in}\sidenoteblock\end{minipage}}%
  \ifodd\value{page}%
    \getdynamicid{\@tempb}{oddsidenote}%
  \else
    \getdynamicid{\@tempb}{evensidenote}%
  \fi%
  \ifdim\dimexpr\ht0+\dp0>\textheight%
    \appenddynamiccontents{\@tempb}{\par}%
    \newpage\addtocounter{sidenote}{-1}%
    \sidenote{#1}%
  \else
    \textsuperscript{\thesidenote}%
    \expandafter\appenddynamiccontents\expandafter{\expandafter\@tempb\expandafter}\expandafter{\the@sidenote #1\space}%
  \fi
}
\makeatother
\begin{document}
\sidenote{Here is the first side note.}\lipsum[1]
\sidenote{Here is the second side note.}\lipsum[2]
\sidenote{This is the third side note.}\lipsum[3]
\sidenote{Here is another, now the fourth, side note.
  Here is another, now the fourth, side note.
  Here is another, now the fourth, side note.
  Here is another, now the fourth, side note.
  Here is another, now the fourth, side note.
  Here is another, now the fourth, side note.
  Here is another, now the fourth, side note.
  Here is another, now the fourth, side note.
  Here is another, now the fourth, side note.
  Here is another, now the fourth, side note.
  Here is another, now the fourth, side note.
  Here is another, now the fourth, side note.}\lipsum[4]
\sidenote{Side note number five.}\lipsum[5]
\sidenote{Another, the sixth one.}\lipsum[6]
\sidenote{More side notes are coming. This is number seven.}\lipsum[7]
\sidenote{Eight, yes, this is the eighth.}\lipsum[8]
\end{document}

Caveat: The above solution will not work for a side note that is longer that the text block height.


You can define

\newcommand{\sidenote}[2]{% \sidenote{<word>}{<side note>}
  \refstepcounter{sidenote}%
  \protected@edef\the@sidenote{\textsuperscript{\thesidenote}}% http://tex.stackexchange.com/a/40006/5764
  \expandafter\g@addto@macro\expandafter\sidenoteblock\expandafter{\the@sidenote #2\space}%
  \sbox0{\begin{minipage}{.75in}\sidenoteblock\end{minipage}}%
  \ifodd\value{page}%
    \getdynamicid{\@tempb}{oddsidenote}%
  \else
    \getdynamicid{\@tempb}{evensidenote}%
  \fi%
  \ifdim\dimexpr\ht0+\dp0>\textheight%
    \appenddynamiccontents{\@tempb}{\par}%
    \newpage\addtocounter{sidenote}{-1}%
    \sidenote{#1}{#2}%
  \else
    #1\textsuperscript{\thesidenote}%
    \expandafter\appenddynamiccontents\expandafter{\expandafter\@tempb\expandafter}\expandafter{\the@sidenote #2\space}%
  \fi
}

that allows you to use \sidenote{<word>}{<side note>}, which makes sure that <word> and <side note> are always together, while the side note reference always follows the word; similar to

... blah blah blah word7 blah blah blah ...

Werner
  • 603,163
  • Werner, This perfectly answers the desire to switch sides for the notes. Out of curiosity, why did you also add \strut? I couldn't tell a difference when it was there or not.

    Any thoughts on the paragraph style in the sidenotes?

    – themarshian Oct 17 '12 at 20:00
  • With the paragraph style, I would like for the notes to start at the top of the page, regardless of where the first note is. Is this possible? – themarshian Oct 17 '12 at 20:03
  • @themarshian: The \strut is not always necessary, but it sometimes used when dealing with paragraph boxes to allow for an even height of the first/last line. Since you're not using it in paragraph text, it could probably be removed. Regarding paragraph style: I'll look into such options, but it would not be easy. What should happen to if the entire margin is filled with sidenotes yet you still want to add more? Where do they go? – Werner Oct 17 '12 at 20:13
  • If the sidenote gets too full, it ideally would force the start of the next page, moving the corresponding main text with it. – themarshian Oct 17 '12 at 20:49
  • @themarshian: Wow, asking for the moon and the stars! :) Interaction between the text block and the margin block would require some overhead. As mentioned, an interesting problem, but a large scope in general... – Werner Oct 17 '12 at 20:54
  • It looks like the \sidenote package (that @cgnieder mentioned above) accomplishes similar things to the inserted code. However, the markers are numbers rather than letters. Not sure how easy it would be to change that, as well as change the format to paragraph style. I found nothing in the documentation that allowed for that... – themarshian Oct 17 '12 at 22:21
  • You asked an open question, and I gave you the ideal answer. However, I am fine to need to either filter down my sidenotes, or insert an \endpage as needed to make the sidenotes behave properly. The biggest thing I am looking for is the ability to have my sidenotes in paragraph form, to remove as much of the dead white space as possible. – themarshian Oct 18 '12 at 16:55
  • @themarshian: The paragraph formatting is the most difficult, since one is not relying on the default LaTeX placing mechanism. I'm working on a technique using the flowfram package. – Werner Oct 18 '12 at 19:59
  • @themarshian: I've added your request to my answer. Technically this should work with your similar question under memoir: memoir class, \sidebar formatting. Let me know/give some feedback. – Werner Oct 20 '12 at 04:42
  • you are a genius! This is incredible. The only caveat I have run into so far is that, when I made a few changes to the spacing and margins, the total number of sidenotes on the page did not change. I made the following changes to lines 2-4: \newlength{\innermargin}\setlength{\innermargin}{\dimexpr3in+2em} \setlength{\marginparwidth}{1.75in} \usepackage[twoside,hmargin={\innermargin,1.25in}]{geometry} It still only kept 8 notes on the first page, even though there was room for more notes and main text. – themarshian Oct 20 '12 at 16:22
  • Also, is there a way, if the sidenote column is too full and it forces a new page, that the sidenote reference stays connected to the word it is connected to, that they both come down? (I use the sidenotes after words, not before). – themarshian Oct 20 '12 at 16:39
  • @themarshian: So you have a \sidenote that is associated with a specific word, and you use the \sidenote after the word? For this you would need to rather supply the word as an additional argument to \sidenote. For example, perhaps something like \sidenote{<word>}{<side note>}. That way you can capture the word and reset it on the following page. Would this not look weird though? – Werner Oct 20 '12 at 18:44
  • Yes, that would work, though that changes the position of the sidenote marker to the beginning of the word, rather than afterward. I prefer it at the end. I also had to put it in the following format: \sidenote{<side note>}{<word>} rather than your suggested \sidenote{<word>}{<side note>}. – themarshian Oct 20 '12 at 19:09
  • @themarshian: The order of the arguments are not the problem; it's how they are used in the replacement text for the macro \sidenote. I've defined \sidenote{<word>}{<side note>} in my updated answer which probably addresses your page-breaking concerns. – Werner Oct 20 '12 at 21:22
  • I had to increase the size defined in \sbox{minipage} in order for the page break to work properly. Other than that, this works perfectly! Thank you! – themarshian Oct 23 '12 at 16:56
  • @themarshian: Yes, the sizes I chose were based on a guess for what your margins were. However, they're adjustable to your needs. – Werner Oct 23 '12 at 16:58
2

You can use footmisc package with option side, which replaces footnotes for numbered \marginpars, reformating \thefootnote for alphabetic references with

\renewcommand{\thefootnote}{\alph{footnote}}

Notice that if you have long footnotes, you might need to load marginfix to dea with page breaks. Also, even with marginfix, if you have too many footnotes you might run into Too many floats errors.

Here's a MWE:

\documentclass[twoside]{article}
\usepackage[side]{footmisc}
\renewcommand{\thefootnote}{\alph{footnote}}
\usepackage{kantlipsum}% dummy text
\usepackage{marginfix}
\begin{document}
This is a short footnote\footnote{Short footnote.} and another\footnote{Another short footnote.}.

\kant*[3]\footnote{Yet another short one.}

\kant*[4]\footnote{But: Too many (or too long) footnotes won't work for these are still marginpars. \emph{That's why we need \textbf{marginfix}}}

\kant*[5]\footnote{\kant*[6]}

\kant*[7]\footnote{\kant*[8]}

\kant*[9]\footnote{\kant*[10]}

Marginfix however might have a limit for too many footnotes will become too many floats, and you might end up with none being typeset.
\end{document}

The memoir class also provides a \sidebar and a \sidefootnote command: while the latter behaves pretty much like a \marginpar (the note is typeset next to its anchor), the first typesets all sidenotes in the bottom of the page.

henrique
  • 6,616
  • Any way you know of to have the sidenotes that either the \footmisc package or the memoir class creates to be in paragraph style, similar to the effect that fnpara does for footnotes? – themarshian Oct 18 '12 at 16:52
  • I'm sorry, I had completely ignored that request! footmisc provides a para option, but it is incompatible with its side option. I don't know if memoir can do it. – henrique Oct 18 '12 at 18:13