2

Related to Make first row of table all bold, however the solution seems not to be transferable to striking text through (see Strikethrough command that affects all following text, like \bfseries).

So far my solution works by overlaying the respective line with

\renewcommand{\sttableline}{\rlap{\rule[3pt]{1\paperwidth}{.4pt}}}

through a command in the spirit of my first referenced Q&A above. This is however very unflexible and needs manual adjustment depending on how the respective table is scaled/placed on the page.

Edit: Idealy the solution I'm looking for would work withou any modification in the last columns and only need modification of the table header and entries in the first columns.

sheß
  • 3,622
  • The two solution that were already provided answer my original question. However what I am looking for is slightly different. So I've added that I'd prefer a solution that works without modifying adding (something inside) an additional last column. The reason is that the table content is generated by another software. – sheß Sep 04 '15 at 12:07

4 Answers4

5

While someone else provides a better answer, you can always use a tikzmark

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{tikzmark}

\begin{document}
\begin{tabular}{lcr}
a & a & a \\
\tikzmark{start}b & b & b\tikzmark{end} \\
c & c & c \\
\end{tabular}

\tikz[remember picture] \draw[overlay] ([yshift=.35em]pic cs:start) -- ([yshift=.35em]pic cs:end);
\end{document}

enter image description here

Ignasi
  • 136,588
1

Something like this might be workable. There is a slight difference in approach from the cited answer of the OP. That is, a phantom column must be added at the end of the row (the added space of it is compensated for with a @{\hspace{-\tabcolsep}} as is shown in my MWE with an \fbox around the tabular).

An alternative to the phantom column is to add \relax prior to \\ at the end of each tab row.

\documentclass{article}
\usepackage{array}
\newcolumntype{$}{>{\global\let\currentrowstyle\relax}}
\newcolumntype{^}{>{\relax\currentrowstyle}}
\newcommand{\rowstyle}[1]{\gdef\currentrowstyle{#1}%
  #1\ignorespaces%
}
\def\mystyle#1\relax{\setbox0=\hbox{#1}\rule[2pt]{\wd0}{1pt}\kern-\wd0#1}
\begin{document}
\fbox{\begin{tabular}{$l^c^r^c@{\hspace{-\tabcolsep}}}
\rowstyle{\mystyle}
This is an entry & another entry & a third entry&\\
b & b & b &\\
\rowstyle{\mystyle}
data & other data & last data &\\
\end{tabular}}
\end{document}

enter image description here

An alternate way to achieve the same thing, requiring a little less typing in the tabular itself, is to define the ! column type

\documentclass{article}
\usepackage{array}
\newcolumntype{$}{>{\global\let\currentrowstyle\relax}}
\newcolumntype{^}{>{\relax\currentrowstyle}}
\newcolumntype{!}{>{\relax\hspace*{-2\tabcolsep}}c}
\newcommand{\rowstyle}[1]{\gdef\currentrowstyle{#1}%
  #1\ignorespaces%
}
\def\mystyle#1\relax{\setbox0=\hbox{#1}\rule[2pt]{\wd0}{1pt}\kern-\wd0#1}
\begin{document}
\fbox{\begin{tabular}{$l^c^r!}
\rowstyle{\mystyle}
This is an entry & another entry & a third entry&\\
b & b & b &\\
\rowstyle{\mystyle}
data & other data & last data &\\
\end{tabular}}
\end{document}
1

A solution with pst-node. I used the \psDefBoxNodes, which puts its contents in a box and defines a series of nodes in that box (12 nodes in all), then I connected a node from the first element in the row to a node from the last element in the row:

\documentclass[x11names]{article}
\usepackage{pst-node}
\usepackage{auto-pst-pdf}

\begin{document}

\begin{postscript}
  \begin{tabular}{lcr}
    a & a & a \\
    \psDefBoxNodes{B1}{b} & b & \psDefBoxNodes{B2}{b} \\
    c & c & c \\
  \end{tabular}
  \ncline[nodesep=-2pt, offset=-0.3ex, linewidth=0.4pt, linecolor=IndianRed3]{B1: Cl}{B2: Cr}
\end{postscript}

\end{document}

enter image description here

Bernard
  • 271,350
0

Here is a solution with {NiceTabular} of nicematrix. That environment is similar to the classical {tabular} (of the package array) but adds PGF/Tikz nodes under the rows, columns and cells. It's possible to use those nodes in the so-called \CodeAfter to draw with Tikz whatever rule you want.

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

\begin{document}

\begin{NiceTabular}{ccc} \toprule Sandra & Alexandra & Anne \ Luc & Claude & Jean \ Paul & Pierre & Jacques \ Laurence & Sophie & Lucie \ \bottomrule \CodeAfter \tikz \draw (3.5-|1) -- (3.5-|last) ; \end{NiceTabular}

\end{document}

Output of the first code

If you prefer a syntax with a command \Strike in the beginning of the row to strike, it's also possible:

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

\ExplSyntaxOn \NewDocumentCommand{\Strike}{} { \tl_gput_right:Nx \g_nicematrix_code_after_tl { \shess_strike:n { \arabic { iRow } } } \ignorespaces } \cs_new_protected:Nn \shess_strike:n { \tikz \draw (#1.5-|1) -- (#1.5-|last) ; } \ExplSyntaxOff

\begin{document}

\begin{NiceTabular}{ccc} \toprule Sandra & Alexandra & Anne \ \Strike Luc & Claude & Jean \ Paul & Pierre & Jacques \ Laurence & Sophie & Lucie \ \bottomrule \end{NiceTabular}

\end{document}

\g_nicematrix_code_after_tl is a parameter of nicematrix, internal but public, which corresponds to the so-called \CodeAfter.

Output of the second code

F. Pantigny
  • 40,250