I'm drawing a lattice of nodes and I would like to highlight certain paths with different colors. When the paths overlap, I would like the colors to appear adjacent to each other. I've seen solutions on this site for when the nodes appear either only vertically or only horizontally displaced from one another. My situation, for which I haven't found an answer yet, is one where the nodes are offset by some nonzero slope.
I can kind of achieve the effect I want. But, I'm not entirely happy with my solution to this. It requires a bit too much tinkering on my part.
To duplicate what I've done, I'd like something to transform canvas orthogonally to some path. (Or perhaps there's another approach I'm unaware of.)
Here's my attempt at this,
Here's my code for this:
\documentclass[border=3pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc}
\def\aev{\dimexpr12pt+0.65cm}
\def\aeh{\dimexpr12pt+1.00cm}
\newcommand\aes[2]{\scalebox{\ifcase#1\or1.00\or0.90\or0.80\or0.70\fi}{#2}}
\begin{document}
\begin{tikzpicture}[
aec/.style={circle,draw,inner sep=1pt,minimum size=0.80cm},
ae transform top/.style={transform canvas={yshift= 1.3pt,xshift= 0.3pt}},
ae transform bot/.style={transform canvas={yshift=-1.3pt,xshift=-0.3pt}},
]
%% ------------------------------------------------------------
%% a bit of a work around for several issues
%% the primary one here is how "transformed" path connect
%% at the nodes
%% ------------------------------------------------------------
\coordinate (cA) at (0,0);
\coordinate (cB) at ($(cA.south)+(0,-\aev)$);
\coordinate (cC) at ($(cB.south)+(0,-\aev)$);
\coordinate (cD) at ($(cC.south)+(0,-\aev)$);
\coordinate (cAB) at ($($(cA.south)!0.5!(cB.north)$)+(\aeh,0pt)$);
\coordinate (cBC) at ($($(cB.south)!0.5!(cC.north)$)+(\aeh,0pt)$);
\coordinate (cCD) at ($($(cC.south)!0.5!(cD.north)$)+(\aeh,0pt)$);
\coordinate (cABC) at ($($(cAB.south)!0.5!(cBC.north)$)+(\aeh,0pt)$);
\coordinate (cBCD) at ($($(cBC.south)!0.5!(cCD.north)$)+(\aeh,0pt)$);
\coordinate (cABCD) at ($($(cABC.south)!0.5!(cBCD.north)$)+(\aeh,0pt)$);
\node[aec] (A) at (cA) {A};
\node[aec] (B) at (cB) {B};
\node[aec] (C) at (cC) {C};
\node[aec] (D) at (cD) {D};
\node[aec] (AB) at (cAB) {\aes{2}{AB}};
\node[aec] (BC) at (cBC) {\aes{2}{BC}};
\node[aec] (CD) at (cCD) {\aes{2}{CD}};
\node[aec] (BCD) at (cBCD) {\aes{3}{BCD}};
\draw (AB) -- (A);
\draw (AB) -- (B);
\draw (BC) -- (B);
\draw (BC) -- (C);
\draw (CD) -- (C);
\draw (CD) -- (D);
%\draw (ABC) -- (AB);
%\draw (ABC) -- (BC);
\draw (BCD) -- (BC);
\draw (BCD) -- (CD);
%\draw (ABCD) -- (ABC);
%\draw (ABCD) -- (BCD);
%% ------------------------------------------------------------
%% Using my "coordinate" construct work around to make the
%% lines connecting nodes look more "beautiful
%% ------------------------------------------------------------
\draw[ red,line width=3pt] (cABC) -- (BC);
\draw[green,line width=3pt] (cABC) -- (AB) -- (B);
\draw[green,line width=3pt,ae transform top] (cABCD) -- (cABC);
\draw[ red,line width=3pt,ae transform bot] (cABCD) -- (cABC);
%% ------------------------------------------------------------
%% Using a more pure "node" approach to this, but the
%% transformed colored paths don't connect to the nodes very
%% beautifully and I'm not happy with that.
%% ------------------------------------------------------------
\node[aec,fill=white] (ABC) at (cABC) {\aes{3}{ABC}};
\node[aec,fill=white] (ABCD) at (cABCD) {\aes{4}{ABCD}};
\draw[ blue,line width=3pt] (ABCD) -- (BCD) -- (BC);
\draw[ red,line width=3pt,ae transform top] (BC) -- (B);
\draw[blue,line width=3pt,ae transform bot] (BC) -- (B);
\end{tikzpicture}
\end{document}
So, there are two issues I'd like fixed.
The most important of the two is how to more easily transform canvas or use some other technique to color the same essential path in parallel (with up to three colors potentially used for the same path).
Of secondary interest (since I already have a bit of a work-around) is: once I've got the path colored as I would like (point 1), how can I make the connection with the nodes more beautiful.
Regarding the second point, you can see the appearance created by my work around between nodes ABCD
and ABC
.
You can see the ugly connect created by not using my work-around between the nodes BC
and B
.