2

As seen on page 200 of pgf manual is there a way to put notes in the margin but on the same level as the place it is called ?

One can deal with the right-left positionning with the help of this question margin notes multicolumn, but how to deal with up-down level ?

Edit

With your help, here is my try. Still vertical alignement problem.

\documentclass[french]{article}
\usepackage[marginparsep=3pt, top=2cm, bottom=1.5cm, left=1.5cm, right=1.5cm]{geometry}
\setlength{\parindent}{0pt}
\setlength{\headsep}{1em}
\usepackage{tikz,lipsum}
\usepackage{multicol,zref-savepos}

\def\Note#1{%
\zsavepos{#1}%
%%%%%%--------
\ifnum20000000<\number\zposx{#1}%
    \begin{tikzpicture}[remember picture,overlay]
    \coordinate (here) at (0,0);
    \draw (current page.east |- here)
            node[left]{\makebox[1.2cm][l]{#1}};
    \end{tikzpicture}%to prevent adding extra space before text
\else
    \begin{tikzpicture}[remember picture,overlay]
    \coordinate (here) at (0,0);
    \draw (current page.west |- here)
            node[right]{\makebox[1.2cm][r]{#1}};
    \end{tikzpicture}%to prevent adding extra space before text
\fi%
\ignorespaces
}

\begin{document}
\begin{multicols}{2}

\lipsum[1]

Un essai de note dans la colonne de gauche.\hfill\Note{1pt}

\lipsum[2-3]

\Note{1.5pt} Un essai de note dans la colonne de droite.
\lipsum[4-5]
\end{multicols}

\end{document}

enter image description here

3
  • The node is vertically centered relative to (here), wherever (here) is. A quick fix us to use (0,.2\baselineskip) instead of (0,0) for (here). Mar 6, 2014 at 5:18
  • 1
    You can also use \draw (current page.east |- here)+(-1.5cm,0.2\baselineskip) node[right]{#1}; and \draw (current page.west |- here)+(1.5cm,0.2\baselineskip) node[left]{#1}; instead of \makebox. Mar 6, 2014 at 5:48
  • Yes, good idea.
    – Tarass
    Mar 6, 2014 at 9:14

3 Answers 3

2

I'm surprised this works. The actual location of the origin isn't usually fixed until the picture is completed and the current bounding box is fit into the text area.

\documentclass{article}
\usepackage{tikz}
\usepackage{lipsum}

\begin{document}

\lipsum[1]

\begin{tikzpicture}[remember picture,overlay]
\coordinate (here) at (0,0);
\draw (current page.west |- here) node[right]{Margin note};
\end{tikzpicture}%to prevent adding extra space before text
\lipsum[2-4]

\end{document}

full page

3
  • Have you looked at the tikzpagenodes package?
    – azetina
    Mar 5, 2014 at 16:31
  • I have now. It would certainly make it easier to right justify a margin note to the text area, if that was what was desired. But you don't really need it. Mar 5, 2014 at 16:55
  • 1
    Thank you. I made a try with multicols and two columns. Still a vertical alignement problem. Do you know how to fix it ?
    – Tarass
    Mar 6, 2014 at 3:26
3

You can also use Tikz to perform the left column/right column test. Also, putting a \strut inside the nodes will give more consistent results wrt vertical centering, and it looks better with the calculated offset: 0.15\baselineskip.

\documentclass[french]{article}
\usepackage[marginparsep=3pt, top=2cm, bottom=1.5cm, left=1.5cm, right=1.5cm]{geometry}
\setlength{\parindent}{0pt}
\setlength{\headsep}{1em}
\usepackage{tikz,lipsum}
\usepackage{multicol}

\newlength{\test}

\def\Note#1{%
\begin{tikzpicture}[remember picture,overlay]
\coordinate (here) at (0,0.15\baselineskip);
%compute horizontal offset from origin to center
\pgfextractx{\test}{\pgfpointdiff{\pgfpointorigin}
  {\pgfpointanchor{current page}{center}}}%
\ifdim\test < 0pt%
  \draw (current page.east |- here)+(-1.5cm,0pt) node[right]{\strut #1};
\else
  \draw (current page.west |- here)+(1.5cm,0pt) node[left]{\strut #1};
\fi%
\end{tikzpicture}%
\ignorespaces%
}%

\begin{document}
\begin{multicols}{2}

\lipsum[1]

Un essai de note dans la colonne de gauche.\hfill\Note{pyg}

\lipsum[2-3]

\Note{CAP} Un essai de note dans la colonne de droite.
\lipsum[4-5]
\end{multicols}

\end{document}
3
  • 1
    This works, however it does not consider different margins on odd/even pages. Jun 15, 2016 at 10:59
  • To adjust for odd and even pages: I had to add \ifthispageodd{}{} commands (from Koma Script) in both \ifdim and \else clauses, to adjust the horizontal placement. Also, I had to change \ifdim\text < 0pt to \ifdim\text < 1pt because placement was completely off on even pages. Jun 15, 2016 at 11:32
  • 2
    @MichaelFranzl - You can also use tikzpagenodes and (current page text area.center). Jun 15, 2016 at 15:09
2

I like John's idea about the columns. I distrust niggly adjustmants (0.15\baselineskip) and would rather have tikz do the work of positioning things correctly. The best thing to do is to use anchor=text in the nodes. Also changed the text alignment depending on whether it is on the left or right side. Fiddle with the dimensions to suit.

\documentclass[french]{article}
\usepackage[top=2cm, bottom=1.5cm, left=1.5cm, right=1.5cm]{geometry}
\setlength{\parindent}{0pt}
\setlength{\headsep}{1em}
\usepackage{tikz,lipsum}
\usepackage{multicol}

\newlength{\test}

\def\Note#1{%
\begin{tikzpicture}[remember picture,overlay]
\coordinate (here) at (0,0);
%compute horizontal offset from origin to center
\pgfextractx{\test}{\pgfpointdiff{\pgfpointorigin}
  {\pgfpointanchor{current page}{center}}}%
\ifdim\test < 0pt%
  \draw (current page.east |- here)+(-0.5in,0pt) node[anchor=text,align=left,text width=0.5in]{\strut #1};
\else
  \draw (current page.west |- here)+(0cm,0pt) node[anchor=text,align=right,text width=0.5in]{\strut #1};
\fi%
\end{tikzpicture}%
\ignorespaces%
}%

\begin{document}
\begin{multicols}{2}

\lipsum[1]

Un essai de note dans la colonne de gauche.\Note{pyg}

\lipsum[2-3]

\Note{CAP}% and more} 
Un essai de note dans la colonne de droite.
\lipsum[4-5]
\end{multicols}

\end{document}
1
  • The baseline is located precisely .35\baselineskip from the bottom. But anchor=base is more esthetically pleasing. Apr 1, 2014 at 4:04

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.