# Creating a graph in LyX

I am new to LyX and I was trying to build the following graph:

• I tried to draw it using Paint but failed to do a proper graph. Hope LyX can do a better job then me.

How To draw this graph in LyX?

• Welcome to TeX SX! I'm no user of LyX, but I can explain a LaTeX code to obtain this graph. – Bernard Jan 25 '18 at 0:03
• Welcome to TeX.SX. Please read the introductory material for this site. When you post a question, please provide a "Minimal Working Example" (MWE) that starts with \documentclass, includes all relevant \usepackage commands, ends with \end{document} and compiles without errors, even if it does not produce your desired output. – Sandy G Jan 25 '18 at 0:03
• LyX does not provide any tool that helps you make such diagrams. I suggest either using TikZ (like the answer by marmot), or using a program called dia. LyX has integration with dia (Insert > File > External Material), so you can right click on a dia diagram in LyX and click "edit" and it will launch dia so you can edit it. – scottkosty Jan 25 '18 at 3:45

## 1 Answer

According to @scottkosty, you should be able to import the following snippet into Lyx.

\documentclass{article}
\usepackage{tikz}
\begin{document}
\newdimen\R % radius
\R=1.5cm
\newdimen\SmallR % node radius
\SmallR=0.5cm
\newcommand{\A}{360/7}
\begin{tikzpicture}
\node[circle,minimum size=2*\SmallR,draw,thick] (1) at (0,0) {1};
\foreach \X in {2,...,8}
{\node[circle,minimum size=2*\SmallR,draw,thick] (\X) at ({-\X*\A+180}:\R) {\X};}
\foreach \X in {2,...,8}
{\pgfmathtruncatemacro{\Y}{mod(\X-1,7)+2}
\draw[-latex] (\X)--({\Y});
\draw[-latex] (1)--({\Y});}
\end{tikzpicture}
\end{document}


When compiled with pdflatex, it produces

• +1 nice solution. Questions about LyX are encouraged at tex.se. See e.g. here: tex.stackexchange.com/help/on-topic. In fact, we even have a "LyX" tag here. And yes, you can use custom LaTeX code in LyX. – scottkosty Jan 25 '18 at 3:42
• @scottkosty Thanks for letting me know. I was glancing through the LyX web site and from what I read there it looked as if this is possible, but I was not sure. Thanks for clarifying this. – user121799 Jan 25 '18 at 3:53
• Yeah it doesn't look clear on the website. What is unfortunately not possible in LyX is to seamlessly toggle between editing LaTeX and using LyX. This is why LyX is not really a "LaTeX editor"; it is a "LaTeX exporter". – scottkosty Jan 25 '18 at 3:56
• @scottkosty Thanks again. Doesn't sound too convenient, then. And probably it won't be straightforward to include an MWE in the document. – user121799 Jan 25 '18 at 4:03
• The .lyx format is just a text file so it can be pasted in just like a .tex file can. The user should give a .lyx MWE and also the exported LaTeX MWE (so that non-LyX users can help). I always point LyX users to the following Wiki page: wiki.lyx.org/FAQ/MinimalExample – scottkosty Jan 25 '18 at 4:06