9

I want to have a node with different border colors: One for the upper and left border, one for the lower and right color.

Is this possible? From all examples I found, it seems that I can only set the color as a whole, not for each side.

alper
  • 1,389
flyx
  • 2,051

1 Answers1

8

This should get you started. More polishing can be done, but left as an exercise.

\documentclass{article}
\usepackage{tikz}
\tikzset{%
pics/.cd,
mynode/.style args={#1#2#3}{
  code={\node (a) {#3};
       \draw[thick,#1] (a.south west) |- (a.north east);
       \draw[thick,#2] (a.south west) -| (a.north east);
  }
},
}
\begin{document}
  \begin{tikzpicture}
    \pic {mynode={red}{blue}{Here}};
    \pic at (4,0) {mynode={olive}{magenta}{Here comes another one}};
  \end{tikzpicture}
\end{document}

enter image description here

\documentclass{article}
\usepackage{tikz}
\tikzset{%
pics/.cd,
mynode/.style args={#1#2#3}{
  code={\node (a) {#3};
       \draw[thick,#1,line cap=butt,shorten <= -0.5\pgflinewidth,shorten >= 0.5\pgflinewidth] (a.south west) |- (a.north east);
       \draw[thick,#2,line cap=butt,shorten <= 0.5\pgflinewidth,shorten >= -0.5\pgflinewidth] (a.south west) -| (a.north east);
  }
},
}
\begin{document}
  \begin{tikzpicture}
    \pic {mynode={red}{blue}{Here}};
    \pic at (4,0) {mynode={olive}{magenta}{Here comes another one}};
  \end{tikzpicture}
\end{document}

enter image description here

  • Thanks! I'm not sure what to do about the ugly corners where the colors meet, but I'll try to fix that myself. – flyx Sep 07 '14 at 12:46
  • @flyx I have added one option for it. –  Sep 07 '14 at 13:00
  • Your code may be correct mathematically, but it produces a small gap between the lines when I render it. I could use a factor slightly smaller than 0.5, but the gap has a different width depending on the zoom level, so this is not the solution. I need a way to actually connect the lines with each other. – flyx Sep 09 '14 at 18:44