4

How to obtain something like this ?

enter image description here

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: enter image description here

5

enter image description here

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


\begin{document}

\arrayrulecolor{red}
\begin{tabular}{|ll|}
  a & b \\
  c & d \\
\multispan{2}{\color{red}\vline\hspace*{.5em}\leaders \hrule height\arrayrulewidth\hskip\fill\hspace*{.5em}\vline}\\
  e & f
\end{tabular}

\end{document}
  • Why if I put your code in a \newcommand with options like this: \newcommand{\htrimmedline}[1][2]{\multispan{#1}{\color{gray!40}\hspace*{.2em}\vline\hspace{.2em}\leaders \hrule height\arrayrulewidth\hskip\fill\hspace*{.2em}\vline\hspace{.2em}}\\} when I compile I get the error Misplaced omit, while if I put it in a newcommand without optional argument like this: \newcommand{\htrimmedline}[1]{\multispan{#1}{\color{gray!40}\hspace*{.2em}\vline\hspace{.2em}\leaders \hrule height\arrayrulewidth\hskip\fill\hspace*{.2em}\vline\hspace{.2em}}\\}, it works? – Robbo Jan 9 '14 at 12:34
  • 1
    @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
2

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}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.