我在两个节点之间画一条线,我想避免接触这两个节点,我可以用第一个节点做到这一点,但不能用第二个节点做到这一点。
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\begin{document}
\tikzstyle{every picture}+=[remember picture]
\tikz[baseline] \node[fill opacity=0.1,circle,label=left:2016,fill=black,inner sep=3pt] at (0,0) (n1) {};
\tikz[baseline] \node[draw=none,fill=none,align=left] {
\vbox{
bar
}
};
\tikz[baseline] \node[draw=none,align=left] {
\hspace*{20mm}\parbox{10cm}{
foo
}
};
\tikz[baseline] \node[fill opacity=0.1,circle,label=left:2016,fill=black,inner sep=3pt] at (0,0) (n2) {};
\tikz[baseline] \node[draw=none,fill=none,align=left] {
\vbox{
bar
}
};
\tikz[baseline] \node[draw=none,align=left] {
\hspace*{20mm}\parbox{10cm}{
foo
}
};
\begin{tikzpicture}[overlay]
\draw (n1)++(0, -0.25) -- (n2)++(0, 0.25);
\end{tikzpicture}
\end{document}
答案1
在您的设置中,您只需要使用\draw ([yshift=-0.1cm]n1.south) -- ([yshift=0.1cm]n2.north);
。但是,无需 ,也可以在单张图片中绘制您的图片remember picture
。
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usetikzlibrary{positioning}
\begin{document}
\begin{tikzpicture}
\node[fill opacity=0.1,circle,label=left:2016,fill=black,inner
sep=3pt,label={[xshift=5mm]right:bar},label={[xshift=2mm,yshift=-5mm]right:foo},] (N1){};
\node[below=1cm of N1,fill opacity=0.1,circle,label=left:2016,fill=black,inner
sep=3pt,label={[xshift=5mm]right:bar},label={[xshift=2mm,yshift=-5mm]right:foo}] (N2) {};
\draw ([yshift=-0.1cm]N1.south) -- ([yshift=0.1cm]N2.north);
\end{tikzpicture}
\end{document}
附录: 使用扎科的方式定义一种通用的风格,可以用来outer sep
产生差距。我宁愿不是使用缩短,因为如果您考虑使用曲线路径,这可能会产生不良的副作用。
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usetikzlibrary{positioning}
\begin{document}
\begin{tikzpicture}[pfft/.style={circle,fill opacity=0.1,fill=black,inner
sep=3pt,outer sep=1mm}]
\node[pfft,label=left:2016,,label={[xshift=5mm]right:bar},label={[xshift=2mm,yshift=-5mm]right:foo},] (N1){};
\node[below=1cm of N1,pfft,label=left:2016,label={[xshift=5mm]right:bar},label={[xshift=2mm,yshift=-5mm]right:foo}] (N2) {};
\draw (N1) -- (N2);
\end{tikzpicture}
\end{document}
答案2
第三种选择是,没有yshift
和没有outer sep
但shorten
在节点之间有选项:
\documentclass[tikz, margin=3.141592mm]{standalone}
\usetikzlibrary{positioning}
\begin{document}
\begin{tikzpicture}[
node distance = 12mm,
dot/.style = {circle, fill=black, fill opacity=0.1,
inner sep=3pt, %No outer sep like in Zarko's answer
node contents={}}
]
\node (n1) [dot, label=left:2016, label={[xshift=3mm]right:bar}, label=below right:foo];
\node (n2) [dot, label=left:2017, label={[xshift=3mm]right:bar}, label=below right:foo,
below=of n1];
\draw[shorten >=2pt, shorten <=2pt] (n1) -- (n2); %No `yshift` like in Marmot's answer
\end{tikzpicture}
\end{document}
答案3
作为对@marmot 的精彩回答的补充:
\documentclass[tikz, margin=3.141592mm]{standalone}
\usetikzlibrary{positioning}
\begin{document}
\begin{tikzpicture}[
node distance = 12mm,
dot/.style = {circle, fill=black, fill opacity=0.1,
inner sep=3pt, outer sep=2pt,
node contents={}}
]
\node (n1) [dot, label=left:2016, label={[xshift=3mm]right:bar}, label=below right:foo];
\node (n2) [dot, label=left:2017, label={[xshift=3mm]right:bar}, label=below right:foo,
below=of n1];
\draw (n1) -- (n2);
\end{tikzpicture}
\end{document}