[Tex/LaTex] the best way to name nodes in TikZ

nodestikz-pgf

I found there are several ways to name a node (please relate to the MWE for more) but I am wondering if there are other (rather "simple") ways of doing this:

  1. My current 'best practice', it works with 2 node commands in a \draw command.
  2. My second way of doing this, it's very useful when paths based on names of nodes shall be produced, which again is useful when an axis is scaled individually and therefor all other measures within a scope.
  3. The initial attempt which actually does not work as intended and lead to nr. 2.

Would anyone happen to have some advice to simplify the code? Or what else could be done? I'd appreciate anyh ints!

Display

MWE:

\documentclass[
a4paper
]{scrartcl}

\usepackage{
lmodern,
booktabs,
tikz
}
\usepackage[T1]{fontenc}

\begin{document}
\begin{center}
\begin{tikzpicture}[font=\sffamily\small]
    %
    \draw[style=help lines,step=0.5cm] (0,0) grid (6.2,6.2);
    %
    \draw[->,thick] (-0.1,0) -- (6.5,0) node[anchor=west]{x}; %X-Achse
    \draw[->,thick] (0,-0.1) -- (0,6.5) node[anchor=south]{y}; %Y-Achse
    %
    \foreach \x in {0,1,...,6} \draw [thick](\x cm,-2pt) -- (\x cm,2pt);
    \foreach \y in {0,1,...,6} \draw [thick](-2pt,\y) -- (2pt,\y);
    %
    \foreach \x in {0,1,...,6} \draw (\x cm, 0 cm) node[anchor=north]{\x};
    \foreach \y in {0,1,...,6}  \draw (0 cm, \y cm) node[anchor=east]{\y};
    %
    \begin{scope}[color=black]
    %1.
    \filldraw (2,1) circle (0.08cm) node (A) {} node[anchor=north,fill=white,yshift=-0.1cm]{A};
    %2.
    \filldraw (4,2) circle (0.08cm) node[anchor=west,fill=white] (B) {B};
    %3.
    \filldraw (3,5) circle (0.08cm) node[anchor=south,fill=white,yshift=0.1cm]{C};
    \node (C) at (3,5) {};
    \end{scope}
    \draw[very thick] (A.center) -- (B.center) -- (C.center) -- cycle;
\end{tikzpicture}
\end{center}

Best Answer

A solution with a different approach: name your coordinates then add the labels.

enter image description here

The code:

\documentclass[tikz]{standalone}
\usepackage{lmodern}
\usepackage[T1]{fontenc}
\begin{document}
\begin{tikzpicture}[font=\sffamily\small]
    %
    \draw[style=help lines,step=0.5cm] (0,0) grid (6.2,6.2);
    %
    \draw[->,thick] (-0.1,0) -- (6.5,0) node[anchor=west]{x}; %X-Achse
    \draw[->,thick] (0,-0.1) -- (0,6.5) node[anchor=south]{y}; %Y-Achse
    %
    \foreach \x in {0,1,...,6} \draw [thick](\x cm,-2pt) -- (\x cm,2pt);
    \foreach \y in {0,1,...,6} \draw [thick](-2pt,\y) -- (2pt,\y);
    %
    \foreach \x in {0,1,...,6} \draw (\x cm, 0 cm) node[anchor=north]{\x};
    \foreach \y in {0,1,...,6}  \draw (0 cm, \y cm) node[anchor=east]{\y};
    % triangle with coordinates
    \draw[very thick]
    (2,1) coordinate (A)
    -- (4,2) coordinate (B)
    -- (3,5) coordinate (C)
    -- cycle;
    %
    \foreach \pt/\labpos in {A/below left,B/right,C/above}{
      \filldraw (\pt) circle(.8mm) node[\labpos=1.5mm,fill=white]{\pt};
    }
\end{tikzpicture}
\end{document}