# Top aligned tabular: \cline equivalent of \firsthline

When aligning tabular environments with the [t] option, one can use \firsthline (from the array package) instead of \hline when a line is required at the top of the table. Like so:

\documentclass{article}
\usepackage{array}

\begin{document}
Tabular with hline:
\begin{tabular}[t]{ll}
\hline A & B \\ C & D \\ \hline
\end{tabular}
and with firsthline:
\begin{tabular}[t]{ll}
\firsthline A & B \\ C & D \\ \lasthline
\end{tabular}


But what if I want only some cells of the first line to have a line above them, like this:

Tabular with cline:
\begin{tabular}[t]{ll}
\cline{2-2} A & B \\ C & D \\ \hline
\end{tabular}
and what it should look like:
\raisebox{.8em}{
\begin{tabular}[t]{ll}
\cline{2-2} A & B \\ C & D \\ \hline
\end{tabular}
}
\end{document}


And the compiled result:

Is there any easy way to achieve this effect without manually tweaking the vertical offset with \raisebox?

-

You can define a command \firscline similar to \firsthline but using \cline instead of \hline:

\documentclass{article}
\usepackage{array}

\makeatletter
\newcommand{\firstcline}[1]{%
\multicolumn1c{%
\global\backup@length\ht\@arstrutbox
\raise\extratabsurround\copy\@arstrutbox
}\\[-\backup@length]\cline{#1}
}
\makeatother

\begin{document}
Tabular with \verb+\hline+:
\begin{tabular}[t]{ll}
\hline A & B \\ C & D \\ \hline
\end{tabular}
and with \verb+\firstcline+:
\begin{tabular}[t]{ll}
\firstcline{1-1} A & B \\ C & D \\ \lasthline
\end{tabular}
\begin{tabular}[t]{ll}
\firstcline{2-2} A & B \\ C & D \\ \lasthline
\end{tabular}

\end{document}


-
Wow, that's a whole lot of @s in there. I think that definition would make a sensible addition to the array package. –  Fritz Mar 8 '13 at 19:12