如何在 Tikz 节点和表格环境中对齐行

如何在 Tikz 节点和表格环境中对齐行

在附图中,您可以看到文本未正确对齐。最后它开始按要求对齐。抱歉,我无法再减少 MWE。由于序言很大,所以我会把它放在评论部分。我画了红线来显示文本应该如何对齐。

    \documentclass{article} \usepackage{setspace}\usepackage[left=1in,right=1in,top=1in,bottom=1in]{geometry} \usepackage{fontspec,xltxtra,xunicode}
\usepackage{fancyhdr} \usepackage{color} \usepackage[svgnames]{xcolor} \usepackage{cmll} \usepackage{tabularx,multicol,ulem,array} \usepackage{placeins} 
\usepackage{longtable}
\usepackage{tikz} \usepackage{pgf,pgffor}
\usetikzlibrary{calc} \pagestyle{fancy}
\usetikzlibrary{positioning,shapes,shadows,arrows}
\usetikzlibrary{fit,shapes.geometric}
\newcounter{nodemarkers}
\newcommand\circletext[1]{%
    \tikz[overlay,remember picture] 
        \node (marker-\arabic{nodemarkers}-a) at (0,1.5ex) {};%
    #1%
    \tikz[overlay,remember picture]
        \node (marker-\arabic{nodemarkers}-b) at (0,0){};%
    \tikz[overlay,remember picture,inner sep=2pt]
        \node[draw,ellipse,fit=(marker-\arabic{nodemarkers}-a.center) (marker-\arabic{nodemarkers}-b.center)] {};%
    \stepcounter{nodemarkers}%
}
\hfuzz=45pt
\newcommand\fb\FloatBarrier % to put float barriers
\setmainfont[Script=Devanagari]{Sanskrit2003}
\newcounter{nodecount}
\newcommand\tabnode[1]{\addtocounter{nodecount}{1} \tikz \node (\arabic{nodecount}) {#1};}
\tikzstyle{every picture}+=[remember picture,baseline]
\tikzstyle{every node}+=[inner sep=0pt,anchor=base,
minimum width=1.5cm,align=center,text depth=0.5ex,outer sep=1pt]
\tikzstyle{every path}+=[thick, rounded corners]
\newcommand{\nl}{\\[2mm]}
\begin{document}
.
\vspace{0.5cm} \\
\fb
\begin{table}[!htbp]
\begin{minipage}[b]{1\linewidth} 
\begin{tabular}{c c c c c}
& & \tabnode{}& \tabnode{}&  \tabnode{}\\
प्र० & \tabnode{पु० \nl स्त्री० } & \tabnode{स: \nl सा} & \tabnode{तौ \nl ते} &  \tabnode{ते \nl ता:} 
\end{tabular}
%    \hspace{2cm}
\begin{tabular}{l l c l}
& \tabnode{}& \tabnode{}&  \tabnode{} \\
प्र० & \tabnode{गच्छति \nl वदति \nl आगच्छति \nl प्रतिगच्छति \nl प्रत्यागच्छति \nl करोति \nl खादति \nl पिबति \nl अस्ति \nl भवति \nl उपविशति \nl तिष्ठति \nl उत्तिष्ठति \nl ददाति \nl गृह्णाति \nl जानाति} & \tabnode{ गच्छतः \nl वदतः \nl आगच्छतः \nl प्रतिगच्छतः \nl प्रत्यागच्छतः \nl कुरुतः \nl खादतः \nl पिबतः \nl स्तः \nl भवतः \nl उपविशतः \nl तिष्ठतः \nl उत्तिष्ठतः \nl दत्तः \nl गृह्णीतः \nl जानीतः} & \tabnode{ गच्छन्ति \nl वदन्ति \nl आगच्छन्ति \nl प्रतिगच्छन्ति \nl प्रत्यागच्छन्ति \nl कुर्वन्ति \nl खादन्ति \nl पिबन्ति \nl सन्ति \nl भवन्ति \nl उपविशन्ति \nl तिष्ठन्ति \nl उत्तिष्ठन्ति \nl ददति \nl गृह्णन्ति \nl जानन्ति} \\
& \tabnode{}& \tabnode{}&  \tabnode{} \\
\end{tabular}
\vspace{2cm}
 \caption{Make simple sentences by joining Nouns \& पठ् धातु forms}
\end{minipage}
\end{table}

\begin{tikzpicture}[overlay]
\draw [Green] (5.west) -- (1.north west) -- (1.north east) -- (5.south east) -- (5.south west) -- cycle;
\draw [red] (6.west) -- (2.north west) -- (2.north east) -- (6.south east) -- (6.south west) -- cycle;
\draw [blue] (7.west) -- (3.north west) -- (3.north east) -- (7.south east) -- (7.south west) -- cycle;

\draw [Green] (14.west) -- (8.north west) -- (8.north east) -- (14.south east) -- (14.south west) -- cycle;
\draw [red] (15.west) -- (9.north west) -- (9.north east) -- (15.south east) -- (15.south west) -- cycle;
\draw [blue] (16.west) -- (10.north west) -- (10.north east) -- (16.south east) -- (16.south west) -- cycle;

\path[-latex] (1.north) edge [bend left,Green] (8.north);
\path[-latex] (2.north) edge [bend left,red] (9.north);
\path[-latex] (3.north) edge [bend left,blue] (10.north);

\end{tikzpicture}
%\doublespacing
it is respectful to address everyone as "त्वम्" in order to address people who are older than you and who deserve respect forms of "भवत्" are used as shown in the image above. 
\end{document}

在此处输入图片描述

答案1

请原谅我的无知,但不知何故我无法找到正确的字体。所以我只能给出你的代码的矩阵版本,而无需编译它。我只是用替换了所有\nl内容\\并将它们放入矩阵节点中。我不确定大小是否兼容,但它应该让你知道如何处理它。有关此矩阵和单个条目的参考,请参阅我对问题的评论中的答案。

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{matrix}
\begin{document}
\begin{tikzpicture}
\matrix[matrix of nodes,draw=green,rounded corners] (mat1) {
गच्छति \\ वदति \\ आगच्छति \\ प्रतिगच्छति \\प्रत्यागच्छति \\ करोति \\ खादति \\पिबति \\ 
अस्ति \\ भवति \\उपविशति \\ तिष्ठति \\ उत्तिष्ठति \\ ददाति \\ गृह्णाति \\ जानाति\\
};
\matrix[matrix of nodes,draw=red,rounded corners] (mat2) at (3cm,0){
गच्छतः \\ वदतः \\ आगच्छतः \\ प्रतिगच्छतः \\ प्रत्यागच्छतः \\ कुरुतः \\ खादतः \\ पिबतः \\ स्तः \\ 
भवतः \\ उपविशतः \\ तिष्ठतः \\ उत्तिष्ठतः \\ दत्तः \\ गृह्णीतः \\ जानीतः \\
};
\matrix[matrix of nodes,draw=blue,rounded corners] (mat3) at (6cm,0){
गच्छतः \\ वदतः \\ आगच्छतः \\ प्रतिगच्छतः \\ प्रत्यागच्छतः \\ कुरुतः \\ खादतः \\ पिबतः \\ 
स्तः \\ भवतः \\ उपविशतः \\ तिष्ठतः \\ उत्तिष्ठतः \\ दत्तः \\ गृह्णीतः \\ जानीतः \\
};
\end{tikzpicture}
\end{document}

在此处输入图片描述

答案2

右侧的表格仅包含 3 行,其中 2 行几乎为空。您隐藏了宏中的行分隔符\tabnode。这

\tabnode{गच्छति \nl वदति \nl आगच्छति \nl प्रतिगच्छति \nl ... } \\

实际上是

\tabnode{गच्छति \\[2mm] वदति \\[2mm] आगच्छति \\[2mm] प्रतिगच्छति \\[2mm]... } \\

为了实现tabular处理您的对齐,请将以下内容\\删除:

\tabnode{गच्छति} \\ ...\tabnode{आगच्छति} ... \\

实际上,您\tabnode只需要几次引用,所以不要过度使用它。如果您想将所有单元格变成节点,那么节点矩阵会更好,正如 Jake 所评论的那样,但您只需要几个引用点。

相关内容