1

I'm using TikZiT(see link) to draw graphs with nods and edges. How to translate that picture to pdf version of my LaTeX document if possible. There is a code below picture in TikZiT which I copy paste to LaTeX document but it doesn't show the picture in pdf format and I don't know what exactly I'm missing here. I only have \usepackage{tikz} in preamble of LaTeX document.

example of TikZiT code that I copy paste to LaTeX:

\begin{tikzpicture}
\begin{pgfonlayer}{nodelayer}
    \node [style=newstyle] (0) at (0, -0) {};
    \node [style=newstyle] (1) at (0, 0.5) {};
    \node [style=newstyle] (2) at (0.5, 0.5) {};
    \node [style=newstyle] (3) at (1, 0.5) {};
    \node [style=newstyle] (4) at (0.5, -0) {};
    \node [style=newstyle] (5) at (1, -0) {};
    \node [style=newstyle] (6) at (1, 0.5) {};
    \node [style=newstyle] (7) at (1, -0) {};
    \node [style=newstyle] (8) at (1, 0.5) {};
\end{pgfonlayer}
\begin{pgfonlayer}{edgelayer}
    \draw [style=simple] (3) to (5);
    \draw [style=simple] (5) to (1);
    \draw [style=simple] (3) to (0);
    \draw [style=simple] (2) to (4);
\end{pgfonlayer}
\end{tikzpicture}
/* picture in TikZiT represents six nodes and few lines connecting them /*
  • 1
    Welcome to TeX SE! It would be appreciated if you would complete your code to form a complete, small document people can compile to play with. How exactly are you adding this to you document? (What environment are you putting it in?) And what error messages/warnings do you get? Normally, those kinds of commands would be in a tikzpicture environment, and you would have definitions somewhere of the styles you are using (simple, newstyle). Also, I suspect you're missing definitions of layers and the relevant libraries. If this is what TiKZiT gives you, I think you'd be better to learn TiKZ. – cfr Oct 10 '14 at 22:04
  • 2
    You probably need parts of the preamble in your document. Details of how to find this are at tikzit.sourceforge.net/manual.html. – cfr Oct 10 '14 at 22:08
  • After playing with the tool for a little bit, it's a good tool—but it does not define the styles for you. You must do this yourself (but it really isn't difficult). – Sean Allred Oct 10 '14 at 22:11
2

You need to declare the layers and the two missing styles. Not sure what the style defintions should be so I just set them to draw thick lines:

enter image description here

Code:

\documentclass{article}
\usepackage{tikz}

%% -------------------------------------- Declare the layers
\pgfdeclarelayer{nodelayer}
\pgfdeclarelayer{edgelayer}
\pgfsetlayers{edgelayer,nodelayer,main}

%% -------------------------------------- Declare the styles
\tikzset{newstyle/.style={thick}}
\tikzset{simple/.style={thick}}

\begin{document}

\begin{tikzpicture}
\begin{pgfonlayer}{nodelayer}
    \node [style=newstyle] (0) at (0, -0) {};
    \node [style=newstyle] (1) at (0, 0.5) {};
    \node [style=newstyle] (2) at (0.5, 0.5) {};
    \node [style=newstyle] (3) at (1, 0.5) {};
    \node [style=newstyle] (4) at (0.5, -0) {};
    \node [style=newstyle] (5) at (1, -0) {};
    \node [style=newstyle] (6) at (1, 0.5) {};
    \node [style=newstyle] (7) at (1, -0) {};
    \node [style=newstyle] (8) at (1, 0.5) {};
\end{pgfonlayer}
\begin{pgfonlayer}{edgelayer}
    \draw [style=simple] (3) to (5);
    \draw [style=simple] (5) to (1);
    \draw [style=simple] (3) to (0);
    \draw [style=simple] (2) to (4);
\end{pgfonlayer}
\end{tikzpicture}

\end{document}
2

OK. I compiled and installed TiKZit in order to retrieve the rest of the default preamble. The only thing I don't know is what the definition of newstyle should be. I guess this is your own. Here, I've just made it the same as simple but in green rather than black.

\documentclass{article}
\usepackage[svgnames]{xcolor}
\usepackage{tikz}
\usetikzlibrary{decorations.markings}
\usetikzlibrary{shapes.geometric}
\pagestyle{empty}

\pgfdeclarelayer{edgelayer}
\pgfdeclarelayer{nodelayer}
\pgfsetlayers{edgelayer,nodelayer,main}

\tikzstyle{none}=[inner sep=0pt]

\tikzstyle{rn}=[circle,fill=Red,draw=Black,line width=0.8 pt]
\tikzstyle{gn}=[circle,fill=Lime,draw=Black,line width=0.8 pt]
\tikzstyle{yn}=[circle,fill=Yellow,draw=Black,line width=0.8 pt]

\tikzstyle{simple}=[-,draw=Black,line width=2.000]
\tikzstyle{arrow}=[-,draw=Black,postaction={decorate},decoration={markings,mark=at position .5 with {\arrow{>}}},line width=2.000]
\tikzstyle{tick}=[-,draw=Black,postaction={decorate},decoration={markings,mark=at position .5 with {\draw (0,-0.1) -- (0,0.1);}},line width=2.000]

% this are just for tikzit's display, I think
% \usepackage[graphics,tightpage,active]{preview}
% \PreviewEnvironment{tikzpicture}
% \newlength{\imagewidth}
% \newlength{\imagescale}

\tikzstyle{newstyle}=[% this is a custom style - you need to replace with whatever definition you are using
  -,draw=Green,line width=2.000]

\begin{document}

  \begin{tikzpicture}
    \begin{pgfonlayer}{nodelayer}
      \node [style=newstyle] (0) at (0, -0) {};
      \node [style=newstyle] (1) at (0, 0.5) {};
      \node [style=newstyle] (2) at (0.5, 0.5) {};
      \node [style=newstyle] (3) at (1, 0.5) {};
      \node [style=newstyle] (4) at (0.5, -0) {};
      \node [style=newstyle] (5) at (1, -0) {};
      \node [style=newstyle] (6) at (1, 0.5) {};
      \node [style=newstyle] (7) at (1, -0) {};
      \node [style=newstyle] (8) at (1, 0.5) {};
    \end{pgfonlayer}
    \begin{pgfonlayer}{edgelayer}
      \draw [style=simple] (3) to (5);
      \draw [style=simple] (5) to (1);
      \draw [style=simple] (3) to (0);
      \draw [style=simple] (2) to (4);
    \end{pgfonlayer}
  \end{tikzpicture}

\end{document}

6 node graph

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.