2

I am using tikzmark and tikzpicture to annotate code examples. I noticed that there is inconsistent vspace between the next paragraph(or text line) and the code examples. I tried \vspace{-1em} or similar to reduce the spacing. But I am afraid that will have undesirable result accidentally. How should I achieve consistent (or near consistent) spacing without undesirable side effects? Please have a look at the attached picture to better see the problem.

%!TEX encoding = UTF-8 Unicode

\documentclass[10pt]{article}
\XeTeXlinebreaklocale "my_MM"  %Myanmar line and character breaks
\XeTeXinterwordspaceshaping=2 %%% PLEASE EXPERIMENT  BY SETTING WITH DIFFERENT VALUES


\usepackage{fontspec}
\setmainfont{Padauk Book}

\usepackage[outputdir=out]{minted}
\AtBeginEnvironment{minted}{\let\special\mintedspecial} 
\def\mintedspecial{\kern0pt\primitive\special}
\makeatletter
\AtBeginEnvironment{minted}{\dontdofcolorbox}
\def\dontdofcolorbox{\renewcommand\fcolorbox[4][]{##4}}
\makeatother

\usepackage{tikz}
\usetikzlibrary{tikzmark}
\usetikzlibrary{arrows.meta}

\begin{document}


%
\setlength{\fboxsep}{0pt}
\begin{minted}[frame=leftline, framerule=.5pt,framesep= 2pt, xleftmargin=0pt
    , escapeinside=ßß]{python}
def make_beeper_row():
    if front_is_clear():ß\tikzmark{z2}ß
        put_beeper()
        move()
        make_beeper_row()ß\tikzmark{z3}ß
    else:
        put_beeper()ß\tikzmark{z4}ß

make_beeper_row()ß\tikzmark{z1}ß
\end{minted}
%
\begin{tikzpicture}[
  remember picture,
  overlay,
  annotation/.style={
    inner sep=0pt,
    outer sep=0pt,
    outer xsep=0mm,
    fill=yellow!80!black,
    text width=5cm
  },
  >={Stealth[inset=0pt, angle=30:7pt]}
]
\draw[->, thick] ([yshift=0ex] pic cs:z1) -- ++(3,0) |- ([yshift=1.4ex]pic cs:z2);%
\draw[->, thin,blue] ([yshift=0ex] pic cs:z3) -- ++(1,0) |- ([yshift=0.5ex] pic cs:z2);%
\draw[->, thin,blue] ([yshift=1.2ex] pic cs:z3) -- ++(.7,0) |- ([yshift=-.4ex] pic cs:z2);%
\draw[->, thin,red] ([yshift=0.5ex] pic cs:z4) -- ++(.7,0) |- ([yshift=1.2ex] pic cs:z1);%
\end{tikzpicture}%


ရီကားဆစ်ဖ်ကောလ် ဖြစ်တာကို စိတ်ကူးပုံဖော်ကြည့်ဖို့ ပြထားတာပါ။ အပြင်ဆုံး မြှားအနက်က ကန\allowbreak ဦး ဖန်ရှင်ကောလ် စတင်တာဖြစ်‌ပေါ်တာကို ဖော်ပြတယ်။ ရီကားဆစ်ဖ်ကောလ် မဟုတ်သေးဘူး။ 

%
\setlength{\fboxsep}{0pt}
\begin{minted}[frame=leftline, framerule=.5pt,framesep= 2pt, xleftmargin=0pt
    , escapeinside=ßß]{python}
def make_beeper_row():
    if front_is_clear():
        put_beeper()
        move()
        make_beeper_row()
    else:
        put_beeper()

make_beeper_row()
\end{minted}

ရီကားဆစ်ဖ်ကောလ် ဖြစ်တာကို စိတ်ကူးပုံဖော်ကြည့်ဖို့ ပြထားတာပါ။ အပြင်ဆုံး မြှားအနက်က ကန\allowbreak ဦး ဖန်ရှင်ကောလ် စတင်တာဖြစ်‌ပေါ်တာကို ဖော်ပြတယ်။ ရီကားဆစ်ဖ်ကောလ် မဟုတ်သေးဘူး။ 

%
\setlength{\fboxsep}{0pt}
\begin{minted}[frame=leftline, framerule=.5pt,framesep= 2pt, xleftmargin=0pt
    , escapeinside=ßß]{python}
def make_beeper_row():
    if front_is_clear():ß\tikzmark{y2}ß
        put_beeper()
        move()
        make_beeper_row()ß\tikzmark{y3}ß
    else:
        put_beeper()ß\tikzmark{y4}ß

make_beeper_row()ß\tikzmark{y1}ß
\end{minted}
%
\begin{tikzpicture}[
  remember picture,
  overlay,
  annotation/.style={
    inner sep=0pt,
    outer sep=0pt,
    outer xsep=0mm,
    fill=yellow!80!black,
    text width=5cm
  },
  >={Stealth[inset=0pt, angle=30:7pt]}
]
\draw[->, thick] ([yshift=0ex] pic cs:y1) -- ++(3,0) |- ([yshift=1.4ex]pic cs:y2);%
\draw[->, thin,blue] ([yshift=0ex] pic cs:y3) -- ++(1,0) |- ([yshift=0.5ex] pic cs:y2);%
\draw[->, thin,blue] ([yshift=1.2ex] pic cs:y3) -- ++(.7,0) |- ([yshift=-.4ex] pic cs:y2);%
\draw[->, thin,red] ([yshift=0.5ex] pic cs:y4) -- ++(.7,0) |- ([yshift=1.2ex] pic cs:y1);%
\end{tikzpicture}%
ရီကားဆစ်ဖ်ကောလ် ဖြစ်တာကို စိတ်ကူးပုံဖော်ကြည့်ဖို့ ပြထားတာပါ။ အပြင်ဆုံး မြှားအနက်က ကန\allowbreak ဦး ဖန်ရှင်ကောလ် စတင်တာဖြစ်‌ပေါ်တာကို ဖော်ပြတယ်။ ရီကားဆစ်ဖ်ကောလ် မဟုတ်သေးဘူး။ 


\end{document}

enter image description here

1 Answer 1

1

The issue is that a tikzpicture environment, even if with remember picture and overlay, still creates a horizontal box and that potentially introduces spacing even though it itself has no size. It can prevent successive sets of vertical spacing from being squashed together, which is what (I think) is happening here: the vertical space at the end of the minted environment and at the start of the paragraph aren't getting put together.

The simplest solution is to ensure that this box is created at a place where it's okay to have a zero-size horizontal box. In your last example, you are effectively placing it at the beginning of the following paragraph. This is fine, since there is then no space between the box and the first letter of that paragraph and so it doesn't act as a separator. To make the source code a little easier to read you could add a line with just a % on it.

I'm not familiar with minted but I suspect that another option would be to hook in to the end of the minted environment to put the tikzpicture code before minted finishes. This would have the effect of putting the zero-sized box before the vertical space between the minted section and the following paragraph.

There are other solutions; the main thing is to have the tikzpicture code on the same page as the minted environment. It is convenient in the source code to have it immediately afterwards, but so long as it stays on the same page then it can be anywhere.

2
  • thanks for your advice and explanation for the root cause. I'll see if I can mange to find a good solution to the problem based on your explanation.
    – Pyi Soe
    Commented Jul 14 at 8:30
  • I tried as I understand the explanation above by Andrew Stacey. Putting the tikzpicture before minted seems to work fine, at least for the example in the question.
    – Pyi Soe
    Commented Jul 22 at 17:12

You must log in to answer this question.

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