tabularray icon indicating copy to clipboard operation
tabularray copied to clipboard

rounding error (?) when doing double or triple line borders in table

Open jtl5770 opened this issue 2 years ago • 4 comments

my MWE to demonstrate the problem I see is

\documentclass{article}
\usepackage{tabularray}

\begin{document}
\begin{tblr}{
    hline{1} = {1}{-}{}, hline{1} = {2}{-}{rightpos=0.5, leftpos=0.5}, hline{1} = {3}{-}{rightpos=0, leftpos=0},
    hline{4} = {1}{-}{rightpos=0, leftpos=0}, hline{4} = {2}{-}{rightpos=0.5, leftpos=0.5}, hline{4} = {3}{-}{},
    vline{1} = {1}{-}{abovepos=1, belowpos=1}, vline{1} = {2}{-}{abovepos=0.5, belowpos=0.5}, vline{1} = {3}{-}{},
    vline{4} = {1}{-}{}, vline{4} = {2}{-}{abovepos=0.5, belowpos=0.5}, vline{4} = {3}{-}{abovepos=1, belowpos=1},
  }
  Alpha & Beta & Gamma \\
  One   & Two  & Three \\
  Tic   & Tac  & Toe \\
\end{tblr}
\end{document}

resulting in tripleborder

First of all - is this the intended way to achieve the triple (or double) border? If no, all the rest of this post (and maybe the bug reported) may be invalid...

Possible bug: compare the upper left and upper right corner of the inner hline/vline - there seems to be missing a couple of pixels. All other corners, even the bottom left/right of the inner hline/vline seem to be correct. This seems to be a bug, or I may have missed or misused an option?

Additional question: Is there a way to selectively (or even globally) influence the distance between the border lines?

jtl5770 avatar Mar 23 '22 13:03 jtl5770

The distance between the border lines is controlled by rulesep option. The positons of hlines with leftpos/rightpos set to 0 can be improved in the future. But I will not touch pos=0.5 case.

lvjr avatar Mar 24 '22 08:03 lvjr

Just for reference: To achieve a double rule border, the "official way" is like I did it (minus the 0.5 thing, just forget about that)?

Is it really the hline that is positioned wrong, or could it also be the vline? I am just wondering how and why the inner border bottom left/right seem to be OK, while top left/right is clearly buggy.

I understood the rulesep now. Can this be controlled for specific rules, or only globally for a table?

jtl5770 avatar Mar 24 '22 08:03 jtl5770

Is it really the hline that is positioned wrong, or could it also be the vline? I am just wondering how and why the inner border bottom left/right seem to be OK, while top left/right is clearly buggy.

Yes, it maybe vlines which cause the problem.

I understood the rulesep now. Can this be controlled for specific rules?

Sorry, but I don't want to make source code even more complicated by doing this.

lvjr avatar Mar 24 '22 09:03 lvjr

Sorry, but I don't want to make source code even more complicated by doing this.

Yes, I can understand that. I assume that everything completely fancy can be done once we have some tikz integration running.

jtl5770 avatar Mar 24 '22 09:03 jtl5770

I will fix the inconsistent positioning of abovepos and belowpos in issue #272.

lvjr avatar Aug 22 '22 11:08 lvjr

I don't see the problem solved with the latest version (2023A) and the inner line of a double rule. I use the following, slightly reduced code (only two instead of three lines)

\documentclass{article}
\usepackage{tabularray}

\begin{document}
\begin{tblr}{
    hline{1} = {1}{-}{rightpos=1, leftpos=1},
    hline{1} = {2}{-}{rightpos=0, leftpos=0},
    hline{4} = {1}{-}{rightpos=0, leftpos=0},
    hline{4} = {2}{-}{rightpos=1, leftpos=1},
    vline{1} = {1}{-}{abovepos=1, belowpos=1},
    vline{1} = {2}{-}{abovepos=0, belowpos=0},
    vline{4} = {1}{-}{abovepos=0, belowpos=0},
    vline{4} = {2}{-}{abovepos=1, belowpos=1},
  }
  Alpha & Beta & Gamma \\
  One   & Two  & Three \\
  Tic   & Tac  & Toe \\
\end{tblr}
\end{document}

and, looking at the result in a high enough magnification one can still see the error at the joints of the inner line

image

jtl5770 avatar Mar 28 '23 07:03 jtl5770

Unfortunately I don't see how I can reopen the issue - I hope it is not lost completely now...

jtl5770 avatar Mar 28 '23 07:03 jtl5770

This works by design. You need to set the correct position values for either hlines or vlines: 0.4/(0.4*2+2)=0.14 from rulewidth=0.4pt and rulesep=2pt.

\documentclass{article}
\usepackage{tabularray}
\begin{document}
\begin{tblr}{
    hline{1} = {1}{-}{rightpos=1, leftpos=1},
    hline{1} = {2}{-}{rightpos=0.14, leftpos=0.14},
    hline{4} = {1}{-}{rightpos=0.14, leftpos=0.14},
    hline{4} = {2}{-}{rightpos=1, leftpos=1},
    vline{1} = {1}{-}{abovepos=1, belowpos=1},
    vline{1} = {2}{-}{abovepos=0, belowpos=0},
    vline{4} = {1}{-}{abovepos=0, belowpos=0},
    vline{4} = {2}{-}{abovepos=1, belowpos=1},
  }
  Alpha & Beta & Gamma \\
  One   & Two  & Three \\
  Tic   & Tac  & Toe \\
\end{tblr}
\end{document}

image

lvjr avatar Mar 28 '23 12:03 lvjr

Oh... wow.

First of all - thanks for the hint. And nice that there is a way to make it work without pure guessing and trying of random values. But - and I mean this in the most polite way possible - this seems to be such a huge level of internal knowledge necessary for the "normal" user for achieving a simple double rule... Is there no way to provide an interface that is a bit more oriented towards the average user? Maybe the optimal way would be not having to use multiple hline and vline expressions per side in the first place, and express the double rules as a style to a single hline and vline...

Anyway - thanks for this great package

jtl5770 avatar Mar 28 '23 13:03 jtl5770

It seems to me the current semantics of xxxpos options are not convenient enough when there are multiple rules in the other direction.

Current semantics: https://github.com/lvjr/tabularray/blob/e5f340b1f8a60b7b24acdf02991cf0a29811426a/tabularray.tex#L776-L780 Then

  • with abovepos=1 the vline for the first row has length full cell height + 1st hline width + double sep + 2nd hline width, the 2nd hline width is counted,
  • but with abovepos=0 the corresponding vline only has length full cell height, 1st hline width is not counted.

A set of more powerful xxxpos-like options are welcome, for example for vline{1}={1-1}{aboveNpos=<n>}

<n> ::= "-1"  (* len = full cell height - row above sep *)
      |  "0"  (* len = full cell height *)
      |  "0+" (* len = full cell height + 1st hline width *)
      |  "1"  (* len = full cell height + 1st hline width + double sep *)
      |  "1+" (* len = full cell height + 1st hline width + double sep + 2nd hline width, if the 2nd hline exists *)
      |  "n"  (* len = full cell height + sum(1st to nth hline width) + n * double sep *)
      |  "n+" (* len = full cell height + sum(1st to (n+1)th hline width) + n * double sep *)
      ;

image

Full example

\documentclass{article}
\usepackage{tabularray}
\usepackage{xcolor}

\begin{document}
\rulewidth=3pt

\verb|abovepos| with single rule\par
\begin{tblr}{
  cells={bg=cyan!20},
  vline{1}={abovepos=1},
  vline{2}={abovepos=0},
  vline{3}={abovepos=-1},
  hline{1}={2}{2-Z}{fg=cyan!30!black!50, leftpos=-1, endpos},
}
  Alpha & Beta & Gamma \\
\end{tblr}
\bigskip

\verb|abovepos| with multiple rules\par
\begin{tblr}{
  cells={bg=cyan!20},
  vline{1}={abovepos=1},
  vline{2}={abovepos=0},
  vline{3}={abovepos=-1},
  hline{1}={1}{1-Z}{fg=cyan!30!black!50, leftpos=-1, endpos},
  hline{1}={2}{2-Z}{fg=cyan!30!black!50, leftpos=-1, endpos},
}
  Alpha & Beta & Gamma \\
\end{tblr}
\bigskip

suppose there's \verb|aboveNpos=<n>|\par
\begin{tblr}{
  cells={bg=cyan!20},
  vline{1}={abovepos=1}, % 8/8      % or aboveNpos=1+
  vline{2}={abovepos=\fpeval{5/8}}, % or aboveNpos=1
  vline{3}={abovepos=\fpeval{3/8}}, % or aboveNpos=0+
  vline{4}={abovepos=0}, % 0/8      % or aboveNpos=0
  vline{5}={abovepos=-1},           % or aboveNpos=-1
  hline{1}={1}{1-1}{fg=cyan!30!black!50, leftpos=-1, rightpos=0},
  hline{1}={1}{2-2}{fg=cyan!30!black!50, leftpos=0, endpos},
  hline{1}={2}{3-3}{fg=cyan!30!black!50, leftpos=-1, rightpos=0},
  hline{1}={2}{4-4}{fg=cyan!30!black!50, leftpos=0},
}
  A & B & C & D \\
\end{tblr}
\end{document}

muzimuzhi avatar Mar 28 '23 14:03 muzimuzhi

I am planning to drop support for multiple border lines and border text in future Lua rewriting (see #250). But old TeX code will stay unchanged.

lvjr avatar Mar 29 '23 08:03 lvjr