LaTeX forum ⇒ 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?

Postby krz » Wed Feb 09, 2011 1:07 pm

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.

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

Postby meho_r » Wed Feb 09, 2011 2:37 pm

Try this code:
  1. \documentclass{book}
  2.  
  3. \usepackage{marginnote}
  4.  
  5. \newcounter{mynote}% a new counter for use in margin notes
  6.  
  7. \newcommand{\mynote}[1]{% a simple margin note
  8. \refstepcounter{mynote}% step counter
  9. \mbox{\textsuperscript{\themynote}}% the number (superscript) in text
  10. \marginnote{\mbox{\textsuperscript{\themynote}}#1}% the note
  11. }
  12.  
  13.  
  14. \begin{document}
  15.  
  16. \chapter{A chapter}
  17.  
  18. Some text.\mynote{A margin note\label{one}}
  19.  
  20. Some text.
  21.  
  22. Some text.
  23.  
  24. Some text.\mynote{Another margin note}
  25.  
  26. \newpage
  27.  
  28. Some text.\mynote{A new margin note\label{two}}
  29.  
  30. Some text.
  31.  
  32. Some text.
  33.  
  34. Some text.\mynote{And one more margin note}
  35.  
  36. And here is a referencing test: the margin note labelled ``one'': note~\ref{one} on page~\pageref{one};
  37. the margin note labelled ``two'': note~\ref{two} on page~\pageref{two}.
  38.  
  39. \end{document}
  40.  

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

Postby krz » Wed Feb 09, 2011 6:10 pm

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?

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

Postby meho_r » Wed Feb 09, 2011 8:09 pm

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):
  1. \documentclass{book}
  2.  
  3. \usepackage{marginnote}
  4.  
  5. \newcounter{mynote}% a new counter for use in margin notes
  6.  
  7. \newcommand{\mynote}[2][0]{% a simple margin note
  8. \refstepcounter{mynote}% step counter
  9. \mbox{\textsuperscript{\themynote}}% the number (superscript) in text
  10. \marginnote{\mbox{\textsuperscript{\themynote}}#2}[#1\baselineskip]% the note
  11. }
  12.  
  13.  
  14. \begin{document}
  15.  
  16. \chapter{A chapter}
  17.  
  18. 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}}
  19.  
  20. Some text.\mynote[5]{Another margin note vertically adjusted}
  21.  
  22. \newpage
  23.  
  24. Some text.\mynote{A new margin note\label{two}}
  25.  
  26. Some text.
  27.  
  28. Some text.
  29.  
  30. Some text.\mynote{And one more margin note}
  31.  
  32. And here is a referencing test: the margin note labelled ``one'': note~\ref{one} on page~\pageref{one};
  33. the margin note labelled ``two'': note~\ref{two} on page~\pageref{two}.
  34.  
  35. \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:
  1. \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:
  1. \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

Postby krz » Thu Feb 10, 2011 9:53 am

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.

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

Postby meho_r » Thu Feb 10, 2011 1:43 pm

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

Postby krz » Thu Feb 10, 2011 2:46 pm

I don't know how to attache pdf to my post. Here is a tex file:
  1. \documentclass{book}
  2.  
  3. \usepackage{marginnote}
  4. \renewcommand*{\marginfont}{\footnotesize}
  5.  
  6. \newcounter{mynote}% a new counter for use in margin notes
  7.  
  8. \newcommand{\mynote}[2][0]{% a simple margin note
  9. \refstepcounter{mynote}% step counter
  10. \mbox{\textsuperscript{\themynote}}% the number (superscript) in text
  11. \marginnote{\mbox{\textsuperscript{\themynote}}#2}[#1\baselineskip]% the note
  12. }
  13. \usepackage[
  14. marginparwidth=70pt,
  15. papersize={176mm,235mm},
  16. text={120mm,180.9mm},
  17. ]{geometry}
  18. \sloppy
  19.  
  20. \begin{document}
  21.  
  22. \chapter{A chapter}
  23.  
  24. 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}}
  25.  
  26. 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.}
  27.  
  28. \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?

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

Postby meho_r » Thu Feb 10, 2011 4:48 pm

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.
  1. \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:
  1. \newcommand{\mynote}[2][0]{% a simple margin note
  2. \refstepcounter{mynote}% step counter
  3. \mbox{\textsuperscript{\themynote}}% the number (superscript) in text
  4. \marginnote{\mbox{\textsuperscript{\themynote}}\hspace{0pt}#2}[#1\baselineskip]% the note
  5. }

As for hyphenation of other lines, I suggest you ask at comp.text.tex or {TeX} SE if nobody here comes with a solution.

  1. \documentclass{book}
  2.  
  3. \usepackage{marginnote}
  4. \renewcommand*{\marginfont}{\footnotesize}
  5.  
  6. \newcounter{mynote}% a new counter for use in margin notes
  7.  
  8. \newcommand{\mynote}[2][0]{% a simple margin note
  9. \refstepcounter{mynote}% step counter
  10. \mbox{\textsuperscript{\themynote}}% the number (superscript) in text
  11. \marginnote{\mbox{\textsuperscript{\themynote}}\hspace{0pt}#2}[#1\baselineskip]% the note
  12. }
  13.  
  14. \newcommand{\mybr}{-\\}% a new command for manual line break
  15.  
  16. \usepackage[
  17. marginparwidth=70pt,
  18. papersize={176mm,235mm},
  19. text={120mm,180.9mm},
  20. ]{geometry}
  21. \sloppy
  22.  
  23. \begin{document}
  24.  
  25. \chapter{A chapter}
  26.  
  27. 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}}
  28.  
  29. 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.}
  30.  
  31. \end{document}

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

Postby krz » Thu Feb 10, 2011 5:52 pm

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:
  1. \usepackage{ragged2e}
  2. \renewcommand*{\raggedleftmarginnote}{\RaggedLeft}
  3. \renewcommand*{\raggedrightmarginnote}{\RaggedRight}
  4. \newcommand\Marginnote[1]{\marginnote{\hspace{0pt}#1}}

ragged2e works pretty well. Now I have automatic hyphenation.

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

Postby meho_r » Tue Feb 15, 2011 8:26 pm

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.


Return to “Text Formatting”

Who is online

Users browsing this forum: No registered users and 7 guests