# Rules of column width in tabular

I would like to put rules in a tabular to "strike out" a number of consecutive cells within one row. I want these rules to automatically adjust to column width.

For example, the width of the first column is determined by foobar, the width of the second column is determined by barbarbar, and the width of the third column is determined by foo. The width of the first rule is \widthof{barbarbar}+2\tabcolsep+\widthof{foo} and the width of the second rule is \widthof{foo}.

The tabular above is generated by the following code:

\documentclass{standalone}
\usepackage{calc}
\begin{document}

\begin{tabular}{ l l l }
foo & bar & foo  \\
foobar & barbarbar \\
bar & \multicolumn{2}{l}{\rule[0.5ex]{\widthof{barbarbar}+2\tabcolsep+\widthof{foo}}{0.5pt}} \\
bar & foo & \rule[0.5ex]{\widthof{foo}}{0.5pt} \\
\end{tabular}

\end{document}


I'm interested in how to automatically get the widths of columns and use them within the same tabular to set the width of the rules so that they don't have to be manually specified as \widthof{barbarbar}+2\tabcolsep+\widthof{foo} and \widthof{foo}. Thus, if I change foo in the last column to foofoo, I want the width of the rules to automatically adjust:

.

• Probably \hrulefilldoes what you want to achieve? Jul 12 '20 at 15:33
• what about tikz solution Jul 12 '20 at 16:12

Next to your original code, here are two versions using either \hrulefill or \xhfill from the xhfill package:

\documentclass{standalone}
\usepackage{calc}
\usepackage{xhfill} % provides the \xrfill command used in the third example
\begin{document}

\begin{tabular}{ l l l }
foo & bar & foo  \\
foobar & barbarbar \\
bar & \multicolumn{2}{l}{\rule[0.5ex]{\widthof{barbarbar}+2\tabcolsep+\widthof{foo}}{0.5pt}} \\
bar & foo & \rule[0.5ex]{\widthof{foo}}{0.5pt} \\
\end{tabular}

\begin{tabular}{ l l l }
foo & bar & foo  \\
foobar & barbarbar \\
bar & \multicolumn{2}{l}{\hrulefill} \\
bar & foo & \hrulefill \\
\end{tabular}

\begin{tabular}{ l l l }
foo & bar & foo  \\
foobar & barbarbar \\
bar & \multicolumn{2}{l}{\xrfill[0.75ex]{0.2pt}} \\
bar & foo & \xrfill[0.75ex]{0.2pt} \\
\end{tabular}

\end{document}