# How to trim horizontal line ends in table with vertical lines?

How to obtain something like this ?

The only way for trimming horizontal line in table that I found is using booktabs. The problem with booktabs is that it doesn't manage good vertical lines.

I tried this code:

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{xcolor}
\usepackage{colortbl}
\usepackage{booktabs}

\begin{document}

\arrayrulecolor{gray}
\begin{tabular}{!{\color{gray}\vline}ll!{\color{gray}\vline}}
a & b \\
c & d \\
\cmidrule(rl){1-2}
e & f
\end{tabular}

\end{document}


But it leads to this results:

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{xcolor}
\usepackage{colortbl}

\begin{document}

\arrayrulecolor{red}
\begin{tabular}{|ll|}
a & b \\
c & d \\
e & f
\end{tabular}

\end{document}

• @Robbo \multicolumn/\multispan and friends have to expand to a sequence of tokens starting with \omit as TeX uses a special pre-scan to see if it should or should not start a normal table cell. You can have nothing before \omit not even \relax (which does nothing). The machinery used for testing if there is an optional argument does not work purely by expansion. – David Carlisle Jan 9 '14 at 12:52

Here's a way using scalerel's \stretchleftright macro:

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{xcolor}
\usepackage{booktabs}
\usepackage{colortbl}
\usepackage{scalerel}
\begin{document}
\arrayrulecolor{gray}
\stretchleftright{\color{gray}|}{%
\begin{tabular}{ll}
a & b \\
c & d \\
\cmidrule(rl){1-2}
e & f
\end{tabular}%
}{\color{gray}|}
\end{document}