7

Is there a possibility to create frames for tabulars, that go beyond a simple line?

\begin{tabular}{|l|l|}
\hline
A & B\\
\hline
C & D\\
\hline
\end{tabular}

creates lines as a "frame", but these are indistinguishable from the lines that separate the rows and columns. I would like to have, for example thick lines for the frame. Or double lines that look good and not like the one I create like this

\begin{tabular}{||l|l||}
\hline \hline
A & B\\
\hline
C & D\\
\hline \hline
\end{tabular}

Any ideas?

David Carlisle
  • 757,742
Haatschii
  • 700

4 Answers4

11

Perhaps tikz can help here

screenshot

Of course, because it's tikz, you can get much more adventurous with your affects if you want to.

\documentclass{article}

\usepackage{tikz}

\begin{document}

\tikz\node[draw=red,thick,double,inner sep=1pt]{
\begin{tabular}{l|l}
A & B\\
\hline
C & D\\
\end{tabular}};

\end{document}

If you'd like to apply the idea to every tabular, then you could use the etoolbox, perhaps something like the following- note the gradient shading :)

enter image description here

\documentclass{article}

\usepackage{tikz}
\usepackage{etoolbox}

\BeforeBeginEnvironment{tabular}{\tikzpicture\node[draw=red,thick,double,inner sep=1pt,top color=blue,bottom color=yellow]\bgroup}
\AfterEndEnvironment{tabular}{\egroup;\endtikzpicture}

\begin{document}

\begin{tabular}{l|l}
  A & B\\
  \hline
  C & D\\
\end{tabular}

\end{document}

Perhaps you'd like rounded corners

\BeforeBeginEnvironment{tabular}{\tikzpicture\node[rounded corners=3pt,draw=red,thick,double,inner sep=1pt,top color=blue,bottom color=yellow]\bgroup}

enter image description here

You could even go completely crazy and surround the tabular in a circle or a star, but I'll leave that up to you :)

The possibilities are limited only by imagination- have fun, and check out the manual for more ideas and options.

David Carlisle
  • 757,742
cmhughes
  • 100,947
  • Thanks, I got some nice frames from your examples. Although I dont think, that I need color at all in my tables! ;) – Haatschii Nov 26 '12 at 03:07
  • @Haatschii you're very welcome :) glad it helped! – cmhughes Nov 26 '12 at 03:14
  • With inner sep=.3pt+\pgflinewidth, .3pt being the half of double distance (initially .6pt), the outer lines just touch tabular's lines instead of drawing over them. – Qrrbrbirlbel Nov 26 '12 at 03:30
9

You could be interested in the features provided by the tabu package: a simple example:

\documentclass{article}
\usepackage{xcolor}
\usepackage{tabu}

\begin{document}

{\arrayrulewidth=3pt
\begin {tabu}{|[5pt cyan!60!black]c|[5pt red!60!black] c|[5pt cyan!60!black]}
\taburulecolor{orange}
\hline
A & B \\
\hline
C & D \\
\hline
\end {tabu}
}

\end{document}

enter image description here

Moriambar
  • 11,466
Gonzalo Medina
  • 505,128
6

Besides the TikZ solution where you can create very interesting  tables, there is the hhline package which is suited for just  tables.

Code

\documentclass{article}
\usepackage{hhline}
\begin{document}
\begin{tabular}{||l|l||}
    \hhline{#==#}
    A & B \\ \hhline{|--|}
    C & D \\ \hhline{#==#}
\end{tabular}

\begin{tabular}{||l|l||}
    \hhline{|t:==:t|}
    A & B \\ \hhline{||--||}
    C & D \\ \hhline{|b:==:b|}
\end{tabular}
\end{document}

Output

enter image description here

Qrrbrbirlbel
  • 119,821
4

Have a look at the booktabs package on some guidelines for creating good looking tables. In general, it is not a good idea to use vertical lines in tables. The booktabs package also provides \toprule, \midrule and \bottomrule commands for rules of different thickness.

\documentclass[margin=3mm]{standalone}

\usepackage{booktabs}

\begin{document}
\begin{tabular}{ll}
\toprule
A & B \\
\midrule
C & D \\
E & F \\
\bottomrule
\end{tabular}
\end{document}

enter image description here

Aditya
  • 62,301
  • I know booktabs and use it most of the time. However in this case I am creating some kind of form sheet, that has to be filled out in printed form by other people. So I really want the vertical lines to make clear where to write. I don't think booktabs helps here. – Haatschii Nov 26 '12 at 03:00