-
Notifications
You must be signed in to change notification settings - Fork 15
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
能否扩展diagbox的斜线类型 #239
Comments
tikz 的路子。
\documentclass{article}
\usepackage{tabularray}
\ExplSyntaxOn
\NewTblrLibrary { tikzbox }
{
\RequirePackage{ tikz }
\NewContentCommand \tikzbox [2] []
{
\__tblr_lib_tikzbox_fix:n
{
\tikz[baseline=\dim_use:N \box_dp:N \l__tblr_strut_dp_box + \belowsep, ##1] {##2}
}
}
}
\box_new:N \l__tblr_tikz_box
\cs_new_protected:Npn \__tblr_lib_tikzbox_fix:n #1
{
\hbox_set:Nn \l__tblr_tikz_box {#1}
\box_set_ht:Nn \l__tblr_tikz_box { \box_ht:N \l__tblr_tikz_box - \abovesep }
\box_set_dp:Nn \l__tblr_tikz_box { \box_dp:N \l__tblr_tikz_box - \belowsep }
\box_set_wd:Nn \l__tblr_tikz_box { \box_wd:N \l__tblr_tikz_box - \rightsep }
\skip_horizontal:n { -\leftsep }
\box_use:N \l__tblr_tikz_box
}
\ExplSyntaxOff
\UseTblrLibrary{diagbox, tikzbox}
\begin{document}
\verb|\diagbox{Aa}{Pp}|\par
\begin{tblr}{hlines,vlines}
\diagbox{Aa}{Pp} & Beta & Gamma \\
Epsilon & Zeta & Eta \\
Iota & Kappa & Lambda \\
\end{tblr}
\bigskip
\verb|\tikzbox{<tikz drawing code>}|\par
\begin{tblr}{hlines,vlines}
\tikzbox{
\useasboundingbox (0,0) rectangle (3,1);
\pgfnodealias{cbb}{current bounding box}
\draw
(cbb.north west) -- (cbb.south east)
(cbb.north west) -- (cbb.south);
}
& Beta & Gamma \\
Epsilon & Zeta & Eta \\
Iota & Kappa & Lambda \\
\end{tblr}
\end{document} 注意,
|
\NewTblrLibrary { tikzbox }
{
\RequirePackage{ tikz }
\NewContentCommand \tikzbox [2] []
{
\__tblr_lib_tikzbox_fix:n
{
- \tikz[baseline=\dim_use:N \box_dp:N \l__tblr_strut_dp_box + \belowsep, ##1] {##2}
+ $\vcenter{\hbox{\tikz[##1] {##2}}}$
}
}
} 这样就把纵向偏离值降到和 一些比较例子\documentclass{article}
\usepackage[margin=1cm]{geometry}
\usepackage{tabularray}
\ExplSyntaxOn
\NewTblrLibrary { tikzbox }
{
\RequirePackage{ tikz }
\NewContentCommand \tikzbox [2] []
{
\__tblr_lib_tikzbox_fix:n { $\vcenter{\hbox{\tikz[##1] {##2}}}$ }
}
}
\box_new:N \l__tblr_tikz_box
\cs_new_protected:Npn \__tblr_lib_tikzbox_fix:n #1
{
\hbox_set:Nn \l__tblr_tikz_box {#1}
\box_set_ht:Nn \l__tblr_tikz_box { \box_ht:N \l__tblr_tikz_box - \abovesep }
\box_set_dp:Nn \l__tblr_tikz_box { \box_dp:N \l__tblr_tikz_box - \belowsep }
\box_set_wd:Nn \l__tblr_tikz_box { \box_wd:N \l__tblr_tikz_box - \rightsep }
\skip_horizontal:n { -\leftsep }
\box_use:N \l__tblr_tikz_box
}
\ExplSyntaxOff
\UseTblrLibrary{diagbox, tikzbox}
\begin{document}
\noindent\verb|\diagbox[...]{...}{...}|\par
\newcommand\diagboxtest[3]{%
\begin{tblr}{hlines, vlines, baseline=3, #1}
\diagbox[#2]{Aa}{Pp}
& Beta & #3 \\
Epsilon & Zeta & Eta \\
Iota & Kappa & Lambda \\
\end{tblr}%
}
\def\diagboxtests#1#2{%
\texttt{\detokenize{#1}}\quad
\diagboxtest{#1} {} {Gamma}\quad
\diagboxtest{#1,#2}{height=1.2cm}{{Gamma \\ Gamma}}\quad
\diagboxtest{#1,#2}{height=1.3cm}{{Gamma \\ Gamma}}\par
}
\diagboxtests{row{1}=t}{cell{1}{1}=cyan!20}
\diagboxtests{row{1}=m}{}
\diagboxtests{row{1}=b}{cell{1}{1}=cyan!20}
\bigskip
\noindent\verb|\tikzbox{<tikz drawing code>}|\par
\newcommand\tikzboxtest[4]{%
\begin{tblr}{hlines, vlines, baseline=3, #1}
\tikzbox[#4]{
\useasboundingbox (0,0) rectangle (2,#2);
\pgfnodealias{cbb}{current bounding box}
\draw
(cbb.north west) -- (cbb.south east)
(cbb.north west) -- (cbb.south);
}
& Beta & #3 \\
Epsilon & Zeta & Eta \\
Iota & Kappa & Lambda \\
\end{tblr}
}
\def\tikzboxtests#1#2{%
\texttt{\detokenize{#1}}\quad
\tikzboxtest{#1} {1cm} {Gamma} {}\quad
\tikzboxtest{#1,#2}{1.2cm}{{Gamma \\ Gamma}}{}\quad
\tikzboxtest{#1,#2}{1.3cm}{{Gamma \\ Gamma}}{}\par
}
\tikzboxtests{row{1}=t}{cell{1}{1}=cyan!20}
\tikzboxtests{row{1}=m}{}
\tikzboxtests{row{1}=b}{cell{1}{1}=cyan!20}
\end{document} |
不错。其中 |
如果只是画线的话,似乎用 |
@lvjr 有点想让 |
diagbox宏包定义了几种表格线样式,能满足基本需求。但是对于复杂的表格斜线就有些难以实现了,能否定义一个更自由的画线命令,通过平移左上角和右下角的坐标实现画线自由?
The text was updated successfully, but these errors were encountered: