Replies: 2 comments 2 replies
-
Looks like there's no public interface yet. \documentclass{article}
\usepackage{tabularray}
\UseTblrLibrary{diagbox}
\ExplSyntaxOn
\cs_new:Npn \getCurrColWidth
{
\prop_item:Ne \l__column_computed_width_prop { \arabic{colnum} }
}
\ExplSyntaxOff
\begin{document}
\begin{longtblr}[label=none]{
width=\textwidth,
colspec={X[2]X[3]X[5]},
vlines,hlines
}
\diagbox[innerwidth=\getCurrColWidth]{}{} &
\diagbox[innerwidth=\getCurrColWidth]{}{} &
\diagbox[innerwidth=\getCurrColWidth]{}{} \\
\getCurrColWidth & \getCurrColWidth & \getCurrColWidth
\end{longtblr}
\end{document} |
Beta Was this translation helpful? Give feedback.
2 replies
-
Getting width and (total) height of table cells (in building phase) has been requested several times, see #329, #342, #406, and #461. Below is another attempt that exposes expandable \documentclass{article}
\usepackage{tabularray}
\UseTblrLibrary{diagbox}
\ExplSyntaxOn
% To be used in dim expressions, these two getters must be expandable, hence
% cannot be defined by \proNewFunction, like \cellGetText provided with library
% "functional"
\cs_new:Npn \TblrGetCellWidth { \dim_use:N \l__tblr_cell_wd_dim }
\cs_new:Npn \TblrGetCellHeight { \dim_use:N \l__tblr_cell_ht_dim }
% helper
\cs_new:Npn \TblrIfMeasuringTF { \bool_if:NTF \lTblrMeasuringBool }
% temp workaround for lvjr/tabularray#470
\cs_new:Npn \TblrFixBelowsepAndRightsep
{
% In case cell sizes are affected by \belowsep and \rightsep, this fix must
% be applied in both measuring and building phases.
\tl_if_empty:NT \l__tblr_cell_rowspan_tl
{
\tl_set:Ne \l__tblr_cell_rowspan_tl
{
\__tblr_data_item:neen { cell }
{ \l__tblr_i_tl } { \l__tblr_j_tl } { rowspan }
}
}
% FIXME: updating \belowsep unconditionally only introduces more problems
\int_compare:nNnT { \l__tblr_cell_rowspan_tl } > { 1 }
{
\dim_set:Nn \belowsep
{
\__tblr_data_item:nen { row }
{ \int_eval:n { \l__tblr_i_tl + \l__tblr_cell_rowspan_tl - 1 } }
{ belowsep }
}
}
\tl_if_empty:NT \l__tblr_cell_colspan_tl
{
\tl_set:Ne \l__tblr_cell_colspan_tl
{
\__tblr_data_item:neen { cell }
{ \l__tblr_i_tl } { \l__tblr_j_tl } { colspan }
}
}
\int_compare:nNnT { \l__tblr_cell_colspan_tl } > { 1 }
{
\dim_set:Nn \rightsep
{
\__tblr_data_item:nen { column }
{ \int_eval:n { \l__tblr_j_tl + \l__tblr_cell_colspan_tl - 1 } }
{ rightsep }
}
}
}
\ExplSyntaxOff
\newcommand{\onlySlash}[1][]{%
\TblrIfMeasuringTF{%
\diagbox{}{}%
}{%
\diagbox[
innerwidth=\TblrGetCellWidth,
height=\abovesep+\TblrGetCellHeight+\belowsep,
#1
]{}{}%
}%
}
\SetTblrInner{hlines, vlines}
\begin{document}
\begin{tblr}{
hlines,
vlines,
width = .7\linewidth,
colspec = { l c r X X[2] },
rowspec = { Q[t] Q[m] Q[b] Q[h] Q[f] },
cells =
{
appto = {%
\smash{\rlap{\tiny\sffamily(\therownum, \thecolnum)}}%
\onlySlash
}
},
}
& & & & \\
\\ \\ \\ \\
\end{tblr}
\begin{tblr}{
hlines,
vlines,
row{2} = { belowsep = 0pt },
% FIXME: larger belowsep (e.g., 10pt) resulted in vertically shifted diagbox
row{4} = { belowsep = 6pt },
column{3} = { rightsep = 12pt },
cell{1}{1} = { r = 2, c = 1 }{ font = \bfseries, c },
cell{2}{3} = { r = 2, c = 2 }{ font = \bfseries, c },
cell{4}{1} = { r = 1, c = 2 }{ font = \bfseries, c },
cell{5}{2} = { r = 1, c = 3 }{ font = \bfseries, c },
cells =
{
preto = {\TblrFixBelowsepAndRightsep},
appto = {%
\smash{\rlap{\tiny\sffamily(\therownum, \thecolnum)}}%
\onlySlash[dir=NE]
}
},
% vary cell sizes a bit
column{1} = { wd = 1cm },
row{3} = { ht = 1cm },
}
& & & \\
\\ \\ \\ \\
\end{tblr}
\end{document} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
When I use diagbox in a X column table, the line can't fix the cell. How to get the real width of the final cell?
Beta Was this translation helpful? Give feedback.
All reactions