![chains](https://linux22.com/image/366511/chains.png)
第二、第三和第四个公式应该像第一行中的公式一样位于点的右侧。
平均能量损失
\documentclass{scrartcl}
\usepackage{amsmath}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
% Graph Paper
\draw[step=0.5,help lines,black!20] (-5,-5) grid (10,5);
% Coordinate
\coordinate (a) at (0,0);
% Nodes
\node[right of=a] {\(y = 5 - 3x\)};
\node[below of=a] (b) {\(y = 5 - 3x\)};
\node[below of=b] (c) {\(y = 5 - 3x\)};
\node[below of=c] (d) {\(\frac{1}{2}\)};
% Points
\fill (a) circle[radius=2pt];
\fill (b) circle[radius=2pt];
\fill (c) circle[radius=2pt];
\fill (d) circle[radius=2pt];
\end{tikzpicture}
\end{document}
答案1
这是另一种方法,使用positioning
库及其below=of
语法,而不是弃用的below of=
语法(参见PGF/TikZ 中“right of=”和“right=of”之间的区别)。这里的一个关键点就是样式on grid
中的key eqitem
,表示节点之间的距离是在节点的中心点之间测量的,而不是边之间的。
节点本身只是填充的黑色圆圈,而方程式则作为标签添加到节点,由样式的默认参数提供eqitem
。#1
样式定义中的 表示它必须用作eqitem={...}
,其中...
是标签文本,它放置在数学模式中。
另请参阅代码中的一些注释。
\documentclass{scrartcl}
\usepackage{amsmath}
\usepackage{tikz}
\usetikzlibrary{positioning}
\begin{document}
\begin{tikzpicture}[
node distance=10mm, % set distance between nodes
eqitem/.style={
on grid, % node distance measured between node centers
circle, % circular node ...
fill, % filled (with black, the default colour) ...
minimum size=4pt, % diameter 4pt because no content and ...
inner sep=0, % no padding between content and node edge
label={right:$#1$}} % add label right of the node
]
% Graph Paper
\draw[step=0.5,help lines,black!20] (-5,-5) grid (10,5);
\node [eqitem={y = 5 - 3x}] (a) at (0,0.25) {};
\node [eqitem={y = 5 - 3x},below=of a] (b) {};
\node [eqitem={y = 5 - 3x},below=of b] (c) {};
\node [eqitem={y = 5 - 3x},below=of c] (d) {};
\end{tikzpicture}
\end{document}
chains
对此的一个可能有用的扩展是利用chains
库。这允许您创建节点“链”,这些节点会自动放置在链中上一个节点的下方或旁边。
样式中新增加的内容是on chain
,并且我name
在中添加了label
,这样您可以稍后将它们作为坐标引用,例如,如果您需要从一个坐标绘制箭头。
\documentclass{scrartcl}
\usepackage{amsmath}
\usepackage{tikz}
\usetikzlibrary{
positioning,
chains
}
\begin{document}
\begin{tikzpicture}[
node distance=10mm,
eqitem/.style={
on grid,
circle,
fill,
minimum size=4pt,
inner sep=0,
label={[name=\tikzchaincurrent-l]right:$#1$}, % \tikzcurrent is name of current node in chain
node contents={}, % node text, with this we can use \node[...]; instead of \node[...] {};
on chain % add node to current chain
}]
% Graph Paper
\draw[step=0.5,help lines,black!20] (-5,-5) grid (10,5);
\begin{scope}[
start chain=eqs1 going below
]
\node [eqitem={y = 5 - 3x}];
\node [eqitem={y = 5 - 3x}];
\node [eqitem={y = 5 - 3x}];
\node [eqitem={y = 5 - 3x}];
\end{scope}
\begin{scope}[
start chain=eqs2 going below
]
% place the first node in the chain with at={(x,y)}, the rest are placed automatically
\node [eqitem={y = 5 - 4x},at={(3,0)}];
\node [eqitem={y = 5 - 5x}];
\node [eqitem={y = 5 - 6x}];
\node [eqitem={y = 5 - 7x}];
\end{scope}
% to illustrate that node names are available
% the circles in the eqs1 chain are named eqs-N, while the labels
% (i.e. the equations) are named eqs-N-l (l for label)
\draw [red,shorten <=2pt,shorten >=3pt,->] (eqs1-1) to[bend left] (eqs2-1);
\draw [blue,shorten <=2pt,shorten >=3pt,->] (eqs1-4-l) to[bend right] (eqs2-4-l);
\end{tikzpicture}
\end{document}