![Как предотвратить наложение меток на картинке tikz?](https://rvso.com/image/461907/%D0%9A%D0%B0%D0%BA%20%D0%BF%D1%80%D0%B5%D0%B4%D0%BE%D1%82%D0%B2%D1%80%D0%B0%D1%82%D0%B8%D1%82%D1%8C%20%D0%BD%D0%B0%D0%BB%D0%BE%D0%B6%D0%B5%D0%BD%D0%B8%D0%B5%20%D0%BC%D0%B5%D1%82%D0%BE%D0%BA%20%D0%BD%D0%B0%20%D0%BA%D0%B0%D1%80%D1%82%D0%B8%D0%BD%D0%BA%D0%B5%20tikz%3F.png)
Код Latex ниже сгенерирован моей программой C#. Есть три стрелки с меткой каждая. Вторая метка перекрывает первую. Чтобы решить эту проблему, метку можно расположить под стрелкой (как третья стрелка/метка), или стрелку/метку можно вообще опустить.
Как обнаружить перекрытие?
Или как расположить метку относительно оси X, а не относительно ее стрелки, как сейчас (переключатель выше/ниже/пропустить)?
Или как положение метки и расстояние до стрелки (выше = 4?) связаны с осью x?
\documentclass[11pt,a4paper,dutch]{article}
\usepackage[per-mode=symbol,mode=text,per-mode=symbol,exponent-product=\cdot]{siunitx}
\usepackage{xcolor}
\usepackage{rotating}
\usepackage{pgfplots}
\usepackage{tikz}
\tikzset{every picture/.style={line width=0.75pt}}
\usetikzlibrary{arrows.meta,calc,math,quotes,angles}
\tikzset{>=latex}
\tikzstyle{vector}=[->,very thick,xcol]
\pgfplotsset{compat=1.18}
\begin{document}
\begin{figure}
\begin{tikzpicture}[scale=0.9, transform shape]
\fontsize{10pt}{12pt}
\begin{axis}[
width=6cm,
height=6cm,
xmin={-0.7},xmax={5*1.1},
ymin={-0.1*1.1},ymax={2.335*1.1},
y label style={at={(axis description cs:-0.04,.5)},rotate=90,anchor=south},
grid=both,
grid style={line width=.1pt, draw=gray!20},
major grid style={line width=.2pt,draw=gray!50},
axis lines=middle,
y label style={at={(axis description cs:-0.04,.5)},rotate=90,anchor=south},
xlabel near ticks,
minor tick num=5,
enlargelimits={abs=0.5},
ticklabel style={font=\tiny,fill=white},
axis x line = bottom,
axis y line = left,
axis line style={-stealth}
]
\def\closeby{3.2}
\def\spaced{3.7}
\coordinate(Sag1) at (axis cs: 3.5,0);
\coordinate(Sag2) at (axis cs: 3.5,1.835);
\draw[stealth-stealth] [black](Sag1) -- (Sag2) node [above,midway, rotate=90]{$\qty{2.33}{\meter}$};
\coordinate(Sag1) at (axis cs: \closeby, 0);
\coordinate(Sag2) at (axis cs: \closeby, 2.335);
\draw[stealth-stealth] [red](Sag1) -- (Sag2) node [above,midway, rotate=90]{$\qty{2.353}{\meter}$};
\coordinate(Sag1) at (axis cs: \spaced, 0);
\coordinate(Sag2) at (axis cs: \spaced, 2.235);
\draw[stealth-stealth] [red](Sag1) -- (Sag2) node [below,midway, rotate=90]{$\qty{2.353}{\meter}$};
\end{axis}
\end{tikzpicture}
\end{figure}
\end{document}
решение1
Один из способов:
- к этикеткам добавить белый фон,
- напишите метки стрелками,
- уменьшить размер шрифта этикеток
- уменьшать
inner ysep
\documentclass[11pt,a4paper,dutch]{article}
\usepackage{xcolor}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\usetikzlibrary{arrows.meta,
calc,
math,
quotes,
angles}
\tikzset{
>=latex,
vector/.style = {->,very thick},
every picture/.style = {line width=0.75pt},
lbl/.style = {fill=white, font=\scriptsize, inner ysep=0pt, sloped}
}
\usepackage[per-mode=symbol,
mode=text,
exponent-product=\cdot]{siunitx}
\begin{document}
\begin{figure}
\begin{tikzpicture}[scale=0.9, transform shape]
\fontsize{10pt}{12pt}
\begin{axis}[
width=6cm,
height=6cm,
xmin={-0.7},xmax={5*1.1},
ymin={-0.1*1.1},ymax={2.335*1.1},
y label style={at={(axis description cs:-0.04,.5)},rotate=90,anchor=south},
grid=both,
grid style={line width=.1pt, draw=gray!20},
major grid style={line width=.2pt,draw=gray!50},
axis lines=middle,
y label style={at={(axis description cs:-0.04,.5)},rotate=90,anchor=south},
xlabel near ticks,
minor tick num=5,
enlargelimits={abs=0.5},
ticklabel style={font=\tiny,fill=white},
axis x line = bottom,
axis y line = left,
axis line style={-stealth}
]
\def\closeby{3.2}
\def\spaced{3.7}
\coordinate(Sag1) at (axis cs: 3.5,0);
\coordinate(Sag2) at (axis cs: 3.5,1.835);
\draw[stealth-stealth] (Sag1) -- node [pos=0.3, lbl] {\qty{2.33}{\meter}} (Sag2);
\coordinate(Sag1) at (axis cs: \closeby, 0);
\coordinate(Sag2) at (axis cs: \closeby, 2.335);
\draw[stealth-stealth,red] (Sag1) -- node [pos=0.7, lbl] {\qty{2.353}{\meter}} (Sag2);
\coordinate(Sag1) at (axis cs: \spaced, 0);
\coordinate(Sag2) at (axis cs: \spaced, 2.235);
\draw[stealth-stealth,red] (Sag1) -- node [pos=0.7, lbl] {\qty{2.353}{\meter}} (Sag2);
\end{axis}
\end{tikzpicture}
\end{figure}
\end{document}
Другой вариант — увеличить расстояние между стрелками.