0

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.

enter image description here

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:

enter image description here.

Thanks for your help!

2
  • Probably \hrulefilldoes what you want to achieve?
    – leandriis
    Jul 12 '20 at 15:33
  • what about tikz solution
    – js bibra
    Jul 12 '20 at 16:12
1

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

enter image description here

\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}

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.