5

Neither ulem nor soul packages allow striking thru a whole row in a tabular environment, eg:

\sout{1,3-Cyclopentadiene    & 161.39    & 148.19    & 155.65    & 153.43    & 154.7     & 5.5  & 118.20} \\

Is there an alternative?

Package xcolor with the table option clashes with package dcolumn so that does not appear to be an option

5 Answers 5

5

As a quick and dirty fix you can superpose a row with a \hline by reducing row spacing before and after the line:

\documentclass{article}
\begin{document}
\begin{tabular}{lll}
aaaaa & bbbbb & ccccc \\
11111 & 22222 & 33333 \\ [-1.5ex]
\hline \\ [-1.5ex]
xxxxx & yyyyy & zzzzz \\
\end{tabular}
\end{document}
1
3

One can use TikZ to do so :

\usepackage{tikz}
\tikzstyle{every picture}+=[remember picture]
\tikzstyle{na} = [shape=rectangle,inner sep=0pt]

\newcommand{\ptStrikeA}[1]{     % Left 'point' to be striked (A)
    \tikz[baseline=(A.base)]\node[na](A){#1};
  }
\newcommand{\ptStrikeB}[1]{     % Right 'point' to be striked (B)
    \tikz[baseline=(B.base)]\node[na](B){#1};
  }  

\newcommand{\strike}{   % Strike from A to B
    \begin{tikzpicture}[overlay]
        \draw (A.west) -- (B.east);
    \end{tikzpicture}
  }

\begin{document}
    \begin{tabular}{lll}
                    aaaaa & bbbbb & ccccc \\
        \ptStrikeA{11111} & 22222 & \ptStrikeB{33333} \\
                    xxxxx & yyyyy & zzzzz \\
    \end{tabular}
    \strike
\end{document}

This way, you can either strike an entire row, or only part of it. Putting the \strike command outside the environment allows you to embed it into beamer overlays.

1

[Extending the answer given by Dorian]

To achieve multiple strikethroughs in a single table, rather than declaring more and more commands, you can specify the start/end points dynamically:

\usepackage{tikz}
\tikzstyle{every picture}+=[remember picture]
\tikzstyle{na} = [shape=rectangle,inner sep=0pt]

% end point for strike
\newcommand{\ptStrike}[2]{    
    \tikz[baseline=(#1.base)]\node[na](#1){#2};
}

% draw strike between two endpoints
\newcommand{\strike}[2]{  
    \begin{tikzpicture}[overlay]
        \draw (#1.west) -- (#2.east);
    \end{tikzpicture}
}

\begin{document}
    \begin{tabular}{lll}
        aaaaa & bbbbb & ccccc \\
        \ptStrike{A}{11111} & 22222 & \ptStrike{B}{33333} \\
        xxxxx & yyyyy & zzzzz \\
        \ptStrike{C}{33333333} & 55555555 & \ptStrike{D}{88888888}\\
    \end{tabular}
    \strike{A}{B} % draw strike from A to B
    \strike{C}{D} % draw strike from C to D
\end{document}
1

[Extending the answer given by @Dorian and @Dixie]

You can take it one step further even and avoid needing to redefine names for beginning and endpoints!

\documentclass{standalone}
\usepackage{tikz}
\tikzstyle{every picture}+=[remember picture]
\tikzstyle{na} = [shape=rectangle,inner sep=0pt]

\newcommand{\myStrikeBegin}[1]{%
    \tikz[baseline=(begin.base)]\node[na](begin){#1};
}

\newcommand{\myStrikeEnd}[1]{%
    \tikz[baseline=(end.base)]\node[na](end){#1};
    \begin{tikzpicture}[overlay]
          \draw (begin.north west) -- (end.south east);
    \end{tikzpicture}
}

\begin{document}
    \begin{tabular}{lll}
        aaaaa & bbbbb & ccccc \\
        \myStrikeBegin{11111} & 22222 & \myStrikeEnd{33333} \\
        xxxxx & yyyyy & zzzzz \\
        \myStrikeBegin{33333333} & 55555555 & \myStrikeEnd{88888888} \\
    \end{tabular}
\end{document}

compiled sample

2
  • Please, can you edit your answer? Missing \documentclass. Thank you.
    – Sebastiano
    May 3, 2019 at 11:40
  • @Sebastiano didn't know it was necessary, I guess it is easier to copy it now
    – Pinna_be
    May 3, 2019 at 12:44
1

With {NiceTabular} of nicematrix, you can easily strike a row with TikZ by using the nodes created by nicematrix.

\documentclass{article}
\usepackage{nicematrix,tikz}

\begin{document}

\begin{NiceTabular}{lll}[hvlines]
    aaaaa & bbbbb & ccccc \\
    11111 & 22222 & 33333 \\
    xxxxx & yyyyy & zzzzz \\
    33333333 & 55555555 & 88888888 \\
\CodeAfter
   \tikz \draw [red] (2.5-|1) -- (2.5-|last) ; 
   \tikz \draw [thick,red] ([yshift=-4pt]4-|1) -- ([yshift=4pt]5-|last) ; 
\end{NiceTabular}

\end{document}

Output of the above code

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .