3

I am trying to visualize a perfect matching by drawing a circle with a given even number of points on its boundary and some number chords going between these points so that each point is incident to exactly one chord. This is my current output:enter image description here

The code I'm using is modified from another example. At the moment, I get almost what I want.

\documentclass{article}
\usepackage{tikz}

\newcommand\matching[2]{
\begin{tikzpicture}
\foreach \x [count=\p] in {0,...,#1} {
    \node[shape=circle,fill=black, scale=0.5] (\p) at (-\x*360/#1:2) {};};
\foreach \x [count=\p] in {1,...,#1} {
    \draw (\x*360/#1:2.4) node {\p};}; 
\draw (1) arc (1:360:2);
\foreach \x/\y in {#2} {
   \draw (\x) -- (\y);}
\end{tikzpicture}}

\begin{document}
\matching{8}{7/4, 2/5, 1/8, 6/3}
\end{document} 

In the above example, I want the chords between the following points 7/4, 2/5, 1/8 and 6/3 which is not in agreement with the picture. Furthermore, I would like to have the point 1 in the uppermost position instead of the 2.

4

I don’t fully understand what you mean with the connections being different between your code and your output, but you can use the following code, which is a bit simpler than your approach:

\documentclass[tikz]{standalone}
\usetikzlibrary{calc}

\newcommand\matching[2]{%
 \begin{tikzpicture}
  \draw (0,0) circle (2);
  \foreach \x in {1,...,#1} {
   \node[shape=circle,fill=black, scale=0.5,label={{((\x-1)*360/#1)+90}:\x}] (n\x) at ({((\x-1)*360/#1)+90}:2) {};
  };
  \foreach \x/\y in {#2} {
   \draw (n\x) -- (n\y);
  }
 \end{tikzpicture}%
}

\begin{document}
\matching{8}{7/4, 2/5, 1/8, 6/3}
\end{document} 

Resulting in:

enter image description here

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.