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.

  • Maybe you can change the placement with \reversemarginpar as suggested here: tex.stackexchange.com/questions/5180/…
    – Habi
    Oct 30, 2013 at 15:26
  • @math: Did the comment of Habi help?
    – masu
    Nov 15, 2013 at 15:46
  • 4
    Nope, this just swaps the left and right margin. So far I couldn't solve this.
    – math
    Nov 19, 2013 at 7:47
  • I am still interested in an answer, too.
    – buhtz
    Feb 28, 2016 at 10:09
  • 1
    The automatic part is what's hard.
    – JPi
    Aug 22, 2016 at 3:01

1 Answer 1


There is a way of achieving this by using the zref package and marginnotes. This answer is based on this answer about placing nodes on both sides and hints taken from this answer about zrefusage.

The idea is to use zref to get the horizontal position of the "anchor" of a todo note and let ifdim check, if that is on the left or right side of the page. Since all the x-coordinates are written to the aux 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 kind todo<number>. The aux file contains all those todo<number> labels associated with their posx 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 the zref 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 pdflatexor what ever you use might fix it.

The complete MWE is:




  \ifdim \zposx{#2}sp < 20000000sp%





Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Ut purus elit,\mytodo{the first note} vestibulum ut,
placerat ac, adipiscing vitae, felis. Curabitur dictum gravida mauris. Nam arcu libero,
nonummy eget, consectetuer id, vulputate a, magna. Donec vehicula augue eu neque.
Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis
egestas. Mauris ut leo.\mytodo{this is another note} Cras viverra metus rhoncus sem. Nulla et lectus vestibulum
urna fringilla ultrices. Phasellus eu tellus sit amet tortor gravida placerat. Integer
sapien est, iaculis in, pretium quis, viverra ac, nunc. Praesent eget sem vel leo ultrices
bibendum. Aenean faucibus. Morbi dolor nulla, malesuada eu, pulvinar at, mollis ac,
nulla. Curabitur auctor semper nulla. Donec varius orci eget risus. Duis nibh mi, congue
eu, accumsan eleifend, sagittis quis, diam. Duis eget orci sit amet orci dignissim rutrum.
Nam dui ligula, fringilla a, euismod sodales, sollicitudin vel, wisi. Morbi auctor lorem
non justo. Nam lacus libero, pretium at, lobortis vitae, ultricies et, tellus. Donec
aliquet, tortor sed accumsan bibendum, erat ligula aliquet magna, vitae ornare odio
metus a mi. Morbi ac orci et nisl hendrerit mollis. Suspendisse ut massa. Cras nec ante.
Pellentesque a nulla. Cum sociis natoque penatibus et magnis dis parturient montes,
nascetur ridiculus mus.\mytodo{now there would be this} Aliquam tincidunt urna. Nulla ullamcorper vestibulum turpis.
Pellentesque cursus luctus mauris.
Nulla malesuada porttitor diam.\mytodo{now this} Donec felis erat, congue non, volutpat at, tincidunt
tristique, libero.\mytodo{and dont forget that} Vivamus viverra fermentum felis. Donec nonummy pellentesque ante.
Phasellus adipiscing semper elit. Proin fermentum massa ac quam. Sed diam turpis,
molestie vitae, placerat a, molestie nec, leo. Maecenas lacinia. Nam ipsum ligula, eleifend
at, accumsan nec, suscipit a, ipsum. Morbi blandit ligula feugiat magna. Nunc eleifend
consequat lorem. Sed lacinia nulla vitae enim. Pellentesque tincidunt purus vel magna.
Integer non enim. Praesent euismod nunc eu purus. Donec bibendum quam in tellus.
Nullam cursus pulvinar lectus. Donec et mi. Nam vulputate metus eu enim. Vestibulum
pellentesque felis eu massa.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .