2

I would like to implement this picture. The label in the center is arbitrary, but the label in the northeast corner is an ascending integer. My MWE was the best I could do.

enter image description here

Here is my MWE.

\documentclass[10pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{tikz}
\begin{document}

\begin{tikzpicture}
\foreach \i in {1,...,9}
{
     \pgfmathtruncatemacro{\y}{(\i - 1) / 3};
     \pgfmathtruncatemacro{\x}{\i - 3 * \y};
     \pgfmathtruncatemacro{\label}{\x + 3 * (2 - \y)};
     \node[circle,draw=black,fill=white!80!black,minimum size=20]
     (\label) at (1.5*\x,1.5*\y) {\label};
}

\draw (1) -- (2);
\draw (2) -- (3);
\draw (4) -- (5);
\draw (5) -- (6);
\draw (7) -- (8);
\draw (8) -- (9);

\draw (1) -- (4);
\draw (2) -- (5);
\draw (3) -- (6);
\draw (4) -- (7);
\draw (5) -- (8);
\draw (6) -- (9);

\end{tikzpicture}
\end{document}
1
  • You can use nodes and positioning package with TikZ.
    – CroCo
    Jan 30, 2016 at 16:48

1 Answer 1

1

You can call \usetikzlibrary{positioning} to specify where to place a label. In this case, you want it to the northeast, so you'd specify it as \node[above right=<distance> of \label]. I found a distance of 0 looked nice, but you can adjust it as needed.

\begin{tikzpicture}
\foreach \i in {1,...,9}
{
     \pgfmathtruncatemacro{\y}{(\i - 1) / 3};
     \pgfmathtruncatemacro{\x}{\i - 3 * \y};
     \pgfmathtruncatemacro{\label}{\x + 3 * (2 - \y)};
     \node[circle,draw=black,fill=white!80!black,minimum size=20]
     (\label) at (1.5*\x,1.5*\y) {\label};
     \node[above right=0mm of \label]  {\scriptsize\label};
}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .