I'm writing a double-paged document where I'm using pdfpages to insert a pdf on every other page, so that if you read it like a book, the page on the right shows the pdf, while the one on the left is reserved for comments. For these comments, I would like to draw some lines, or arrows, or boxes, or something like that, that connect the comments to stuff in the pdf. I thought I would probably have to use TikZ for that, but I have no idea how, as I have never used that before. Is something like that even possible?

I found this post, which is similar, but too complex for me to understand what's going on.

  • Hello! It will help to produce a useful answer if you post some code that produces a document as described, with some pdf pages inserted and comments on the opposite page. Aug 5 at 17:23
  • 1
    Somewhat related: tex.stackexchange.com/questions/363957/… Aug 5 at 18:56
  • @SimonDispa that's fair. But I wasn't fast enough for Jasper Habicht's answer.
    – mapf
    Aug 6 at 9:11

1 Answer 1


As I understood your question, you have two pages next to each other, one on the right where you include a page from some PDF file, and one on the left where you want to state annotations. Then, you want to draw lines going from the left to the right, crossing the page boundaries.

With the following approach that works a bit like tikzmarks, you can use the macro \annotline to define the coordinate on the next page (the upper left corner of the page is the origin, unit is centimeters) where you want to draw a line to. The macro will then draw a line starting where you placed the macro that goes towards the right margin of the page where it turns up or down until it reaches the height of the coordinate on the next page where it turns to the right again. You can use the macro \annotlinebreakdist to define the distance from the right margin of the page to the vertical part of the line.

On the next page, you can use the macro \printannotlines to draw the remaining part of the lines that start form the left margin of the page and go to the relevant coordinate. The macro automatically draws all the lines that haven't been finished until then.

You can style the line using TikZ styles. In case the lines overlap, you can use the second optional argument to shift the vertical part of the line to the right or left. Using the first optional parameter, you can shift the starting point of the line to the left or right.


        very thick, red
    annotline start/.style={
    annotline end/.style={


\dim_new:N \l_annotline_breakdist_dim
\dim_set:Nn \l_annotline_breakdist_dim { 1cm }

\NewDocumentCommand{\annotlinebreakdist}{ m }{
    \dim_set:Nn \l_annotline_breakdist_dim { #1 }

\clist_new:N \l_annotline_allxpos_clist
\clist_new:N \l_annotline_allypos_clist
\int_new:N \l_annotline_currid_int
\int_new:N \l_annotline_lastid_int

\NewDocumentCommand{\annotline}{ O{0pt} O{0pt} m m }{%
    \clist_put_right:Nn \l_annotline_allxpos_clist { #3 }
    \clist_put_right:Nn \l_annotline_allypos_clist { #4 }
    \int_incr:N \l_annotline_currid_int
    \begin{tikzpicture}[remember~picture, overlay] 
        \coordinate (annotline-\int_use:N\l_annotline_currid_int -start) at 
        \coordinate (annotline-\int_use:N\l_annotline_currid_int -start-break) at 
        \coordinate (annotline-\int_use:N\l_annotline_currid_int -start-margin) at 
        \draw[annotline, annotline~start] 
            (annotline-\int_use:N\l_annotline_currid_int -start) --
            (annotline-\int_use:N\l_annotline_currid_int -start -| annotline-\int_use:N\l_annotline_currid_int -start-break) |-
            (annotline-\int_use:N\l_annotline_currid_int -start-margin);

\dim_new:N \l_annotline_currxpos_dim
\dim_new:N \l_annotline_currypos_dim

\NewDocumentCommand{\annotlineend}{ m }{%
    \dim_set:Nn \l_annotline_currxpos_dim { \clist_item:Nn \l_annotline_allxpos_clist #1 cm }
    \dim_set:Nn \l_annotline_currypos_dim { \clist_item:Nn \l_annotline_allypos_clist #1 cm }
    \begin{tikzpicture}[remember~picture, overlay]
        \coordinate (annotline-#1-end-margin) at 
        \coordinate (annotline-#1-end) at 
        \draw[annotline, annotline~end] 
            (annotline-#1-end-margin) --

    \int_incr:N \l_annotline_lastid_int
    \foreach \i in {\int_use:N\l_annotline_lastid_int,...,\int_use:N\l_annotline_currid_int} {
    \int_set:Nn \l_annotline_lastid_int \l_annotline_currid_int




Some very interesting thing \annotline[0pt][10pt]{8}{5}

Some other interesting thing \annotline[0pt][-10pt]{12}{10}


Yet another interesting thing \annotline{16}{7.5}





Again some very interesting thing \annotline{10}{10}





enter image description here

  • Wow, what a great answer! It works like charm. Thanks a lot!
    – mapf
    Aug 6 at 9:09
  • 1
    @mapf I wasn't sure whether this would suit your needs. I just corrected a minor flaw in the code (It had four lines which were remains from prior testing but which are not necessary actually) so I updated the answer. Aug 6 at 9:19
  • It's exactly what I was thinking of. I'd like to use it for a cumulative thesis where I comment on the incorporated pdfs of papers (afaik you cannot include the actual tex code of the papers instead and make that work, which is a shame but understandable). It's based on the kaobook and classic thesis styles and I think your solution will fit right in.
    – mapf
    Aug 6 at 15:28

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.