Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I have a tabular with and use tikz to create a frame around it. Right now it looks like this:

\documentclass{scrartcl}
\usepackage{tikz}
\begin{document}
\tikz\node[draw=black,ultra thick,double=gray,inner sep=.3pt+\pgflinewidth]{
\begin{tabular}{l|l}
A & B\\
\hline
C & D\\
\end{tabular}};
\end{document}

For some very simple 3d effect I want to seperatly adjust the colour of the frame parts. For example in the top and right part of the frame the outer line in black and the inner line in gray. And in the left and bottom part the outher way round.

EDIT: I did a minimal example in HTML/CSS:

enter image description here

To get the desired effect I need the edges to be in an angle of 45°.

share|improve this question
1  
looks familiar :) could you turn your snippet into a complete MWE so that others can play with it easily? :) –  cmhughes Nov 26 '12 at 20:49
    
definitely not an answer, but might get you started: \usetikzlibrary{fadings} and then \tikz\node[draw=black,ultra thick,double=gray,inner sep=.3pt+\pgflinewidth] [postaction={path fading=south,fill=white}] {\begin{tabular}{l|l} ... produces some effects- it's not quite what you've described though –  cmhughes Nov 26 '12 at 22:43
    
@cmhughes: yea, its pretty much a follow up question to your answer (tex.stackexchange.com/a/84258/15061). I hope I extened my code to be a MWE. Also I did an html example of what I am looking for. –  Haatschii Nov 27 '12 at 14:18
    
I took the liberty of converting your example image to .png format and uploading it here; I hope it's OK. –  Gonzalo Medina Nov 27 '12 at 15:34
    
@GonzaloMedina Sure, good idea. –  Haatschii Nov 28 '12 at 13:27
add comment

2 Answers

up vote 10 down vote accepted

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}

enter image description here

share|improve this answer
    
Thanks, it is pretty much, what I was looking for, exepct for the edges that should be in an angle of 45°. I added an example in my question. –  Haatschii Nov 27 '12 at 14:21
    
@Haatschii answer updated with the 45 degree angle. –  Gonzalo Medina Nov 27 '12 at 15:10
    
Great, thank you so much. I think I have to spend some time reading the tikz manual to understand what you are doing, though. But for now this is exactly what I wanted. –  Haatschii Nov 28 '12 at 13:26
add comment

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}

enter image description here

You can add another layer with the contrast colors to get the 3D effect.

share|improve this answer
    
Thanks a lot. Your example also works well. It always this problem that I can only accept one answer. :/ –  Haatschii Nov 28 '12 at 13:27
    
@Haatschii No problem at all. –  percusse Nov 28 '12 at 13:43
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.