1

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}
4
  • Observation: Your current title sounds like asking for an oppinion (which will probably lead to a close). However, you seem to want adjusting your current solution. // Suggestion: a) rephrase the title, b) make your real question more visible, e.g. by introducing a paragraph, highlighting the relevant part or similar. // Also a screenshot or two may help understanding your current situation and where you do want to go more easy to grasp. Thanks
    – MS-SPO
    Commented Feb 9, 2023 at 12:28
  • Do you need the inner nodes to be drawn (or filled)? If not you can just use anchors to align text horizontally. Commented Feb 9, 2023 at 17:24
  • If I'm installing the two Noto fonts and run your code through LuaLaTeX I get no error message and a clean output. What is not working with your MWE? Commented Feb 9, 2023 at 17:31
  • is it texlive your distro? what version? Commented Feb 10, 2023 at 4:12

1 Answer 1

1

I'm not sure to understand your question, but I suggest a workaround using {NiceTabular} of nicematrix.

That environment creates a tabular like the standard environment {tabular} but creates also PGF/Tikz nodes under the rows, columns and cells.

You can use those nodes to draw whatever rule you want with 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}

You need several compilations.

Output of the above code

1
  • NiceTabular seems better than tabular actually. i get a lor of warnings with tabular in beamer documentclass. Commented Feb 10, 2023 at 11:38

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .