通常,表格采用较多的是标题的方式,有时,对表格制作一个显示标签,以标示表格的主题内容,如下图所示: tablelabel 代码实现一,采用tikz绘制的方式实现:

\documentclass[a4paper]{article}

\usepackage{tikz}
\usetikzlibrary{calc, positioning}

\begin{document}

\begin{tikzpicture}

\node[anchor=north west,inner sep=0pt,outer sep=0pt] (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,text depth=0.5ex, inner ysep=2pt,inner xsep=\tabcolsep,outer sep=0pt] at ([yshift=-0.5\pgflinewidth]A.north west) {Table};

\end{tikzpicture}

\begin{tabular}{|l|l|l|l|||l|}
\cline{1-1} Label \\
\hline
\multicolumn{2}{|l|}{$\texttt{o\_orderkey}$} & $\texttt{o\_orderdate}$ & $\texttt{o\_custkey}$ & rest \\
\hline
\multicolumn{2}{|l|}{0} & 1992-01-01   & 100 & A \\
\multicolumn{2}{|l|}{1} & 1992-01-15   & 3 & B \\
\multicolumn{2}{|l|}{200} & 1993-01-01 & 26 & C \\
\multicolumn{2}{|l|}{201} & 1993-01-15 & 42 & D \\
\multicolumn{2}{|l|}{300} & 1994-01-01 & 88 & E \\
\multicolumn{2}{|l|}{301} & 1994-01-01 & 74 & F \\
\hline
\end{tabular}

\end{document}
代码实现二,采用caption包定义其caption的样式,代码如下:
\documentclass[a4paper]{article}
\usepackage{amsmath}
\usepackage{caption}
\DeclareCaptionFormat{mine}{\setlength\fboxsep{0pt}\hskip-0.5\arrayrulewidth\fbox{\space#3\space}}

\begin{document}

\begin{table}
\captionsetup{singlelinecheck = false, format = mine, skip =-\arrayrulewidth}
 \caption{Label}
\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}
\end{table}

\end{document}
另外,可以利用表格的单元格来实现其他标签:
\documentclass[a4paper]{article}
\usepackage{booktabs,xparse}

\DeclareExpandableDocumentCommand{\tablelabel}{O{1}m}{%
  \multicolumn{#1}{@{}l@{}}{%
    \setlength{\fboxsep}{0pt}%
    \setlength{\fboxrule}{\arrayrulewidth}%
    \fbox{\hspace{\tabcolsep}\strut#2\hspace{\tabcolsep}}%
  }\\[-\arrayrulewidth]
}

\begin{document}

\begin{tabular}{llll}
\tablelabel[4]{Label}
\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}
选自:http://tex.stackexchange.com/questions/196331/fancy-labels-for-tables  

点赞(0)

评论列表 共有 0 条评论

暂无评论
立即
投稿

微信公众账号

微信扫一扫加关注

发表
评论
返回
顶部