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?
- 260
2 Answers
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
- 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
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}
- 111

\includegraphics{<file>}inside a\nodee.g.\node {\includegraphics{<file>}};. If you just need them as content i.e. pictures. Probably best to convert them to PDF (unless you're usinglatexvia 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:36svg.pathlibrary 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+or%20where there's supposed to be a space. (Not sure which one is more indicated in this case.) – Alenanno Feb 02 '16 at 09:43+or%20don'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