I'm trying to draw a graph of a few functions intersecting using Tikz. I currently have (just basic plot formatting and the actual plotting) :
\documentclass{article}
\usepackage{tikz}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
axis lines=middle,
xlabel=$x$,
y label style={anchor=north east, at={(axis description cs:0,1)}},
ylabel=$y$,
xmin=-1, xmax=15,
ymin=-5, ymax=30,
axis on top,
xticklabel style={fill=white},
]
\addplot [id=ghosttan, domain=0:15, samples=500, color=black, dashed] {tan(deg(x))};
\addplot [id=tan, domain=0:15, restrict y to domain=-50:50, samples=1000, color=red, line width=0.5pt]{tan(deg(x))};
\addplot [id=root, domain=0:15, samples=100]{sqrt((12/x)^2 - 1)};
\addplot [id=minx, domain=0:15, samples=2]{-1/2*x};
\node [anchor=north east] at (axis cs:0,0) {$0$};
\end{axis}
\end{tikzpicture}
\end{document}
The output is:
The problem I'm having should be obvious: the white label backgrounds that serve to prevent the graphs crossing/interfering with the labels, clear too much, especially around the 6, the 8, and the 14, for example. The final two axis options in the MWE have this purpose, and they were inspired by this thread.
The idea I have is having the labels have a slightly bigger white copy of themselves between the label and the graph. That way, in this example, the 4 would only clear the graph when it hit its diagonal edge passing over part of the label, for example.
Ideally, I want to keep the axes in the back as well, but the labels are of higher priority. I don't know how to manage either, though, which is my question: how do I manage this?


\pgfmathprintnumber{\tick}with symbolic ticks (e.g. fractions of π, most notably), I don't think that'd work, since pgfmathprintnumber converts numbers to floating-point representation. Is there a fix that could generalise the answer to any kind of tick? – Mew Jun 20 '20 at 23:31pgfprintnumber- - - and maybe also deoutlineoption ofcontour(see https://tex.stackexchange.com/questions/8602/how-can-i-put-a-coloured-outline-around-fraction-lines). I do not know how to do it automatically... – Rmano Jun 21 '20 at 07:09