I want to place todonotes not only on the left or the right margin. I want to use both at the same time, and that the notes should decide by themself where to place. E.g. when the note points to a place near the left margin it should go to the left margin. Or when the left margin is full, it should use right margin then.
There are already similar questions, but I couldn't find some focusing also on the todonotes package.
Best Answer
There is a way of achieving this by using the
zref
package andmarginnotes
. This answer is based on this answer about placing nodes on both sides and hints taken from this answer aboutzref
usage.The idea is to use
zref
to get the horizontal position of the "anchor" of a todo note and letifdim
check, if that is on the left or right side of the page. Since all the x-coordinates are written to theaux
file at least two compilations are necessary. Additionally unique labels are needed for all those coordinates so in the MWE below the count\todocount
is provided giving each note a label of the kindtodo<number>
. The aux file contains all thosetodo<number>
labels associated with theirposx
coordinate (in sp).The command
\mytodo
takes an optional argument and the mandatory argument which are passed to\todo
, it additionally calls\zsafeposx
,\checkxpos
and advances the counter.The number (
20000000
) in the definition of\checkxpos
is the estimated center of the page, really, its just roughly the middle and there are some warnings about taking thezref
positions as absolute values on a page.I am not sure how stable those macros are in conection with
twopage
documents and other stuff.If the connecting lines and everything looks like a mess another run with
pdflatex
or what ever you use might fix it.The complete MWE is: