Tikz Table 自动枚举

Tikz Table 自动枚举

我在 Tikz 中有一个表,其中第一列是连续枚举,即

\documentclass[12pt,twoside]{report}
\usepackage{lmodern}
\usepackage[utf8]{inputenc}
\usepackage{mathtools}
\usepackage{tikz}
\usetikzlibrary{matrix,shadings,arrows,decorations.markings,decorations.pathmorphing}
\tikzset{
    table/.style={
        matrix of nodes,
        row sep=-\pgflinewidth,
        column sep=-\pgflinewidth,
        nodes={
            rectangle,
            draw=black,
            align=center,
                        text width=10em,
                        fill=gray!10,
                   },
                        %baseline={([yshift=-0.5ex]current bounding box.center)},
        %minimum height=1.0em,
        %text depth=0.2em,
        %text height=0.8em,
                %text centered,
        nodes in empty cells,
                row 1/.style={nodes={fill=black, text=white, font=\bfseries}},
                row 2/.style={nodes={text height=3.3ex}},
            }
        }


\begin{document}

Hello World...
\begin{table}
\centering
\begin{tikzpicture}
\matrix[table, ampersand replacement=\&] (TabA1)
{
1 \& A2 \& A3 \\
2 \& $10^{2^{3^{4^{5}}}}$ \& B3 \\
3 \& A2 \& A3 \\
4 \& A2 \& A3 \\
5 \& A2 \& A3 \\
6 \& A2 \& A3 \\
7 \& A2 \& A3 \\
8 \& A2 \& A3 \\
};
\end{tikzpicture}
\caption{Glossary}
\label{tabA1}
\end{table}


\end{document}

如何自动完成?我猜是使用计数器,还是 tikz 中有一个非常简单的解决方案?

答案1

您可以为第一列添加样式:

column 1/.style={nodes={node contents={\the\pgfmatrixcurrentrow}}}

请注意,第一列中的节点不再接受附加内容。

完整 MWE:

\documentclass[12pt,twoside]{report}
\usepackage{lmodern}
\usepackage[utf8]{inputenc}
\usepackage{mathtools}
\usepackage{tikz}
\usetikzlibrary{matrix,shadings,arrows,decorations.markings,decorations.pathmorphing}
\tikzset{
    table/.style={
        matrix of nodes,
        row sep=-\pgflinewidth,
        column sep=-\pgflinewidth,
        nodes={
            rectangle,
            draw=black,
            align=center,
                        text width=10em,
                        fill=gray!10,
                   },
                        %baseline={([yshift=-0.5ex]current bounding box.center)},
        %minimum height=1.0em,
        %text depth=0.2em,
        %text height=0.8em,
                %text centered,
        nodes in empty cells,
                row 1/.style={nodes={fill=black, text=white, font=\bfseries}},
                row 2/.style={nodes={text height=3.3ex}},
                column 1/.style={nodes={node contents={\the\pgfmatrixcurrentrow}}},
            }
        }


\begin{document}

Hello World...
\begin{table}
\centering
\begin{tikzpicture}
\matrix[table, ampersand replacement=\&] (TabA1)
{
 \& A2 \& A3 \\
 \& $10^{2^{3^{4^{5}}}}$ \& B3 \\
 \& A2 \& A3 \\
 \& A2 \& A3 \\
 \& A2 \& A3 \\
 \& A2 \& A3 \\
 \& A2 \& A3 \\
 \& A2 \& A3 \\
};
\end{tikzpicture}
\caption{Glossary}
\label{tabA1}
\end{table}


\end{document}

相关内容