I have a drawing in TiKZ (of a graph, say) and I want to highlight two paths in the drawing. Is there a way to do that using my already-defined node names, without explicitly making new coordinates?
I can almost get there by making my extra paths go through node anchors, but I'd like to offset the paths farther away from the nodes than where the anchors are.
(I've attached a minimal example below. Ideally, I'd like both the red and blue paths to be on the outside of the triangle.)
\documentclass{article}
\usepackage{tikz}
\usepackage{pgf}
\usepackage{pgfplots}
\usetikzlibrary{calc, through}
\tikzstyle{vertex}=[circle, draw, inner sep=1pt, minimum size=6pt, fill=black!20]
\begin{document}
\begin{tikzpicture}
\foreach \i in {0,1,2}{\node[vertex] (\i) at (\i*120:1) {};}
\node[vertex] (4) at (2,0){};
\draw (0) --(1) --(2) -- (0);
\draw[dashed] (0) -- (4);
\draw[red, rounded corners] (4.north) -- (0.north) -- (1.north east) --(1.west) -- (2.west);
\draw[blue, rounded corners] (1.south east) -- (2.south east) -- (0.south) --(4.south);
\end{tikzpicture}
\end{document}
Best Answer
If you put both on the outside, one with partially overwrite the other, won't it?
So you could use the
positioning
library to fine tune the spacing and avoid the second path overwriting the first:or, setting the
node distance=.25mm
:To change the node distance only locally so that it does not affect the location of other nodes in a complex diagram, you can limit the scope of the setting. For example, in this diagram, I limit the setting of
node distance=.25mm
and illustrate this by placing another nodez
after the scope of the setting has ended:Note that the only difference between
and
as regards location is that the former is within the scope of
\tikzset{node distance=.25mm}
whereas the latter is not and therefore uses the default setting.