# Inkscape Text background with LaTeX text

I have a diagram created in Inkscape that I'd like to export to PDF with LaTeX text (so the text keeps the properties of the LaTeX document it's used in). In this diagram I have several labeled arrows like this:

Unfortunately if I resize the image in the LaTeX document, these will turn into either

or

Now, I'm OK with the arrow itself limiting how much I can resize the image (without making the text span across the entire arrow), but I'd like at least the spacing of the label to be consistent.

Currently the arrows are composed of the left side (straight line), the text, and the right side (straight line with arrow point). I'd like to instead make the arrow just a single straight line (with an arrow point) and give the text a (non-transparent) white background, which would then expand or contract with the text. Is this possible?

• (you could create such arrows easily with tikz) – samcarter_is_at_topanswers.xyz Nov 12 '20 at 11:36
• \documentclass{article} \usepackage{tikz} \usetikzlibrary{arrows.meta} \begin{document} \begin{tikzpicture}[>=Stealth] \draw[->] (0,0) -- (3,0) node[midway,fill=white] {Pruning}; \end{tikzpicture} \end{document} – samcarter_is_at_topanswers.xyz Nov 12 '20 at 11:54
• My diagram unfortunately also contains some 3D Illustrations, which would be difficult to draw in tikz, and I would like to avoid combining Inkscape and tikz, unless Inkscape allows you to do that automatically. – Mate de Vita Nov 13 '20 at 21:45
• There are extensions like svg2tikz which allow export from inkscape to tikz – samcarter_is_at_topanswers.xyz Nov 13 '20 at 22:09

Don't add the white background in inkscape, just add the text on top of the arrow.

Then export as pdf+tex and open the resulting .pdf_tex file. There search for your text and replace it with \colorbox{white}{text}. This box will automatically adjust to the size of the text.

  \begin{picture}(1,1.41428571)%
\put(0,0){\includegraphics[width=\unitlength,page=1]{drawing.pdf}}%
\put(0.37047077,0.755){\color[rgb]{0,0,0}\makebox(0,0)[b]{\smash{\colorbox{white}{Text}}}}%
\end{picture}%


I don't know if or how well the following would work using your Latex workflow, but this would work in Inkscape: Draw a rectangle over the arrow line, set the fill to white and stroke to none, and then type your text on top. The white rectangle will cover the line.

Once you have done this, you can group the entire graphic using Ctrl+G. Then in Preferences > Behaviour > Transforms, check the option to Scale Stroke Width. Then you can scale the entire graphic by clicking and dragging the corner handle while holding down Ctrl to constrain the aspect ratio.

• Thanks, this solution is a little nicer than what I'm currently doing, however I don't think the background rectangle gets rescaled when resizing the image in LaTeX. – Mate de Vita Nov 13 '20 at 21:47
• @MatedeVita - I tested a PDF saved from Inkscape, and the PDF does respect grouping when reopened in Inkscape and scaling works as it shoud. To be honest I'm not sure why it wouldn't also do that in LaTeX but then again I'm no expert in LaTeX. – Billy Kerr Nov 13 '20 at 22:03
• @BillyKerr If exported as pdf+tex, text and graphical elements are separated. Text will be inserted via a latex picture environment, while the graphical elements will be included as a pdf graphic. Grouping won't have any influence at all. – samcarter_is_at_topanswers.xyz Nov 13 '20 at 22:08
• Maybe you'd get a better response to that particular problem over at the TeX Stack Exchange site. – Billy Kerr Nov 13 '20 at 22:08
• Another possibility might be to use an SVG in LaTeX. I don't know how practical that is however. – Billy Kerr Nov 13 '20 at 22:16