I am trying to draw relational database tables with tabular
. I would like to label each table with a label at the top left of the table. Neither solution that comes to my mind is exactly what I want.
I would like a rectangular label with the following properties:
- Border width is same as that of table
- Left border aligns with left border of table
- Bottom border overlaps top border of table
- Width is less than column width of table
In the first solution, I use Tikz
and try to draw the label as a rectangular node. I can never quite get the bottom border of the label to overlap the top border of the table. Nor can I get the left border to align with that of the table.
In the second solution, I use multicolumn
. This comes very close, the only problem remaining is the width.
\documentclass[a4paper]{article}
\usepackage{tikz}
\usetikzlibrary{calc, positioning}
\begin{document}
\begin{tikzpicture}
\node (A) {
\begin{tabular}{|l|l|l|||l|}
\hline
$\texttt{o\_orderkey}$ & $\texttt{o\_orderdate}$ & $\texttt{o\_custkey}$ & rest \\
\hline
0 & 1992-01-01 & 100 & A \\
1 & 1992-01-15 & 3 & B \\
200 & 1993-01-01 & 26 & C \\
201 & 1993-01-15 & 42 & D \\
300 & 1994-01-01 & 88 & E \\
301 & 1994-01-01 & 74 & F \\
\hline
\end{tabular}
};
\node[draw, anchor=south west, inner sep=2pt] at (A.north west) {Table};
\end{tikzpicture}
\begin{tabular}{|l|l|l|||l|}
\cline{1-1} \multicolumn{1}{|l|}{Label} \\
\hline
$\texttt{o\_orderkey}$ & $\texttt{o\_orderdate}$ & $\texttt{o\_custkey}$ & rest \\
\hline
0 & 1992-01-01 & 100 & A \\
1 & 1992-01-15 & 3 & B \\
200 & 1993-01-01 & 26 & C \\
201 & 1993-01-15 & 42 & D \\
300 & 1994-01-01 & 88 & E \\
301 & 1994-01-01 & 74 & F \\
\hline
\end{tabular}
\end{document}
booktabs
and a simpleTable
that is left justified just as the first column:\documentclass{article} \usepackage{booktabs} \begin{document} \begin{tabular}{*5l} Table \\\toprule $\texttt{o\_orderkey}$ & $\texttt{o\_orderdate}$ & $\texttt{o\_custkey}$ & rest \\ \midrule 0 & 1992-01-01 & 100 & A \\ 1 & 1992-01-15 & 3 & B \\ 200 & 1993-01-01 & 26 & C \\ 201 & 1993-01-15 & 42 & D \\ 300 & 1994-01-01 & 88 & E \\ 301 & 1994-01-01 & 74 & F \\ \bottomrule \end{tabular} \end{document}
?