4

I want to use custom nodes in TikZ, with shapes loaded (or otherwise converted) from an SVG file because I don't have enough time to learn pgf to draw the shapes I want. How can I do that?

JesseTG
  • 260
  • 1
    If you turn them into a suitable format, you can use \includegraphics{<file>} inside a \node e.g. \node {\includegraphics{<file>}};. If you just need them as content i.e. pictures. Probably best to convert them to PDF (unless you're using latex via DVI). Of course, the shapes won't be nodes in the sense of having shape-specific handling. If you put an octagon shape in a circular node, the borders of the node will be on the edges of the circle - not the octagon. But you can always place coordinates relative to the images, if necessary, and connect to those etc. – cfr Feb 02 '16 at 03:36
  • No good, because I also want to have text in these nodes (and I don't want to write the text inside the SVG). – JesseTG Feb 02 '16 at 04:21
  • Although very brief, have you had a look the svg.path library from the PGF/TikZ manual (http://ctan.unsw.edu.au/graphics/pgf/base/doc/pgfmanual.pdf#SVG-Path Library)? By using that, you may be able to declare new shapes (http://ctan.unsw.edu.au/graphics/pgf/base/doc/pgfmanual.pdf#declaring new shapes).

    PS: The urls in the parenthesis do contain spaces. This is not a mistake (though I can't seem to get markdown to accept that).

    – JP-Ellis Feb 02 '16 at 05:58
  • To me seems to more simple to look in manual for available shapes (you already use TikZ) and it from scratch than make all needed transformation from SVG. – Zarko Feb 02 '16 at 06:19
  • @JP-Ellis Who created the site was wrong about putting the spaces in. Anyway, add + or %20 where there's supposed to be a space. (Not sure which one is more indicated in this case.) – Alenanno Feb 02 '16 at 09:43
  • @Alenanno The + or %20 don't work... I don't know why though. This may be a browser-specific thing given that they are argument given to the PDF viewer? – JP-Ellis Feb 02 '16 at 10:35

2 Answers2

3

There is an svg2tikz extension for inkscape available from

https://github.com/kjellmf/svg2tikz

I haven't tried it personally so no example here. Jake has an example on site at

https://tex.stackexchange.com/a/245839/1090

David Carlisle
  • 757,742
  • This doesn't answer the question as far as I can tell because you can't create new node types this way, can you? Or have I misunderstood the question or the extension or both? – cfr Feb 02 '16 at 18:00
  • @cfr not sure really but anyway even if manual editing is required afterwards converting the svg to (any) tikz is perhaps a useful first step. It is currently the only suggested answer, if someone posts a better answer and this proves to be misleading, I'm happy to delete – David Carlisle Feb 02 '16 at 18:44
  • I think this is probably the best answer there is, because I don't think there is a way of doing what the OP wants. As I understand it, defining new kinds of nodes is a bit tricky (which is why pics are so much easier) and I don't think it can be automated in the way that reproducing the shape can be. [I think this may be why the OP says specifically they don't want to learn PGF as opposed to TikZ.] – cfr Feb 02 '16 at 19:38
0

This is supported with graphics converted to .png or .jpg, by pgfdeclareimage and standard tikz features. Let me share an example where I build a graph with Lego nodes to visualize the BERTopic model architecture:

\documentclass{standalone}

\usepackage{tikz} \usetikzlibrary{positioning}

\begin{document}

\pgfdeclareimage[width=4cm, height=2.5cm]{lego}{figures/lego-piece.png} \begin{tikzpicture} \node (embed) [label=center:\texttt{all-MiniLM-L6-v2}] {\pgfuseimage{lego}}; \node [right=1 cm of embed] {sentence embedding}; \node (reduce) [above=-0.85cm of embed, label=center:\texttt{PCA}] {\pgfuseimage{lego}}; \node [right=1 cm of reduce] {dimensionality reduction}; \node (cluster) [above=-0.85cm of reduce, label=center:\texttt{KMeans}] {\pgfuseimage{lego}}; \node [right=1 cm of cluster] {clustering}; \node (countvect) [above=-0.85cm of cluster, label=center:\texttt{CountVectorizer}] {\pgfuseimage{lego}}; \node [right=1 cm of countvect] {tokenizing}; \node (weight) [above=-0.85cm of countvect, label=center:\texttt{c-TF-IDF}] {\pgfuseimage{lego}}; \node [right=1 cm of weight] {weighting schema}; \draw [<-] (weight) edge (countvect) (countvect) edge (cluster) (cluster) edge (reduce) (reduce) edge (embed) ; \end{tikzpicture}

\end{document}

Gives this nice output (which can be further improved): enter image description here