我发现有几种方法可以命名一个节点(有关更多信息,请参阅 MWE),但我想知道是否还有其他(相当“简单”)的方法来做到这一点:
- 我目前的‘最佳实践’是,它在一个命令中使用 2 个
node
命令\draw
。 - 我的第二种方法是,当需要生成基于节点名称的路径时,这种方法非常有用,当单独缩放轴并因此缩放范围内的所有其他度量时,这种方法也非常有用。
- 初次尝试实际上并未按预期进行,并导致了第 2 项结果。
有人能给些建议来简化代码吗?或者还能做些什么?非常感谢大家的帮助!
平均能量损失:
\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}
答案1
采用不同方法的解决方案:命名您的坐标,然后添加标签。
代码:
\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}