TikZ: How do I occasionally suppress the join option?
Unfortunately, the join
option doesn't just set some option that can be changed, it appends a command using append after command
. Thus, setting join
twice leads to multiple joins. This is how you can join multiple nodes (e.g., \node [join=with node 1, join=with node 2] {...}
). So what you really need to do is delete all the append after command
commands.
Now you probably don't actually want to do that, as it could cause collateral damage. (Who knows what other options that you're relying on also make use of append after command
internally?) Nonetheless, I believe in directly answering people's questions even when I don't think they should use that answer. So here you go, with a minimal working example that suppresses the join option on one of the nodes:
\documentclass[varwidth,convert]{standalone}
\usepackage{tikz}
\usetikzlibrary{chains}
\begin{document}
\makeatletter
\tikzset{reset after command/.code={\def\tikz@after@path{}}}
\makeatother
\begin{tikzpicture}[start chain=going below,
every node/.style={fill=blue!10, draw=blue!20, on chain, join=by ->},
node distance=1em,
]
\node {here};
\node {are};
\node[reset after command] {some};
\node {nodes};
\end{tikzpicture}
\end{document}
Edit: What if the background is not white? asked by egreg
So I mimic a scenario with a background to verify the logic.
Code
\documentclass[border=0.3cm]{standalone}
\usepackage{tikz}
\usetikzlibrary{chains,backgrounds}
\begin{document}
\begin{tikzpicture}[%
start chain=going below,
every node/.style={%
join,
on grid,
on chain,
draw,
align=center,
},
every join/.style={->,draw}
]
\tikzset{
none/.style={->,cyan,line width=5pt}, % remove line width see the artifact
}
\node (a0) {A0};
\node {B0};
\begin{scope}[every join/.style={->, shorten <=5pt,shorten >=5pt}]
\node [join=by none,right=of a0] (a1) {A1};
\begin{pgfonlayer}{background}
\draw[fill=cyan] (-0.5,-1.5) rectangle (1.5,0.5);
\end{pgfonlayer}
\end{scope}
\node {B1};
\end{tikzpicture}
\end{document}
Here is a possible solution to reverse the default
mentioned in the comment by the OP. The logic behind the solution is to use a scope
environment to reverse the default by drawing a shorter connection line, then draw a thick line with white
color to erase the short line. The erase action is defined by the none
macro.
\begin{scope}[every join/.style={->, shorten <=5pt,shorten >=5pt}]
<node commands>
\end{scope}
none/.style={->,white,line width=5pt}, % remove line width see the artifact
Code
\documentclass[border=0.3cm]{standalone}
\usepackage{tikz}
\usetikzlibrary{chains}
\begin{document}
\begin{tikzpicture}[%
start chain=going below,
every node/.style={%
join,
on grid,
on chain,
draw,
align=center,
},
every join/.style={->,draw}
]
\tikzset{
none/.style={->,white,line width=5pt}, % remove line width see the artifact
}
\node (a0) {A0};
\node {B0};
\begin{scope}[every join/.style={->, shorten <=5pt,shorten >=5pt}]
\node [join=by none,right=of a0] (a1) {A1};
\end{scope}
\node {B1};
\end{tikzpicture}
\end{document}
One way will be to use white color (or similar):
\node [join= by {white,->},right=of a0] (a1) {A1};
Equivalently using your approach:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{chains}
\begin{document}
\begin{tikzpicture}[%
start chain=going below,
every node/.style={%
join,
on grid,
on chain,
draw,
align=center,
},
every join/.style={->,draw}
]
\tikzset{
none/.style={draw=white},
}
\node (a0) {A0};
\node {B0};
\node [join= by {none},right=of a0] (a1) {A1};
\node {B1};
\end{tikzpicture}
\end{document}
which yields
Sigh, the artefacts remain.
Or use the join
option on individual nodes like
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{chains}
\begin{document}
\begin{tikzpicture}[%
start chain=going below,
every node/.style={%
%join,
on grid,
on chain,
draw,
align=center,
},
mynode/.style={%
join
},
every join/.style={->,draw}
]
\node[mynode] (a0) {A0};
\node[mynode] {B0};
\node [right=of a0] (a1) {A1}; %% no join here
\node[mynode] {B1};
\end{tikzpicture}
\end{document}
Instead of defining mynode
, we could have added just join
in every node except those which needn't be joined.