I use two languages and two scripts in my document. I use tikz
'matrix' to fill callout bubbles. Tikz
matrix needs to be given the text width
for each column if left or right text alignment is needed. I use width("...")
from tikz
to set columns width.
If the text in width("...")
is in a non-main language it will need a command like \textenglish
... and that does not work in this context. The \noexpand
(I tried up to three consecutive) neither works.
In such multi-language context, how can I set the columns width in tikz
matrix
so that they fit the longest string? \settowidth needs to be used out of tikzpicture.
Or could a simple tabular be used here? If yes, how to make the callout bubble? \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}
Update and solution made from answers:
Actually I do not need the nodes={draw}
. I enabled it here only to highlight the margins. What i need is only this:
\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}