Different colours for tikz node frame sides
Here's a possible solution; the \myboxed
command surround its contents with a frame having the requested specifications; the syntax is:
\myboxed[<length>][<color1>][<color2>]{<contents>}
<length>
controls the width of the frame (default=2pt
); using the second and third optional arguments you can change the colors used (defaults=black
and gray
):
\documentclass{article}
\usepackage{xparse}
\usepackage{tikz}
\newlength\unit
\NewDocumentCommand\myboxed{O{2pt}O{black}O{gray}m}{%
\setlength\unit{#1}
\begin{tikzpicture}
\node[inner sep=0pt] (a) {#4};
\fill[#2] (a.south east) --
([xshift=\unit,yshift=-\unit]a.south east) |-
([xshift=-\unit,yshift=\unit]a.north west) --
(a.north west) -|
(a.south east) --
cycle;
\fill[#3] (a.south east) --
([xshift=\unit,yshift=-\unit]a.south east) -|
([xshift=-\unit,yshift=\unit]a.north west) --
(a.north west) |-
(a.south east) --
cycle;
\fill[#3] ([xshift=\unit,yshift=-\unit]a.south east) --
([xshift=2*\unit,yshift=-2*\unit]a.south east) |-
([xshift=-2*\unit,yshift=2*\unit]a.north west) --
([xshift=-\unit,yshift=\unit]a.north west) -|
([xshift=\unit,yshift=\unit]a.south east) --
cycle;
\fill[#2] ([xshift=\unit,yshift=-\unit]a.south east) --
([xshift=2*\unit,yshift=-2*\unit]a.south east) -|
([xshift=-2*\unit,yshift=2*\unit]a.north west) --
([xshift=-\unit,yshift=\unit]a.north west) |-
([xshift=-\unit,yshift=-\unit]a.south east) --
cycle;
\end{tikzpicture}
}
\begin{document}
\myboxed{\begin{tabular}{l|l}
A & B \\
\hline
C & D \\
\end{tabular}}\quad
\myboxed[4pt]{\begin{tabular}{l|l|l}
A & B & C \\
\hline
C & D & E \\
\hline
F & G & H \\
\end{tabular}}\quad
\myboxed[6pt][black!80][gray!50]{\begin{tabular}{l|l|l}
A & B & C \\
\hline
C & D & E \\
\hline
F & G & H \\
\end{tabular}}
\end{document}
In Tikz it's not that straightforward to get angled linecaps (see TikZ: changing colour of a path half way along )so one needs to draw the extra bit manually either as a full rectangular path or just playing around with the tip (with a new arrow probably. See Luigi's wonders in Is it possible to change the size of an arrowhead in TikZ/PGF? )
Here is the simplest that I can think of
\documentclass[tikz]{standalone}
\newcommand\htmlbutton[4]{
\foreach \x/\z/\y in {|-/-|/#3,-|/|-/#4}{
\fill[fill=\y,line join=bevel] ([shift={(135:#2)}]#1.north west) \x
([shift={(-45:#2)}]#1.south east) -- (#1.south east) \z
(#1.north west)--cycle;
}
}
\begin{document}
\begin{tikzpicture}
\node[outer sep=0,inner sep=1pt] (a) {Test test};
\htmlbutton{a}{2pt}{gray}{gray!40}
\end{tikzpicture}
\end{document}
You can add another layer with the contrast colors to get the 3D effect.