-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve tikz library #29
Comments
|
In fact, Moreover, First of all, we need to decide whether or not |
Also, |
I have merged pull request #554 (Add tikz library) contributed by Jasper Habicht. We can discuss further improvements to this library in this issue. |
I just read issue #27 about PDF tagging and I think it might be a good idea to add another hook directly before |
As far as I know, by default contents not tagged as |
@jasperhabicht From above example, it seems tikz table node is a bit larger than the table box. Any idea? |
You also need
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}
% default "outer sep"
\begin{tikzpicture}[line width=3pt]
\node[draw=none, fill=none, inner sep=0pt, text width=3cm, text height=2cm] (a) at (0,0) {};
\draw[red] (a.north east) rectangle (a.south west);
\draw (-1.5, 0) -- (1.5, 0);
\end{tikzpicture}
% "outer sep=0pt"
\begin{tikzpicture}[line width=3pt]
\node[draw=none, fill=none, inner sep=0pt, outer sep=0pt, text width=3cm, text height=2cm] (a) at (0,0) {};
\draw[red] (a.north east) rectangle (a.south west);
\draw (-1.5, 0) -- (1.5, 0);
\end{tikzpicture}
\end{document} As a cross reference, see how Update: I just opened #559 to address this. |
True, I missed that. Thanks! Interesting that the Of course, if the node is empty (which it is supposed to be anyways), the result will be the same. But we also need to take into account depth here, so using the |
Since corner nodes work only with new node code, I have removed old node code. |
It seems these lines can be removed: \box_set_trim:Nnnnn \l__tblr_tikz_node_box
{ 0pt } { 0pt } { 0pt } { 0pt } |
I originally added these to absolutely make sure that the box created for the TikZ stuff is zero-sized. In theory, since the If we rely on this, we can indeed omit As for the |
Removed. Also I have added labels to the hooks. |
Recently I have been considering long table support. Here are some ideas:
|
I have enabled tikz drawing for long tables in above commit. The good news is that everything works well if the \documentclass{article}
\usepackage{tabularray}
\UseTblrLibrary{tikz}
\usetikzlibrary{patterns}
\begin{document}
\begin{tblrtikzbelow}
\fill[pattern color=lightgray,pattern=crosshatch]
(table.north east) rectangle (table.south west);
\fill[yellow7] (3-1.north west) rectangle (3-1.south east);
\fill[red7] (3-3.north west) rectangle (3-3.south east);
\fill[purple7] (3-5.north west) rectangle (3-5.south east);
\fill[teal7] (4-2.north west) rectangle (4-2.south east);
\fill[brown7] (4-4.north west) rectangle (4-4.south east);
\end{tblrtikzbelow}%
\begin{tblrtikzabove}
\draw[brown7,ultra thick] (7-2.north west) -- (7-2.south east)
(7-2.south west) -- (7-2.north east);
\draw[yellow7,ultra thick] (7-4.north west) -- (7-4.south east)
(7-4.south west) -- (7-4.north east);
\draw[purple7,ultra thick] (8-1.north west) -- (8-1.south east)
(8-1.south west) -- (8-1.north east);
\draw[cyan3,ultra thick] (8-3.north west) -- (8-3.south east)
(8-3.south west) -- (8-3.north east);
\draw[teal7,ultra thick] (8-5.north west) -- (8-5.south east)
(8-5.south west) -- (8-5.north east);
\draw[color=white,thick]
(h5-|v1) -- (h5-|v2) -- (h6-|v2)
-- (h6-|v3) -- (h7-|v3) -- (h7-|v4)
-- (h5-|v4) -- (h5-|v5) -- (h6-|v5)
-- (h6-|v6) -- (h5-|v6);
\end{tblrtikzabove}%
\begin{longtblr}[
caption = Long Table Tikz
]{
%rowhead=2, rowfoot=1,
hlines={wd=4pt},vlines={wd=3pt},colspec={XXXXX}
}
1-1 & 1-2 & 1-3 & 1-4 & 1-5 \\
2-1 & 2-2 & 2-3 & 2-4 & 2-5 \\
3-1 & 3-2 & 3-3 & 3-4 & 3-5 \\
4-1 & 4-2 & 4-3 & 4-4 & 4-5 \\%\pagebreak
5-1 & 5-2 & 5-3 & 5-4 & 5-5 \\
6-1 & 6-2 & 6-3 & 6-4 & 6-5 \\
7-1 & 7-2 & 7-3 & 7-4 & 7-5 \\
8-1 & 8-2 & 8-3 & 8-4 & 8-5 \\
9-1 & 9-2 & 9-3 & 9-4 & 9-5 \\
\end{longtblr}
\end{document} |
The bad news is that if we enable
|
It seems that the code defined via At least, we need separate TikZ environments for every page that may only refer to nodes that exist on this page. Also, the |
I have provided some public variables:
Therefore uses can do conditional tikz drawing on tables. |
With above public variables, we can do conditional drawing (by making sure used cell nodes are actually in current page) in \documentclass{article}
\usepackage[a6paper,margin=15mm]{geometry}
\usepackage{tabularray}
\UseTblrLibrary{tikz}
\usetikzlibrary{patterns}
\begin{document}
\ExplSyntaxOn
\cs_set_eq:NN \boolifnT \bool_if:nT
\cs_set_eq:NN \intcomparepn \int_compare_p:n
\ExplSyntaxOff
\begin{tblrtikzbelow}
\fill[pattern color=lightgray,pattern=crosshatch]
(table.north east) rectangle (table.south west);
\boolifnT{
\intcomparepn{\lTblrRowFirstInt <= 3} && \intcomparepn{\lTblrRowLastInt >= 4}
}{
\fill[yellow7] (3-1.north west) rectangle (3-1.south east);
\fill[red7] (3-3.north west) rectangle (3-3.south east);
\fill[purple7] (3-5.north west) rectangle (3-5.south east);
\fill[teal7] (4-2.north west) rectangle (4-2.south east);
\fill[brown7] (4-4.north west) rectangle (4-4.south east);
}
\end{tblrtikzbelow}%
\begin{tblrtikzabove}
\boolifnT{
\intcomparepn{\lTblrRowFirstInt <= 7} && \intcomparepn{\lTblrRowLastInt >= 8}
}{
\draw[brown7,ultra thick] (7-2.north west) -- (7-2.south east)
(7-2.south west) -- (7-2.north east);
\draw[yellow7,ultra thick] (7-4.north west) -- (7-4.south east)
(7-4.south west) -- (7-4.north east);
\draw[purple7,ultra thick] (8-1.north west) -- (8-1.south east)
(8-1.south west) -- (8-1.north east);
\draw[cyan3,ultra thick] (8-3.north west) -- (8-3.south east)
(8-3.south west) -- (8-3.north east);
\draw[teal7,ultra thick] (8-5.north west) -- (8-5.south east)
(8-5.south west) -- (8-5.north east);
}
\end{tblrtikzabove}%
\begin{longtblr}[
caption = Long Table Tikz
]{
rowhead=2,
rowfoot=1,
hlines={wd=4pt},vlines={wd=3pt},colspec={XXXXX}
}
1-1 & 1-2 & 1-3 & 1-4 & 1-5 \\
2-1 & 2-2 & 2-3 & 2-4 & 2-5 \\
3-1 & 3-2 & 3-3 & 3-4 & 3-5 \\
4-1 & 4-2 & 4-3 & 4-4 & 4-5 \\\pagebreak
5-1 & 5-2 & 5-3 & 5-4 & 5-5 \\
6-1 & 6-2 & 6-3 & 6-4 & 6-5 \\
7-1 & 7-2 & 7-3 & 7-4 & 7-5 \\
8-1 & 8-2 & 8-3 & 8-4 & 8-5 \\
9-1 & 9-2 & 9-3 & 9-4 & 9-5 \\
\end{longtblr}
\end{document} |
I am inclined to try current For a multipage long table, cell nodes works as expected. But the table node is wrong, so I have temporarily disabled corner nodes for multipage long tables in the commit above. |
With \documentclass{article}
\usepackage[a6paper,margin=15mm]{geometry}
\usepackage{tabularray}
\UseTblrLibrary{tikz}
\usetikzlibrary{patterns}
\begin{document}
\ExplSyntaxOn
\cs_generate_variant:Nn \clist_map_inline:nn {e}
\cs_new_protected:Npn \mymagic #1
{
\clist_map_inline:en {\ExpTblrChildClass {#1}}
{
\bool_lazy_and:nnT
{ \int_compare_p:n {\lTblrRowFirstInt <= \use_i:nn ##1} }
{ \int_compare_p:n {\lTblrRowLastInt >= \use_i:nn ##1} }
{ \exp_args:Noo \mymagicfill {\use_i:nn ##1} {\use_ii:nn ##1} }
}
}
\ExplSyntaxOff
\newcommand\mymagicfill[2]{
\fill[teal7] (#1-#2.north west) rectangle (#1-#2.south east);
}
\begin{tblrtikzbelow}
\fill[pattern color=lightgray,pattern=crosshatch]
(table.north east) rectangle (table.south west);
\mymagic{magic}
\end{tblrtikzbelow}%
\begin{longtblr}[
caption = Long Table Tikz
]{
rowhead=2,
rowfoot=1,
hlines={wd=4pt},vlines={wd=3pt},colspec={*{5}{X[r]}}
}
Head1 & Head2 & Head3 & Head4 & Head5 \\
Head1 & Head2 & Head3 & Head4 & Head5 \\
3-1 & 3-2 & 3-3 & 3-4 & 3-5 \\
4-1 & 4-2 & 4-3 & \SetChild{class=magic}4-4
& 4-5 \\
5-1 & 5-2 & 5-3 & 5-4 & 5-5 \\
6-1 & 6-2 & 6-3 & 6-4 & 6-5 \\
7-1 & \SetChild{class=magic}7-2
& 7-3 & 7-4 & 7-5 \\
8-1 & 8-2 & 8-3 & 8-4 & \SetChild{class=magic}8-5 \\
9-1 & 9-2 & 9-3 & 9-4 & 9-5 \\
10-1 & 10-2 & 10-3 & 10-4 & 10-5 \\
11-1 & 11-2 & 11-3 & 11-4 & 11-5 \\
\SetChild{class=magic}12-1
& 12-2 & 12-3 & 12-4 & 12-5 \\
13-1 & 13-2 & 13-3 & 13-4 & 13-5 \\
14-1 & 14-2 & 14-3 & 14-4 & 14-5 \\
15-1 & 15-2 & 15-3 & 15-4 & \SetChild{class=magic}15-5 \\
16-1 & 16-2 & 16-3 & 16-4 & 16-5 \\
17-1 & 17-2 & 17-3 & 17-4 & 17-5 \\
18-1 & 18-2 & 18-3 & 18-4 & 18-5 \\
19-1 & 19-2 & \SetChild{class=magic}19-3
& 19-4 & 19-5 \\
20-1 & 20-2 & 20-3 & 20-4 & 20-5 \\
21-1 & 21-2 & 21-3 & 21-4 & 21-5 \\
22-1 & \SetChild{class=magic}22-2
& 22-3 & 22-4 & 22-5 \\
23-1 & 23-2 & 23-3 & 23-4 & 23-5 \\
24-1 & 24-2 & 24-3 & 24-4 & 24-5 \\
\SetChild{class=magic}25-1
& 25-2 & 25-3 & 25-4 & 25-5 \\
26-1 & 26-2 & 26-3 & 26-4 & 26-5 \\
27-1 & 27-2 & 27-3 & 27-4 & 27-5 \\
28-1 & 28-2 & 28-3 & 28-4 & 28-5 \\
29-1 & 29-2 & 29-3 & 29-4 & 29-5 \\
30-1 & 30-2 & 30-3 & \SetChild{class=magic}30-4
& 30-5 \\
31-1 & 31-2 & 31-3 & 31-4 & 31-5 \\
32-1 & 32-2 & 32-3 & 32-4 & 32-5 \\
33-1 & 33-2 & 33-3 & 33-4 & 33-5 \\
34-1 & \SetChild{class=magic}34-2
& 34-3 & 34-4 & 34-5 \\
35-1 & 35-2 & 35-3 & 35-4 & 35-5 \\
36-1 & 36-2 & 36-3 & 36-4 & 36-5 \\
37-1 & 37-2 & \SetChild{class=magic}37-3
& 37-4 & 37-5 \\
38-1 & 38-2 & 38-3 & 38-4 & 38-5 \\
Foot1 & Foot2 & Foot3 & Foot4 & Foot5 \\
\end{longtblr}
\end{document} In this example, the clist expanded from
|
The main problem is the table nodes. At this time table nodes are created after the last cells in \cs_new_protected:Npn \__tblr_build_short_table:n #1
{
\mode_leave_vertical:
\__tblr_build_one_table:nnNN {1} {\c@rowcount} \c_true_bool \c_true_bool
\__tblr_hook_use:n { private/output/before }
\__tblr_valign_whole:Nn \l__tblr_table_box {#1}
\__tblr_hook_use:n { private/output/after }
}
\cs_new_protected:Npn \__tblr_build_tall_table:n #1
{
\mode_leave_vertical:
\__tblr_build_tall_table_head_foot:
\__tblr_build_one_table:nnNN {1} {\c@rowcount} \c_true_bool \c_true_bool
\vbox_set:Nn \l__tblr_table_box
{
\box_use:N \l__tblr_table_firsthead_box
\hrule height ~ 0pt
\box_use:N \l__tblr_table_box
\hrule height ~ 0pt
\box_use:N \l__tblr_table_lastfoot_box
}
\__tblr_hook_use:n { private/output/before }
\__tblr_valign_whole:Nn \l__tblr_table_box {#1}
\__tblr_hook_use:n { private/output/after }
}
\cs_new_protected:Npn \__tblr_build_page_table:nnn #1 #2 #3
{
\int_set:Nn \lTblrRowFirstInt {#2}
\int_set:Nn \lTblrRowLastInt {#3}
\__tblr_build_one_table:nnNN {#2} {#3} \c_false_bool \c_false_bool
\vbox_set:Nn \l__tblr_table_box
{
\box_use:N \l__tblr_table_head_box
\__tblr_cover_two_vboxes:NN \l__tblr_row_head_box \l__tblr_table_box
\box_use:N \l__tblr_row_foot_box
\hrule height ~ 0pt
\box_use:N \l__tblr_table_foot_box
}
\__tblr_hook_use:n { private/output/before }
\__tblr_halign_whole:Nn \l__tblr_table_box {#1}
\__tblr_hook_use:n { private/output/after }
} |
There is a catcode problem in loading tikz libraries: pgf-tikz/pgf#1213. |
Seems that it can be solved: latex3/latex3#235 (comment) |
nicematrix
use of names of the cells to play with TikZ for (even if this fine-tunings is used in some rare situations).This could be a feature proposed only when using
\UseTblrLibrary{tikz}
.The text was updated successfully, but these errors were encountered: