# Ensure position of latex code in Inkscape Graphic?

I use Inkscape to create some vector graphics, but I want any text on that graphic being compiled by Latex. Therfore I use the option of Inkscape to create a seperate .pdf_tex file which contains the text information.

This works well in principle, but the position of the text in Latex seems somehow "random". In Inkscape I can very easily place my text correclty (centered within a circle, for example), but once I compile it with latex the text isn't centered anymore...

What is the general workflow to avoid such problems? I really want Latex to compile my texts as they contain a lot math symbols, however I don't want to place them manually with \put(x,y) just to get them at the right position.

Any help is greatly appreciated!

EDIT:

Enclosed a MWE:

\documentclass[a4paper]{scrartcl}

\usepackage{graphicx}
\usepackage{color}

\begin{document}

\begin{figure}[!htb]
\centering
\def\svgwidth{0.2\textwidth}
\input{graphic.pdf_tex}
\end{figure}

\end{document}


Where graphic.pdf_tex is an Inkscape image with a circle and some latex math formula in it.

• I doubt there's a satisfactory answer to this problem, since inkscape can't know the size of the TeX compiled text. I hope I'm wrong. – Ethan Bolker Oct 11 '14 at 18:32
• Welcome to TeX.SE. I think it depends on exactly what the definition of the right position is. If there was an algorithm for that or a way you could control then it should be doable. It would recommend you compose a fully compilable MWE including \documentclass and the appropriate packages that illustrates the problem along with some cases where you show how the right position should be determined or specified. – Peter Grill Oct 11 '14 at 18:53
• Because of these difficulties, I eventually moved from inkscape to tikz. A bit of a steep learning curve, but much nicer output overall. – penguinpreferred Oct 12 '14 at 2:05

To align text horizontally, you should use the text alignment options in Inkscape. For each piece of text that you enter, you should consciously choose an alignment to suit its positioning in the graphic. For example, to centre text (horizontally) in a circle, my usual workflow is:

1. Use the text tool to enter some text.
2. Click the align center button (for text).
3. Use the Align and Distribute panel to align the text in the middle of the circle.

Some examples where aligning text will improve the aesthetics include right-aligning labels on the y-axis of a line chart and centre-aligning labels on the x-axis. Do not forget to left-align when necessary.

This workflow will not be able to accurately centre the text vertically because, as the comments state, Inkscape has no way of knowing the size of your text. Although it is not ideal, you should be able to adjust the vertical positioning with relative ease.

• Hi, thanks for the advise but this is how I already place all my text in Inkscape. The text itself is perfectly centered and placed in Inkscape, but when I compile the text in latex, it is shifted even if I align everything correct. It would be enough if the center position of the Latex text text would be exactly the same as in Inkscape. Is there any way to achieve this? – inkscape_user Oct 12 '14 at 0:59
• Just to be sure: when you select the text that you want to centre, you should see a small white square below it. Is it positioned in the centre, left or right? – Anthony Oct 12 '14 at 13:59
• Hi, yes it is centered in the middle of the text. However, I found a "hack" to make the horizontal position in inkscape correspond exactly to the horizintal position in latex: By putting everything in a zero width box: \makebox[0pt]{$f(x) = x^2$} Then, if the text is aligned to the center in Inkscape, the small white dot/square in the text is exactly matched to the horizontal centre of the compiled text in latex. However, this only works for horizontal positioning... If there would be a way for vertical position too, the problem would be fixed - any idea how to achieve this? – inkscape_user Oct 12 '14 at 16:56
• We are definitely doing the same thing and it works for me but not for you! Could you add a sample graphic.svg to your MWE? You could use Google Drive, Dropbox, etc. to host the file. As for vertical aligning, I don't think Inkscape is able to align text vertically so I have no idea how to do this. – Anthony Oct 12 '14 at 18:06
• As an aside, your MWE suggests that you are not using the svg package. If you use Linux or OS X, then you may it is the useful for streamlining your Inkscape workflow, especially if you work with lots of graphics. – Anthony Oct 12 '14 at 18:09

There are (at least) two ways to specify the alignment in Inkscape. If you set the alignment from the top toolbar with the text tool and some text selected, the alignment gets applied to the tspan node in the XML and you it does not get centered in the LaTeX.

The way to do it is to select the text object with the selector tool, so you should see the selection box like so:

Then you can set the centering property of the text node in the "Text and Font" inspector pane that comes up with shift-ctrl-T.

This at least fixes the horizontal centering, though it doesn't address vertical centering.

One workaround that works for me is to format the svg's text in Latin Modern Roman font and with the size that will be used in the document later (e.g. 12pt). In draw.io, the font is called LMRoman.

This places the svg text at a position that works for that font. When you export to pdf + pdf_tex, the text will be correctly vertically aligned.

• The only drawback is that it has to be adjust manually (not only once, but whenever you change your font)... – TeXnician Aug 30 '17 at 17:10