I am using the answer to this question: Drawing tikz line in the margin for multiple pages to draw a colored line on the margin of my document.

I would like to have a possibility to comment out the environment definition and acquire the same document without the colored line. But when I replace the outline environment definition with an empty one, the document has a different alignment.





% Comment this out to disable the marking of text:




The example above has additional empty space when the \renewenvironment is uncommented.

The only solution I have come up with so far is to take care that the environments' begin/end tags are in one block with paragraphs. (Therefore it seems to me that the \tikzmark command makes LaTeX create an additional, empty paragraph.)

Is there any other solution which would ensure that the \tikzmark commands don't change the outline of the document?


tikzmark can introduce whitespace because tikz pictures are typeset in a horizontal box, so even if that box has no size it can change the vertical spacing as TeX switches from vertical to horizontal mode and (in your case) back to vertical mode.

To avoid this, there is a command \pgfmark which does the same as \tikzmark but without the box. As far as I can tell, it gets rid of the additional space in your document.

| improve this answer | |
  • Thanks for the suggestion, it already improves a lot (there are much fewer differences in the spacing). I have tested it a little and found one more case, when the \pgfmark{...} is between an \end{itemize} and \section{} -- there is still extra free space. Any suggestions? – Adam Sep 3 '18 at 22:31
  • A bit of experimenting narrows down the issue to the one in this question: tex.stackexchange.com/q/350339/86 and the answer to that seems to be "can't fix". – Andrew Stacey Sep 4 '18 at 17:52
  • Well, at least I know there no reason to investigate further. Your initial answer has improved a lot anyway, so I am accepting it - thanks again! – Adam Sep 5 '18 at 14:15

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.