I have a code that looks something like the following, where I have arrows with text crossing over a dashed line from a rectangle.
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{graphicx}
\usepackage{tikz, pgfplots}
\usetikzlibrary{positioning}
\begin{document}
\begin{tikzpicture}
\draw (0,1) rectangle (2,-1) [dashed];
\node (A) at (-1, 0) {A};
\node (B) at (1, 0) {B};
\draw [->] (-0.8, 0.1) -- (0.8, 0.1) node[above, midway] {text1};
\draw [->] (0.8, -.1) -- (-0.8, -.1) node[below, midway] {text2};
\end{tikzpicture}
\end{document}
The output of my code looks like this:
I would like to have the diagram arranged such that the text is layered over the rectangle. I did find that using fill opacity
option for the text can fill over the rectangle, however for longer texts this also cuts out the arrow when it fills over the text, which I want to avoid:
I would really appreciate if someone could point me towards making an arrow with text that can just cover over the rectangle, but does not interfere with covering over other arrows/texts.