3

I would like to build a simple 2-column table that will let me attach, to one of the lines in the table, a marginal note in the right margin, for example:

A      B
CC     DDD                              This is a marginal note.
E      FF

I'm using the LaTeX style called tufte-book which, by default, puts \marginnote text into the right margin. (Does the same for \footnote.) See: http://www.latextemplates.com/template/tufte-style-book

But this is not really a problem with the style. My problem is that, no matter whether I use LaTeX tabular, or Plain TeX halign, or even Plain Tex tabs, I get an error like "Not in outer par mode" in the line where I have put the \marginnote.

Because my table requirement is very modest, I also tried this macro:

\def\oneline#1#2{\hbox{\hbox to 10ex{#1}#2}}

Works fine until I do something like:

\oneline{AA}{BB\marginnote{CC}}

which prompts the "Not in outer par mode." The offending agent in the macro is the first hbox, but if I remove that, then my two columns end up on different lines.

Any ideas would be appreciated.

7

\marginnote can not be used inside a tabular. But you can simply use a tabular and insert the margin note after it.

MWE:

\documentclass{tufte-book}

\begin{document}

\begin{tabular}{ll}
A   &   B\\
CC  &   DDD\\
E   &   FF
\end{tabular}
\marginnote{This is a marginal note.}

\end{document} 

Output:

enter image description here

If you need the margin note next to another row, you can use the optional argument of \marginnote to raise it up or down.

For example, to have it next to the first row, use

\marginnote[-\baselineskip]{This is a marginal note.}

enter image description here

In the case of the first row, instead of using the optional argument, you can simply use

\begin{tabular}[t]{ll}

and, in the case of the last row

\begin{tabular}[b]{ll}
  • I might be simpler to use \begin{tabular}[t] for the last one. – yo' Mar 10 '15 at 10:45
  • @yo' You're right, I'll add in the answer. Anyway showing the method with the optional argument can be useful for longer tables. – karlkoeller Mar 10 '15 at 10:49
  • I ended up using \halign with the optional argument to `\marginnote' because I do indeed want to put the note next to a specific row (and because I prefer Plain TeX if I can use it). The optional argument is not an ideal solution, e.g. if a table splits over a page break, or if linespacing changes, but it is good enough for my needs. Thank you very much! – Iron Pillow Mar 12 '15 at 23:29
  • @IronPillow you're welcome. – karlkoeller Mar 13 '15 at 5:26
2

The marginnote package can handle margin notes in tables, so try sticking

\let\marginnote\undefined
\usepackage{marginnote}

\usepackage{etoolbox}
\makeatletter
\patchcmd{\@mn@margintest}{\@tempswafalse}{\@tempswatrue}{}{}
\patchcmd{\@mn@margintest}{\@tempswafalse}{\@tempswatrue}{}{}
\makeatother

in the preamble and it should work. The first two lines redefine the \marginnote command, and the rest (taken from this answer by Gonzalo Medina) makes sure the notes are always placed in the right margin instead of the outer margin.

Now the following code gives the desired result:

\begin{tabular}{ll}
A&B\\
CC&DDD\marginnote{This is a marginal note.}\\
E&FF
\end{tabular}

(This also allows notes on more than one line of the table.) You must compile twice for the notes to end up in the right place.


Also note that marginnote margin notes have a different font size, but this can be changed with the following code, which also lets you use the syntax of the default margin notes of the tufte-book class for vertical adjustment.

\let\marginnote\undefined
\usepackage{marginnote}
\let\oldmarginnote\marginnote
\renewcommand{\marginnote}[2][0pt]{\oldmarginnote{\footnotesize#2}[#1]}

\usepackage{etoolbox}
\makeatletter
\patchcmd{\@mn@margintest}{\@tempswafalse}{\@tempswatrue}{}{}
\patchcmd{\@mn@margintest}{\@tempswafalse}{\@tempswatrue}{}{}
\makeatother

One problem with the marginnote package is that marginnotes that are called on the same line end up printed on top of each other, instead of floating down as the default margin notes. The best solution to this I think is to create two different commands, one for tables and one for text:

\let\tuftenote\marginnote
\let\marginnote\undefined
\usepackage{marginnote}
\let\marginnotemarginnote\marginnote
\let\marginnote\tuftenote
\newcommand{\marginnoteintable}[2][0pt]{\marginnotemarginnote{\footnotesize#2}[#1]}

\usepackage{etoolbox}
\makeatletter
\patchcmd{\@mn@margintest}{\@tempswafalse}{\@tempswatrue}{}{}
\patchcmd{\@mn@margintest}{\@tempswafalse}{\@tempswatrue}{}{}
\makeatother

Now the command \marginnote is the normal from tufte-book, and the command \marginnoteintable works in tables.

  • This worked intermittently. I had a lot of trouble getting the final typeset product to look right, even after compiling (typesetting) multiple times. Margin notes would get moved to the left margin, for example. I really wanted it to work, because the solution is inherently more robust than the other proposed solution, but because the other solution was so easy, I didn't devote the time to debug the problems with this solution. If my needs get more complex, I will return to this solution. So, thank you very much! – Iron Pillow Mar 12 '15 at 23:33
  • @IronPillow I edited the answer so that the notes should end up in the right margin on all pages :) – Jonas Granholm Mar 13 '15 at 15:47

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.