One way would be to add a stage at the start of the arrows that goes horizontally for a bit:
\draw[-latex] (A.east) -- ++(1,0) |- (B.west);
(adjust the 1
to get the length you want).
This does mean that the first part of the line would get drawn 4 times. It may not show (I don't know). To avoid that, you could draw it only the once; thus the later lines would be:
\draw[-latex] (A.east) ++(1,0) |- (C.west);
An alternative would be to put a coordinate
node at that point:
\draw (A.east) -- ++(1,0) coordinate (div);
\draw[-latex] (div) |- (B.west);
\draw[-latex] (div) |- (C.west);
Update:
Here is a better solution, but this has an issue, in that the three sided
node lines can be any color you want as long its black :-). The three sided
style defined here is based loosely on How to modify nodes in TikZ to automatically add a line on their top?. The corrected node on the right here was drawn as:
\node [three sided ] (1) at (0, 0) { $1$ };
\node [draw=red, draw opacity=0.5] (2) at (0.5,0) { $2$ };
Further Enhancements:
- Allow for other line colors for the
three sided
node.
Code:
\documentclass{article}
\usepackage{tikz}
\tikzset{three sided/.style={
draw=none,
append after command={
[shorten <= -0.5\pgflinewidth]
([shift={(-1.5\pgflinewidth,-0.5\pgflinewidth)}]\tikzlastnode.north east)
edge([shift={( 0.5\pgflinewidth,-0.5\pgflinewidth)}]\tikzlastnode.north west)
([shift={( 0.5\pgflinewidth,-0.5\pgflinewidth)}]\tikzlastnode.north west)
edge([shift={( 0.5\pgflinewidth,+0.5\pgflinewidth)}]\tikzlastnode.south west)
([shift={( 0.5\pgflinewidth,+0.5\pgflinewidth)}]\tikzlastnode.south west)
edge([shift={(-1.0\pgflinewidth,+0.5\pgflinewidth)}]\tikzlastnode.south east)
}
}
}
\begin{document}
\begin{tikzpicture}[thick, inner sep=0pt, minimum size=0.5cm]
\node [style={draw}] (1) at (0, 0) { $1$ };
\node [style={draw=red, draw opacity=0.5}] (2) at (0.5,0) { $2$ };
\end{tikzpicture}
%
\begin{tikzpicture}[thick, inner sep=0pt, minimum size=0.5cm]
\node [three sided ] (1) at (0, 0) { $1$ };
\node [draw=red, draw opacity=0.5] (2) at (0.5,0) { $2$ };
\end{tikzpicture}
\end{document}
You example did not really illustrate the issue, so I have adapted it to more clearly illustrate the issue, and also allows you to see that it is not duplicated in the second version. The two on the left show the problem, and the two on the right should be the desired result:
Note:
- This is a very manual solution that requires one to use
draw=none
for the node, followed by a call to \DrawNode
to do the actual drawing. There must be some magic postaction
that can be applied to have the same effect which woudl simply the usage.
- Also, I am not sure why you had
style={}
with the node options.
Code:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc}
\newcommand{\DrawNode}[2][]{%
\draw [#1]
([shift={(-\pgflinewidth,-0.5\pgflinewidth)}]#2.north east) --
([shift={(0.5\pgflinewidth,-0.5\pgflinewidth)}]#2.north west) --
([shift={(0.5\pgflinewidth,+0.5\pgflinewidth)}]#2.south west) --
([shift={(-\pgflinewidth,+0.5\pgflinewidth)}]#2.south east)
;
}%
\begin{document}
\begin{tikzpicture}[thick]
\node [style={draw, densely dotted, inner sep=0pt, minimum size=0.5cm}] (1) at (0, 0) { $1$ };
\node [style={draw=red, draw opacity=0.5, inner sep=0pt, minimum size=0.5cm}] (2) at (0.5,0) { $2$ };
\end{tikzpicture}
%
\begin{tikzpicture}[thick]
\node [draw=none, inner sep=0pt, minimum size=0.5cm] (1) at (0, 0) { $1$ };
\DrawNode[densely dotted]{1}
\node [draw=red, draw opacity=0.5, inner sep=0pt, minimum size=0.5cm] (2) at (0.5,0) { $2$ };
\end{tikzpicture}
\begin{tikzpicture}[thick]
\node [style={draw, inner sep=0pt, minimum size=0.5cm}] (1) at (0, 0) { $1$ };
\node [style={draw=red, draw opacity=0.5, inner sep=0pt, minimum size=0.5cm}] (2) at (0.5,0) { $2$ };
\end{tikzpicture}
%
\begin{tikzpicture}[thick]
\node [draw=none, inner sep=0pt, minimum size=0.5cm] (1) at (0, 0) { $1$ };
\DrawNode{1}
\node [draw=red, draw opacity=0.5, inner sep=0pt, minimum size=0.5cm] (2) at (0.5,0) { $2$ };
\end{tikzpicture}
\end{document}
Best Answer
Problems 1) and 3): you can control the alignment using the
mid
anchor of nodes. Problem 2): you can use the optional argument of the line changing command\\
; here's a modified version of your code, feel free to change the lengths according to your needs: