矩阵中的tikz文本垂直对齐

矩阵中的tikz文本垂直对齐

我需要使用 tikzpicture 中的矩阵创建两个单独的表格。使用我的代码,我无法获得正确的对齐,甚至无法从一行到另一行对齐。我尝试增加“最小高度”和“行间距 = {xxem,原点之间}”,但都无济于事。我基本上同时使用梵文和拉丁文。虽然这个对齐问题似乎与字体无关,但我将两者都留在了 mwe 中。

\documentclass[a4paper]{article}

\usepackage[verbose,vmargin=30mm,hmargin=20mm]{geometry}

\usepackage{tikz}
\usetikzlibrary{positioning, matrix}
\usepackage{babel}

\babelprovide[mapdigits,maparabic,import,main]{sanskrit}
\babelprovide[onchar=ids fonts]{english}
%rm : serif -- sf : sans -- tt : mono

\babelfont[*devanagari]{sf}{Shobhika}
\babelfont[*devanagari]{rm}[Language=Default]{NotoSerifDevanagari}
\babelfont[english]{sf}{FreeSans}
\babelfont[english]{rm}{NotoSerif}
\defaultfontfeatures{Renderer=Harfbuzz}

\tikzset{
  texttable/.style={row sep={.8em}, column sep=-\pgflinewidth,
         nodes={anchor=center, font=\Large, minimum height=4em, 
         text width=#1, inner sep=5pt,outer sep=0pt, draw},
}}
\begin{document}
    \noindent
\begin{tikzpicture}

    \matrix at (0,0) [matrix of nodes, nodes in empty cells, draw,
    texttable={2cm}, align=right] (tb1)
    {
    पुत्रः माता। & माता। \\
    putraḥ \\
    शिष्यः। \\
    śiṣyaḥ \\};

    \matrix at (tb1.north east) [matrix of nodes, nodes in empty cells, draw,
    texttable={2cm}, align=left, matrix anchor=north west, xshift=5mm] (tb2)
    {
    माता। \\
    mātā \\
    गुरुः। \\
    guruḥ \\};
\end{tikzpicture}
\end{document}

答案1

选项text depthtext height必须在这里使用。

\documentclass[a4paper]{article}

\usepackage[vmargin=30mm,hmargin=20mm]{geometry}

\usepackage{tikz}
\usetikzlibrary{matrix,calc}
\usepackage{babel}

\babelprovide[mapdigits,maparabic,import,main]{sanskrit}
\babelprovide[onchar=ids fonts]{english}
%rm : serif -- sf : sans -- tt : mono

\babelfont[*devanagari]{sf}{Shobhika}
%\babelfont{sf}{}
\babelfont[*devanagari]{rm}[Language=Default]{NotoSerifDevanagari}
\babelfont[english]{sf}{FreeSans}
\babelfont[english]{rm}{NotoSerif}
\defaultfontfeatures{Renderer=Harfbuzz}

\tikzset{
  texttable/.style={row sep=-\pgflinewidth, column sep=-\pgflinewidth,
         nodes={anchor=center,outer sep=0pt,draw,
         text width=#1,text depth=0.5ex,text height=12pt, font=\large,nodes={}}},
  ttold/.style={row sep=-\pgflinewidth, column sep=-\pgflinewidth,
         nodes={anchor=center, text width=#1,
         outer sep=0pt,draw,minimum height=2em, font=\large,}}}

\setlength{\parindent}{0pt}

\begin{document}
\begin{tikzpicture}
    \node at (0,0) [font=\Large,anchor=west] (title1) {Previous version:};
    \draw [ultra thick, yshift=-1mm] (title1.south west) -- (title1.south east);

    \matrix at (0,-7mm) [matrix of nodes, nodes in empty cells,
    matrix anchor=north west,
    ttold={2cm}, align=right] (tbold)
    {
    \node (a) {पुत्रः माता।}; & माता।\\
    \node (b) {putraḥ}; & mātā\\
    शिष्यः। & गुरुः\\
    śiṣyaḥ & guruḥ\\
    };
    \draw [thick,red] ($(a.south west)+(6mm,2mm)$) -- ++(60mm,0);
    \draw [thick,red] ($(b.south west)+(6mm,2mm)$) -- ++(60mm,0);

    \matrix at (tbold.north east) [matrix of nodes, nodes in empty cells,
    matrix anchor=north west,
    ttold={2cm}, align=right] (tb2)
    {
    माता। \\
    mātā \\
    गुरुः। \\
    guruḥ \\};

    \node at (.5\textwidth,0) [font=\Large,anchor=west] (title2) {New version:};
    \draw [ultra thick, yshift=-1mm] (title2.south west) -- (title2.south east);

    \matrix at (.5\textwidth,-7mm) [matrix of nodes, nodes in empty cells,
    matrix anchor=north west,
    texttable={2cm}, align=right] (tbnew)
    {
    \node (c) {पुत्रः माता।}; & माता।\\
    \node (d) {putraḥ}; & mātā\\
    शिष्यः। & गुरुः\\
    śiṣyaḥ & guruḥ\\
    };
    \draw [thick,red] ($(c.south west)+(6mm,2mm)$) -- ++(60mm,0);
    \draw [thick,red] ($(d.south west)+(6mm,2mm)$) -- ++(60mm,0);

    \matrix at (tbnew.north east) [matrix of nodes, nodes in empty cells,
    matrix anchor=north west,
    texttable={2cm}, align=right] (tb3)
    {
    माता।\\
    mātā\\
    गुरुः। \\
    guruḥ \\};
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容