1

I’m using the tabularray package, and I’d like to insert vertical border segments between just a few specific cells in a table, as shown in the left-hand table below. As seen in the MWE code, I can get such lines by using the hline option together with the row numbers of the cells in question. However, I’d like to do this without using the absolute row numbers if possible — ideally, with a command in one of the cells neighbouring the border itself, something like the “desired source” code in the MWE — so that I can add/remove rows elsewhere in the table and have these border segments stay with the correct line of content.

(In my eventual use-case there are also multi-row and multi-column cells, and cells with background colours, so a solution that plays well with these would be strongly preferred.)

enter image description here

\documentclass[margin=3mm]{standalone}
\usepackage{tabularray}
\newcommand{\cellvline}{\textbullet} % placeholder to be redefined

\begin{document}
Desired output:
\begin{tblr}{vline{1,Z},hline{1,Z},vline{2}={3}{solid},vline{4}={2}{solid}}
  a1 & a2 & a3 & a4 \\
  b1 & b2 & b3 & b4 \\
  c1 & c2 & c3 & c4 \\
\end{tblr}
\hspace{2em}

Desired source:
\begin{tblr}{vline{1,Z},hline{1,Z}}
  a1 & a2 & a3 & a4 \\
  b1 & b2 & b3 & \cellvline b4 \\
  c1 & \cellvline c2 & c3 & c4 \\
\end{tblr}
\end{document}
2
  • @jsbibra: Indeed, that answer is just the sort of thing I was looking for — except not in tabularray, and I can’t see how to adapt it, since (as far as I can find) the tabulararray equivalents of \multirow/\multiline don’t allow separators to be included with the column specification. Sep 1, 2023 at 6:05

1 Answer 1

4

The simplest and as it seems the only way:

\documentclass[margin=3mm]{standalone}
\usepackage{xcolor}
\usepackage{tabularray}

\begin{document}
\begin{tblr}{hline{1,Z}={solid},  vline{1,Z}={1-Z}{solid},
             vline{2}={Z}{solid, fg=red}, 
             vline{Y}={Y}{solid,fg=blue},
             colspec= {Q[c]}
             }
  a1 & a2 & a3 & a4 \\
  b1 & b2 & b3 & b4 \\
  c1 & c2 & c3 & c4 \\
\end{tblr}
\end{document}

enter image description here

Edit:
You can insert \SetVline in a table cell, however, you still need to tell in which row the cell is...

\documentclass[margin=3mm]{standalone}
\usepackage{xcolor}
\usepackage{tabularray}

\begin{document}
\begin{tblr}{hline{1,Z}={solid},  vline{1,Z}={1-Z}{solid},
             colspec= {Q[c]}
             }
  a1 & a2 & a3 & a4 \\
  b1 & b2 & b3 & \SetVline{2}{blue5} b4 \\
  c1 & \SetVline{3}{red5}  c2 
          & c3 & c4 \\
\end{tblr}
\end{document}

Result is the same as before.

4
  • Unfortunately (sorry if this wasn’t clear in the question) using the row position counted from the bottom is no better than counted from the top — either way, the line segments are not tied to the particular row contents, so may get misplaced from them if more rows are added below/above. Sep 1, 2023 at 6:08
  • @PeterLeFanuLumsdaine, you can insert row and column number absolutely, if you wish. But, more important, unfortunately there is no other way as to explicate tell in which row is particular cell. See edited answer.
    – Zarko
    Sep 1, 2023 at 6:48
  • 1
    It would be a great feature if there was a command that could allow to customize vlines only for the row where it was inserted.
    – Imran
    May 5 at 20:04
  • 1
    @Imran, thank you for editing answer! You are right, but with new version of tabularray maybe this is possible. Sorry, I haven't time yet to test this.
    – Zarko
    May 5 at 20:26

You must log in to answer this question.

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