1

Hi guys I have a problem creating a graph in latex and I will appreciate some help. I want this picture but with the edge between 1 and 4 in thick red. Also If I can somehow have the vertices named and display their names that will be very helpful. I really appreciate input thank you!!!

\begin{tikzpicture}[transform shape]
  \foreach \x in {1,...,4}{%
    \pgfmathparse{(\x-1)*360/4}
    \node[draw,circle,inner sep=0.15cm] (N-\x) at (\pgfmathresult:1.4cm) {};
  } 
  \foreach \x [count=\xi from 1] in {1,...,3}{%
    \foreach \y in {\x,...,4}{%
     \path (N-\x) edge[ultra thin,-] (N-\y);
  }
}
\end{tikzpicture}
2

For the red part :

\documentclass{standalone}
\usepackage{tikz}
\usepackage{etoolbox}
\begin{document}
\begin{tikzpicture}[transform shape]
  \foreach \x in {1,...,4}{%
    \pgfmathparse{(\x-1)*360/4}
    \node[draw,circle,inner sep=0.15cm] (N-\x) at (\pgfmathresult:1.4cm) {\x};
  } 
  \foreach \x [count=\xi from 1] in {1,...,3}{%
    \foreach \y in {\x,...,4}{%
      \ifboolexpr{ test {\ifnumcomp{\x}{=}{1}} and test {\ifnumcomp{\y}{=}{4}} }
      {\path (N-\x) edge[ultra thin, draw=red,-] (N-\y);}
      {\path (N-\x) edge[ultra thin,-] (N-\y);}
  }
}
\end{tikzpicture}
\end{document}

enter image description here

1

See if the following (simple) solution works for you:

\documentclass[tikz, border=3mm]{standalone}

    \begin{document}
\begin{tikzpicture}[transform shape]
  \foreach \x in {1,...,4}{
    \node[draw,circle,inner sep=0.15cm] (N\x) at ({(\x-1)*90}:1.4cm) {};
  }
  \foreach \x in {1,...,3}{%
    \foreach \y in {\x,...,4}{%
        \ifnum\x=3 
    \path (N\x) edge[draw=red,ultra thin] (N\y);
        \else
    \path (N\x) edge[ultra thin] (N\y);
        \fi
  }
}
\end{tikzpicture}
    \end{document}

enter image description here

  • The highlighted edge is between 3 and 4, not 1 and 4 here? – jak123 Mar 16 '16 at 9:37
  • @jak123, you have right. I rotate picture for 90 degrees. It is corrected now. However, this doesn't change the showed way how to highlight desired path. – Zarko Mar 16 '16 at 10:14

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.