Search code examples
latexinkscape

Ensure text postion of Inkscape drawing in latex document


I am trying to create Graphics with Inkscape and include them in my Latex document, but I got a problem with the text alignment. As you can see i the picture below the text in my Inkscape drawing is centered inside the box, but if I include the pdf_tex file in latex the text alignment changes. I export the pdf with the option "Omit text in pdf and create Latex file". How can i solve this problem?

Problem

This is the .svg-File : SVG-FILE


Solution

  • Pre remark:

    • In particular if you want to make many such graphics, I recommend tikz. This would ensure that they follow the same design.

    That being said, there are 3 problems which make your text misaligned:

    • The font size you use in inkscape is 7 pt, which is much smaller than the font used on your latex document. Use a similar font size in inkscape then in your document to make sure the boxes are big enough for your text. Or use the same fontsize in your document

      \documentclass{article}
      
      \usepackage{xcolor}
      \usepackage{graphicx}
      
      \begin{document}
      
      \fontsize{7pt}{7pt}
      
      \def\svgwidth{\textwidth}
      \input{test.pdf_tex}
      
      \end{document}
      
    • The width of the graphic is also bigger than the default text width in latex, so when you include it, you will probably scale down the boxes but not the font. Make the inkscape image a similar width to avoid the problem.

    • As you can see from the small open rectangle at the bottom left of the text, your text is left aligned. This means if you change the relative size of the blocks compared to the font size, it will be misaligned.

    enter image description here

    You can lessen this problem by making your text centred:

    enter image description here

    All together, this gives:

    enter image description here