3

Please, I want to draw a tournament digraph of order n (n=6 as example) with tikz. But i don't know how i can exclude the repeated vertex in the seconde loop. There is my code:

\documentclass{article}
\usepackage{tikz}
\usepackage{tkz-graph}
\usetikzlibrary{graphs,graphs.standard}

    \begin{document}
            \begin{tikzpicture}
            \SetGraphUnit{2}
            \renewcommand*{\VertexLineColor}{white}
            \renewcommand*{\VertexLightFillColor}{red}
            \renewcommand*{\VertexLineWidth}{1pt}
            \GraphInit[vstyle=Welsh]
            \Vertices{circle}{1,2,3,4,5,6}
            \AddVertexColor{blue}{5,1}
            \SetUpEdge[style={->,very thick},color=red]
            \foreach \v in {1,...,5}{
              \foreach \vv in {\v,...,6}{\Edge(\v)(\vv)};  
            };

        \end{tikzpicture}
    \end{document}

enter image description here

HTeX
  • 77
  • please extend your code snippet to complete small document beginning with \documentclass{...} and end with \end{document}. As it is, it gives errors (undefined control sequence ...). Welcome to TeX.SE! – Zarko May 18 '17 at 17:38
  • please add code in question. – Zarko May 18 '17 at 17:45
  • I took liberty and instead you edit your question (complete code snippet and correct question title and text. You image is drawn with tkz-graph (which is based on tikz) . Next time this you should do yourself ... – Zarko May 18 '17 at 18:59

3 Answers3

4
\documentclass{article} 
\usepackage{tkz-graph} 
\usetikzlibrary{arrows.meta}

\begin{document}
    \begin{tikzpicture}
    \SetGraphUnit{2}
    \renewcommand*{\VertexLineColor}{white}
    \renewcommand*{\VertexLightFillColor}{red}
    \renewcommand*{\VertexLineWidth}{1pt}
    \GraphInit[vstyle=Welsh]
    \Vertices{circle}{1,2,3,4,5,6}
    \AddVertexColor{blue}{5,1}
    \SetUpEdge[style={-{Straight Barb[length=1mm,width=1.2mm]}, thick},color=red]
     \foreach \v [count=\vi from 2] in {1,...,5}{
     \foreach \vv in {\vi,...,6}{\Edge(\v)(\vv)};      
     }; 
\end{tikzpicture}    
\end{document}

gives:

![enter image description here

Addendum: Solution for your request in one of your comment:

\documentclass{article}
\usepackage{tkz-graph}
\usetikzlibrary{arrows.meta}


\begin{document}
    \begin{tikzpicture}
    \SetGraphUnit{2}
    \renewcommand*{\VertexLineColor}{white}
    \renewcommand*{\VertexLightFillColor}{red}
    \renewcommand*{\VertexLineWidth}{1pt}
    \GraphInit[vstyle=Welsh]
    \SetVertexNoLabel % <-- added
    \Vertices{circle}{1,2,3,4,5,6}
    \SetUpEdge[style={-{Straight Barb[length=1mm,width=1.2mm]}, thick},color=red]
     \foreach \v [count=\vi from 2] in {1,...,5}
     {
     \foreach \vv in {\vi,...,6}{\Edge(\v)(\vv)};
     };
     \SetVertexLabel
    \Vertices{circle}{A,B,C,D,E,F} % <-- added
    \AddVertexColor{blue}{1,5}% <-- moved here
\end{tikzpicture}
\end{document}

![enter image description here

Addendum (2): solution for naming of vertices without their double drawing:

\documentclass{article}
\usepackage{tkz-graph}
\usetikzlibrary{arrows.meta}

\begin{document}
    \begin{tikzpicture}
\SetGraphUnit{2}
\renewcommand*{\VertexLineColor}{white}
\renewcommand*{\VertexLightFillColor}{red}
\renewcommand*{\VertexLineWidth}{1pt}
\GraphInit[vstyle=Welsh]
\Vertices{circle}{A,B,C,D,E,F}
\SetUpEdge[style={-{Straight Barb[length=1mm,width=1.2mm]}, thick},color=red]
 \foreach \v [remember=\v as \vi (initially A)] in {B,...,F}
 {
 \foreach \vv in {\v,...,F}{\Edge(\vi)(\vv)};
 };
\AddVertexColor{blue}{A,E}
    \end{tikzpicture}
\end{document}
Zarko
  • 296,517
  • @marsupilam, ups, I forgot to move \AddVertexColor{blue}{1,5} on the place after \Vertices{circle}{A,B,C,D,E,F}. Corected. Thank you very much for notice. – Zarko May 18 '17 at 21:45
  • Sorry deleted my comment after your fix, even though it is worth explaining you place the vertices twice : First for joining, then again for labeling (because tkz-graph doesn' t seem to allow for labeling separately from node-naming). – marsupilam May 18 '17 at 21:51
  • @marsupilam, unfortunately I don't speak French, so the manual for tkz-graph is quite cryptic to me. I search in it for possibilities for labeling nodes independent to nodes' names but there is no example, which I could understand. To solve this problem in side drawing of edges drawing: temporary I didn't manage to make counter \vi as alphabetic. – Zarko May 18 '17 at 21:59
  • too bad for the french, as the tkz-graph manual is entirely written in fully prosodic rhymed alexandrin verses. (More seriously, I think I remember there is some way to TeX-hackishly shift[by a constant-addititive-translation] a character code to another, possibly pushing A to 1 or the other way around... ?) – marsupilam May 18 '17 at 22:17
  • @marsupilam, meanwhile I prepare new solution which the problem of vertices naming is solved in loops for drawing edges. Now the counters in loops are alphabetic and double drawing of vertices is not necessary anymore. – Zarko May 18 '17 at 23:08
2

Use the \ifthenelse construction.

The output

enter image description here

The code

\documentclass[12pt,tikz]{standalone}
\usepackage{tkz-graph}
\begin{document}
\begin{tikzpicture}
  \SetGraphUnit{2}
  \renewcommand*{\VertexLineColor}{white}
  \renewcommand*{\VertexLightFillColor}{red}
  \renewcommand*{\VertexLineWidth}{1pt}
  \GraphInit[vstyle=Welsh]
  \Vertices{circle}{1,2,3,4,5,6}
  \AddVertexColor{blue}{5,1}
  \SetUpEdge[style={->,very thick},color=red]
  \foreach \v in {1,...,5}
  {
    \foreach \vv in {\v,...,6}
    {
      \ifthenelse{\v=\vv}%
      {}% the empty `then` clause
      {%
        \Edge(\v)(\vv)% the `else` clause
      }  
    }
  }
\end{tikzpicture}
\end{document}

Per request

enter image description here

With french names for variables, as a token of appreciation to Alain's mysterious tkz-graph manual.

\documentclass[12pt,tikz]{standalone}
\usepackage{tkz-graph}
\begin{document}
\begin{tikzpicture}
  \SetGraphUnit{2}
  \renewcommand*{\VertexLineColor}{white}
  \renewcommand*{\VertexLightFillColor}{red}
  \renewcommand*{\VertexLineWidth}{1pt}
  \GraphInit[vstyle=Welsh]
  \Vertices{circle}{A,B,C,D,E,F}
  \AddVertexColor{blue}{E,A}
  \SetUpEdge[style={->,very thick},color=red]
  \foreach \lettre/\nombre in {A/1,B/2,C/3,D/4,E/5}
  {
    \foreach \llettre/\nnombre in {A/1,B/2,C/3,D/4,E/5,F/6}
    {
      \ifthenelse{\nombre<\nnombre}
      {%
        \Edge(\lettre)(\llettre)
      }  
      {}
    }
  }
\end{tikzpicture}
\end{document}
marsupilam
  • 6,383
1

Another way, same output.

\documentclass[12pt,tikz]{standalone}
\usepackage{tkz-graph}
\begin{document}
\begin{tikzpicture}
  \SetGraphUnit{2}
  \renewcommand*{\VertexLineColor}{white}
  \renewcommand*{\VertexLightFillColor}{red}
  \renewcommand*{\VertexLineWidth}{1pt}
  \GraphInit[vstyle=Welsh]
  \Vertices{circle}{1,2,3,4,5,6}
  \AddVertexColor{blue}{5,1}
  \SetUpEdge[style={->,very thick},color=red]
  \foreach \v in {1,...,5}
  {
    \foreach \vv in {\number\numexpr\v+1\relax,...,6}
    {
        \Edge(\v)(\vv)
    }
  }
\end{tikzpicture}
\end{document}
marsupilam
  • 6,383