Text FormattingMargin notes like footnotes?

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
krz
Posts: 63
Joined: Thu Jul 22, 2010 5:03 pm

Margin notes like footnotes?

Post by krz »

Hi!
Is it possible to use margin notes like footnotes? I know I can use something like that: "some text*\marginpar{*some text}", but I need to use arabic numerals and make it more automatic, just like in \footnote.
I looked at marginnote package documentation, but couldn't find the answer.
Thanks of your help.
Last edited by krz on Thu Feb 10, 2011 5:52 pm, edited 3 times in total.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

meho_r
Posts: 823
Joined: Tue Aug 07, 2007 5:28 pm

Margin notes like footnotes?

Post by meho_r »

Try this code:

Code: Select all

\documentclass{book}

\usepackage{marginnote}

\newcounter{mynote}% a new counter for use in margin notes

\newcommand{\mynote}[1]{% a simple margin note
	\refstepcounter{mynote}% step counter
	\mbox{\textsuperscript{\themynote}}% the number (superscript) in text
	\marginnote{\mbox{\textsuperscript{\themynote}}#1}% the note
}


\begin{document}

\chapter{A chapter}

Some text.\mynote{A margin note\label{one}}

Some text.

Some text.

Some text.\mynote{Another margin note}

\newpage

Some text.\mynote{A new margin note\label{two}}

Some text.

Some text.

Some text.\mynote{And one more margin note}

And here is a referencing test: the margin note labelled ``one'': note~\ref{one} on page~\pageref{one}; 
the margin note labelled ``two'': note~\ref{two} on page~\pageref{two}.

\end{document}

krz
Posts: 63
Joined: Thu Jul 22, 2010 5:03 pm

Re: Margin notes like footnotes?

Post by krz »

meho_r, you are real magician! Thanks!! :)

PS. Do you know how to move one note down if I have two notes in the same line?
PS2. I thought I resolved this problem by using this \mynote{\\[18pt] A margin note\label{one}}, but the problem is with number (label). It stays at the line where I used \mynote whilst margin note move down. Do you know what to do?
meho_r
Posts: 823
Joined: Tue Aug 07, 2007 5:28 pm

Margin notes like footnotes?

Post by meho_r »

OK, here's another try, now with two arguments: one for margin note text and another for vertical offset (which you'll have to specify manually unless some of LaTeX gurus provide a code which will count the spacing between two margin notes and automatically add additional space if necessary; however, I have no idea how to do that):

Code: Select all

\documentclass{book}

\usepackage{marginnote}

\newcounter{mynote}% a new counter for use in margin notes

\newcommand{\mynote}[2][0]{% a simple margin note
   \refstepcounter{mynote}% step counter
   \mbox{\textsuperscript{\themynote}}% the number (superscript) in text
   \marginnote{\mbox{\textsuperscript{\themynote}}#2}[#1\baselineskip]% the note
}


\begin{document}

\chapter{A chapter}

Some text.\mynote{A little bit longer margin note which goes over more than two lines to see how does vertical adjustment in the next margin note work.\label{one}}

Some text.\mynote[5]{Another margin note vertically adjusted}

\newpage

Some text.\mynote{A new margin note\label{two}}

Some text.

Some text.

Some text.\mynote{And one more margin note}

And here is a referencing test: the margin note labelled ``one'': note~\ref{one} on page~\pageref{one}; 
the margin note labelled ``two'': note~\ref{two} on page~\pageref{two}.

\end{document}
Note that now you can use an optional argument to move a margin note down, e.g., to move a margin note down for 4 lines, use this:

Code: Select all

\mynote[4]{margin note text}
If you don't need manual adjustments, just omit the optional argument and it'll be automatically set to 0:

Code: Select all

\mynote{margin note text}
I used \baselineskip as it seemed a good "measure" for this purpose. Of course, if you want to use absolute units instead, you can change the code: [#1\baselineskip] to something like this: [#1cm]
krz
Posts: 63
Joined: Thu Jul 22, 2010 5:03 pm

Re: Margin notes like footnotes?

Post by krz »

meho_r, thanks a lot!! It works great!!
But..., sorry to bother you, I have another question. How to make hyphenation? Unfortunatelly I can't devide words in margin note. \- doesn't work. I was thinking maybe justification would help, but not. In addition, when I justify notes, words at the end of the line step in main text.
Maybe solution is tirvial, because I couldn't google it.

PS. So, I can use \- already. I really don't know what happened (I think I needed to push the button "Typeset" in my TeXShop a few times). But it works only when I center justify (and it doesn't work automatically, but I have to do it manually). When I want to devide word in right justify note it doesn't work.
meho_r
Posts: 823
Joined: Tue Aug 07, 2007 5:28 pm

Margin notes like footnotes?

Post by meho_r »

Please, can you post an example which clearly shows the issue? Also, do you want marginal notes to be floats or non-floats, with text justified or ragged?

As a side note, you might find this informative.
krz
Posts: 63
Joined: Thu Jul 22, 2010 5:03 pm

Margin notes like footnotes?

Post by krz »

I don't know how to attache pdf to my post. Here is a tex file:

Code: Select all

\documentclass{book}

\usepackage{marginnote}
\renewcommand*{\marginfont}{\footnotesize}

\newcounter{mynote}% a new counter for use in margin notes

\newcommand{\mynote}[2][0]{% a simple margin note
   \refstepcounter{mynote}% step counter
   \mbox{\textsuperscript{\themynote}}% the number (superscript) in text
   \marginnote{\mbox{\textsuperscript{\themynote}}#2}[#1\baselineskip]% the note
}
\usepackage[
  marginparwidth=70pt,
  papersize={176mm,235mm},
  text={120mm,180.9mm},
]{geometry}
\sloppy

\begin{document}

\chapter{A chapter}

Some text.\mynote{A little bit longer margin note which goes over more than two lines to see how does vertical adjustment in the next margin note work.\label{one}}

Some text.\mynote[7]{And Here.is.a.long.word that I'd like to divide. I'd like the part of it to be on the first line.}

\end{document}
Look at the second note. In the first you can see the problem too. For example, how to divide the word "adjustment"?

I think what you did in your example is what I need. Ragged notes would be better and sometimes I'd like to hyphenate some long words to save some vertical space on marings. I hope it's clear.
And what's the difference between floats and non-floats?
meho_r
Posts: 823
Joined: Tue Aug 07, 2007 5:28 pm

Margin notes like footnotes?

Post by meho_r »

I see. I'm afraid you'll have to do that manually for now (i.e., using commands for line breaks). However, I suggest you create a new command for that instead using \\ or \linebreak directly, e.g.

Code: Select all

\newcommand{\mybr}{-\\}
Also, not to forget mentioning it again, put a \hspace{0pt} in front of the second argument in \mynote definition so the first word gets hyphenated automatically:

Code: Select all

\newcommand{\mynote}[2][0]{% a simple margin note
   \refstepcounter{mynote}% step counter
   \mbox{\textsuperscript{\themynote}}% the number (superscript) in text
   \marginnote{\mbox{\textsuperscript{\themynote}}\hspace{0pt}#2}[#1\baselineskip]% the note
}
As for hyphenation of other lines, I suggest you ask at comp.text.tex or {TeX} SE if nobody here comes with a solution.

Code: Select all

\documentclass{book}

\usepackage{marginnote}
\renewcommand*{\marginfont}{\footnotesize}

\newcounter{mynote}% a new counter for use in margin notes

\newcommand{\mynote}[2][0]{% a simple margin note
   \refstepcounter{mynote}% step counter
   \mbox{\textsuperscript{\themynote}}% the number (superscript) in text
   \marginnote{\mbox{\textsuperscript{\themynote}}\hspace{0pt}#2}[#1\baselineskip]% the note
}

\newcommand{\mybr}{-\\}% a new command for manual line break

\usepackage[
  marginparwidth=70pt,
  papersize={176mm,235mm},
  text={120mm,180.9mm},
]{geometry}
\sloppy

\begin{document}

\chapter{A chapter}

Some text.\mynote{A little bit longer margin note which goes over more than two lines to see how does vertical adjust\mybr{}ment in the next margin note work.\label{one}}

Some text.\mynote[7]{And Here.is.a.\mybr{}long.word that I'd like to divide. I'd like the part of it to be on the first line.}

\end{document}
krz
Posts: 63
Joined: Thu Jul 22, 2010 5:03 pm

Margin notes like footnotes?

Post by krz »

meho_r, thanks a lot again!
I'll ask on sites you told me about. If I find solution I'll put it at the end of this topic, but telling the truth \mybr{} is good for me now. I need it for a few not so long documents and I can divide words manually.

PS. I asked on {TeX} SE and got this:

Code: Select all

\usepackage{ragged2e}
\renewcommand*{\raggedleftmarginnote}{\RaggedLeft}
\renewcommand*{\raggedrightmarginnote}{\RaggedRight}
\newcommand\Marginnote[1]{\marginnote{\hspace{0pt}#1}}
ragged2e works pretty well. Now I have automatic hyphenation.
meho_r
Posts: 823
Joined: Tue Aug 07, 2007 5:28 pm

Margin notes like footnotes?

Post by meho_r »

Nice, thanks for sharing. I'll take liberty to post the link to your question at {TeX} SE, it might be beneficial for others looking for the solution of the same or similar problem.
Post Reply