我在文档中使用两种语言和两种脚本。我使用tikz
“矩阵”来填充标注气泡。如果需要左对齐或右对齐文本,则Tikz
需要为每列提供矩阵。我使用from来设置列宽。text width
width("...")
tikz
如果文本width("...")
不是主语言,则需要类似\textenglish
... 的命令,但该命令在此上下文中不起作用。\noexpand
(我连续尝试了三次)均不起作用。
在这种多语言环境中,我如何设置列宽以tikz
matrix
使其适合最长的字符串? \settowidth 需要在 tikzpicture 之外使用。
或者这里可以使用简单的表格吗?如果可以,如何制作标注气泡?\documentclass[a4paper]{article}
\usepackage{fontsize,fix-cm}
\usepackage{polyglossia}
\newfontfamily\devanagarifont[Script=Devanagari]{NotoSerifDevanagari}
\setotherlanguages{english}
\newfontfamily\englishfont{NotoSerif}
\newcommand{\eng}[1]{\footnotesize{\textenglish{#1}}}
\setmainlanguage{sanskrit}
\setmainfont[Script=Devanagari]{NotoSansDevanagari}
\usepackage{tikz}
\usetikzlibrary{shapes.callouts,matrix}
\tikzset{
allmatrix/.style = {matrix of nodes,
nodes in empty cells,matrix anchor=#1,
every outer matrix/.append style={inner sep=+0pt, outer sep=+0pt},
row sep=-\pgflinewidth, column sep=-\pgflinewidth,
ampersand replacement=\&, nodes={outer sep=0pt},
text height=1.5ex, text depth=.25ex},
bub/.style = {rectangle callout, rounded corners=2mm,
draw, align=left, callout relative pointer={#1}},
calloutmatrix/.style args = {#1/#2}{column #1/.append style={nodes={rectangle, text width=#2+4pt}}}}
\changefontsize[16.8]{14}
\begin{document}
\begin{tikzpicture}
\node at (0,0)
[shift={(0,0)}, anchor=north west]
{\begin{tabular}{|l|l|}
\hline
संस्कृतम्। & \eng{tikz matrix} \\
\hline
संस्कृतम् अस्ति। & \eng{this is a tikz matrix} \\
\hline
\end{tabular}};
\matrix at (0,-2cm) (sa1bub)
[shift={(0,0)}, allmatrix=north west,
bub={(0,-2cm))}, nodes={draw,rectangle},
calloutmatrix/.list={1/width("संस्कृतम् अस्ति।"), 2/width("this is a tikz matrix")}]
{संस्कृतम्। \& \eng{tikz matrix} \\
संस्कृतम् अस्ति। \& \eng{this is a tikz matrix} \\};
\end{tikzpicture}
\end{document}
根据答案进行更新和解决方案:实际上我不需要nodes={draw}
。我在这里启用它只是为了突出显示边距。我需要的只是这个:
\usepackage{nicematrix}
\tikzset{
bub/.style = {rectangle callout, rounded corners=2mm,
draw, callout relative pointer={#1}},}
\begin{document}
\begin{tikzpicture}
\node at (0,0)
[shift={(0,0)}, anchor=north west, bub={(0,-2cm)}]
{\begin{NiceTabular}{ll}
संस्कृतम्। & \eng{tikz matrix} \\
संस्कृतम् अस्ति। & \eng{this is a tikz matrix} \\
\end{NiceTabular}};
\end{tikzpicture}
\end{document}
答案1
我不确定是否理解了您的问题,但我建议使用一种解决{NiceTabular}
方法nicematrix
。
该环境创建一个类似于标准环境的表格{tabular}
,但也在行、列和单元格下创建 PGF/Tikz 节点。
您可以使用这些节点通过 Tikz 绘制您想要的任何规则。
\documentclass[a4paper]{article}
\usepackage{fontsize,fix-cm}
\usepackage{polyglossia}
\newfontfamily\devanagarifont[Script=Devanagari]{Noto Serif Devanagari}
\setotherlanguages{english}
\newfontfamily\englishfont{NotoSerif}
\newcommand{\eng}[1]{\footnotesize{\textenglish{#1}}}
\setmainlanguage{sanskrit}
\setmainfont[Script=Devanagari]{Noto Sans Devanagari}
\changefontsize[16.8]{14}
\usepackage{nicematrix}
\usepackage{tikz}
\usetikzlibrary{fit,shapes.callouts}
\begin{document}
\begin{tikzpicture}
\node
[ rectangle callout,
rounded corners=2mm,
draw,
callout relative pointer={(0,-2cm)},
inner sep = 0pt
]
at (0,0)
{
\begin{NiceTabular}{ll}[cell-space-limits=1mm]
संस्कृतम्। & \eng{tikz matrix} \\
संस्कृतम् अस्ति। & \eng{this is a tikz matrix} \\
\CodeAfter
\tikz
\foreach \i in {1,...,\arabic{iRow}} % iRow is the number of rows
\foreach \j in {1,...,\arabic{jCol}} % jCol is the number of columns
{
\node
[
rectangle,
draw,
rounded corners=2mm,
fit = (\i-|\j) (\inteval{\i+1} -|\inteval{\j+1})
]
{ } ;
} ;
\end{NiceTabular}%
} ;
\end{tikzpicture}
\end{document}
您需要多次编译。