add tag
3 years ago निरंजन

I am trying to draw a line from one (\tikz)mark to another one from my document. As can be seen in the following code; it works correctly when both the marks are present on a single page, but doesn’t work when the page is crossed.

PS: Kindly don’t suggest tcolorbox or mdframed solutions. I have tried both of them and there are various reasons for not choosing them for this purpose. Don’t worry about that line overlapping the text. That lipsum text is just a place-holder.

Top Answer
3 years ago samcarter

Tikzpictures don’t break across pages. You’ll have to split it into one tikzpicture per page:

(I moved \tikzmark to the label of the first item, otherwise you risk to define the same mark multiple times)

Screenshot 2022-07-23 at 12.45.16.png

3 years
samcarter — Thursday, 11th Aug 2022 09:34

Try both of these code blocks and observe the difference:

samcarter — Thursday, 11th Aug 2022 09:32

The code to draw the line from beg to the end of the page is

In your code, you use this after the end of the second item. At this point you are already on page 2. You need to use this code on page 1

2 hours
निरंजन — Thursday, 11th Aug 2022 07:14

(Currently this isn’t happening.)

निरंजन replying to samcarter — Thursday, 11th Aug 2022 07:14

The line produced with the code above would need to shift a bit to the left of the text and vertically also it should match the starting and ending of the text.

निरंजन — Thursday, 11th Aug 2022 07:11

@samcarter, why doesn’t this work?

What I am trying to achieve is if the end mark is on the same page where the beg mark occurs, I want to draw a line connecting both of them. This works as expected. Now the else branch of this should draw a line from the beg mark to the bottom of the page like in your answer. I don’t know what is wrong in my code, but I am unable to get this.

a day
निरंजन replying to frougon — Wednesday, 10th Aug 2022 07:14

Ah, sorry. My bad. Thanks for pointing out.

निरंजन replying to samcarter — Wednesday, 10th Aug 2022 07:14

Right, at the moment I am struggling with getting the line in my code itself. Because of your answer I got to know about this wonderful way of using let in tikzpicture. I loved this mechanism.

I will definitely need to automatically shift it according to contexts, but will work on it a bit later.

निरंजन — Wednesday, 10th Aug 2022 07:10

@samcarter, Thanks a lot for your answer, it’s great as always. Sorry for replying so late, I was on a break from LaTeX. I am experimenting with your code a bit and at the moment struggling with one particular case. Would form an MWE and ask it here soon.

18 days
samcarter replying to frougon — Saturday, 23rd Jul 2022 13:00

No, I don’t think the syntax can work outside of graphs. (I just copied it from the mwe)

frougon — Saturday, 23rd Jul 2022 12:51

@samcarter Very nice! Does the -> do anything here? I don’t see any arrow, but I do with e.g.

an hour
samcarter — Saturday, 23rd Jul 2022 11:43
samcarter — Saturday, 23rd Jul 2022 11:43

Oh, here, something better:

samcarter replying to निरंजन — Saturday, 23rd Jul 2022 11:39

some proof of concept. (I shifted the line manually to the right, if you need this to be automatic, you’d probably have to store the x component of pic cs:one in some global variable)

samcarter — Saturday, 23rd Jul 2022 11:37
26 minutes
निरंजन replying to samcarter — Saturday, 23rd Jul 2022 11:11

Yesterday I saw some code by @marmot on SE which did that, but I am not able to find it again, anyways, I would be happy to go with the solution you suggested too. It definitely makes sense.

निरंजन replying to samcarter — Saturday, 23rd Jul 2022 11:06

I can do that for the first and last page, but I am not sure how to do that for the intermediate pages. Can you help me there?

samcarter — Saturday, 23rd Jul 2022 11:03

You could split you line into multiple tikz pictures. On the first page, draw from the tikzmark until the bottom. On all intermediate pages, draw full lines and then draw until the other tikz mark on the last page

20 minutes
samcarter — Saturday, 23rd Jul 2022 10:44

The problem isn’t tikzmarks. You can’t break the tikzpicture, which draws your line, across pages.

Enter question or answer id or url (and optionally further answer ids/urls from the same question) from

Separate each id/url with a space. No need to list your own answers; they will be imported automatically.