如何在表格环境中将 tikzpicture 置于中心?

如何在表格环境中将 tikzpicture 置于中心?

我不知道如何让这个三角形和文字“等边三角形”在表格单元格中居中。目前,三角形紧贴左下角,我希望它位于框的中间。以下是代码:

\begin{center}
    \begin{tabular}{|c|c|}
        \hline
        \begin{tikzpicture} [scale = 0.5]
            % Draw the triangle
            \coordinate (O) at (0,0);
            \coordinate (A) at (5,0);
            \coordinate (B) at (2.5,4.33);
            \draw (O) -- (A) -- (B) -- cycle;

            %Draw the line tick marks
            \draw [line width = 0.5 pt] (2.5,-0.25) -- (2.5,0.25);
            \draw [line width = 0.5 pt] (1.5,2.021) -- (1,2.309);
            \draw [line width = 0.5 pt] (4,2.309) -- (3.5,2.021);

            %Draw the angles
            \tkzMarkAngle [size=0.8cm](B,A,O)
            \tkzMarkAngle [size=0.8cm](A,O,B)
            \tkzMarkAngle [size=0.8cm](O,B,A)

            %Tick the Angles
            \draw [line width = 0.5 pt] (2.5,3.25) -- (2.5,3.75);
            \draw [line width = 0.5 pt] (4.5,0.288675) -- (4.1,0.52);
            \draw [line width = 0.5 pt] (0.5,0.288) -- (0.9,0.52);

        \end{tikzpicture}
        & 
        \textbf{Equilateral} Triangle \\
        \hline

    \end{tabular}
\end{center}

这是当前输出:在此处输入图片描述

答案1

您可以将baseline的 设置为tikzpicture。这里有两个例子,一个将它设置为一个距离,另一个将它设置为与三角形重心处的幻影节点的底部重合,位于 的中心,tikzpicture或者只是使用\vcenter

\documentclass{article}
\usepackage{tkz-euclide}
\begin{document}
\begin{center}
    \begin{tabular}{|c|c|}
        \hline
        \begin{tikzpicture}[scale = 0.5,baseline=0.9cm]
            % Draw the triangle
            \coordinate (O) at (0,0);
            \coordinate (A) at (5,0);
            \coordinate (B) at (2.5,4.33);
            \draw (O) -- (A) -- (B) -- cycle;
            %Draw the line tick marks
            \draw [line width = 0.5 pt] (2.5,-0.25) -- (2.5,0.25);
            \draw [line width = 0.5 pt] (1.5,2.021) -- (1,2.309);
            \draw [line width = 0.5 pt] (4,2.309) -- (3.5,2.021);

            %Draw the angles
            \tkzMarkAngle [size=0.8cm](B,A,O)
            \tkzMarkAngle [size=0.8cm](A,O,B)
            \tkzMarkAngle [size=0.8cm](O,B,A)

            %Tick the Angles
            \draw [line width = 0.5 pt] (2.5,3.25) -- (2.5,3.75);
            \draw [line width = 0.5 pt] (4.5,0.288675) -- (4.1,0.52);
            \draw [line width = 0.5 pt] (0.5,0.288) -- (0.9,0.52);

        \end{tikzpicture}
        & 
        \textbf{Equilateral} Triangle \\
        \hline

    \end{tabular}
\end{center}
\begin{center}
    \begin{tabular}{|c|c|}
        \hline
        \begin{tikzpicture}[scale = 0.5,baseline={(X.base)}]
            % Draw the triangle
            \coordinate (O) at (0,0);
            \coordinate (A) at (5,0);
            \coordinate (B) at (2.5,4.33);
            \path (barycentric cs:O=1,A=1,B=1) node(X){\vphantom{X}};
            \draw (O) -- (A) -- (B) -- cycle;
            %Draw the line tick marks
            \draw [line width = 0.5 pt] (2.5,-0.25) -- (2.5,0.25);
            \draw [line width = 0.5 pt] (1.5,2.021) -- (1,2.309);
            \draw [line width = 0.5 pt] (4,2.309) -- (3.5,2.021);

            %Draw the angles
            \tkzMarkAngle [size=0.8cm](B,A,O)
            \tkzMarkAngle [size=0.8cm](A,O,B)
            \tkzMarkAngle [size=0.8cm](O,B,A)

            %Tick the Angles
            \draw [line width = 0.5 pt] (2.5,3.25) -- (2.5,3.75);
            \draw [line width = 0.5 pt] (4.5,0.288675) -- (4.1,0.52);
            \draw [line width = 0.5 pt] (0.5,0.288) -- (0.9,0.52);

        \end{tikzpicture}
        & 
        \textbf{Equilateral} Triangle \\
        \hline

    \end{tabular}
\end{center}
\begin{center}
    \begin{tabular}{|c|c|}
        \hline
        \begin{tikzpicture}[scale = 0.5,baseline={(X.base)}]
            % Draw the triangle
            \coordinate (O) at (0,0);
            \coordinate (A) at (5,0);
            \coordinate (B) at (2.5,4.33);          
            \draw (O) -- (A) -- (B) -- cycle;
            %Draw the line tick marks
            \draw [line width = 0.5 pt] (2.5,-0.25) -- (2.5,0.25);
            \draw [line width = 0.5 pt] (1.5,2.021) -- (1,2.309);
            \draw [line width = 0.5 pt] (4,2.309) -- (3.5,2.021);

            %Draw the angles
            \tkzMarkAngle [size=0.8cm](B,A,O)
            \tkzMarkAngle [size=0.8cm](A,O,B)
            \tkzMarkAngle [size=0.8cm](O,B,A)

            %Tick the Angles
            \draw [line width = 0.5 pt] (2.5,3.25) -- (2.5,3.75);
            \draw [line width = 0.5 pt] (4.5,0.288675) -- (4.1,0.52);
            \draw [line width = 0.5 pt] (0.5,0.288) -- (0.9,0.52);
            \path (current bounding box.center) node(X){\vphantom{X}};
        \end{tikzpicture}
        & 
        \textbf{Equilateral} Triangle \\
        \hline

    \end{tabular}
\end{center}
\begin{center}
    \begin{tabular}{|c|c|}
        \hline
        $\vcenter{\hbox{\begin{tikzpicture}[scale = 0.5]
            % Draw the triangle
            \coordinate (O) at (0,0);
            \coordinate (A) at (5,0);
            \coordinate (B) at (2.5,4.33);
            \draw (O) -- (A) -- (B) -- cycle;
            %Draw the line tick marks
            \draw [line width = 0.5 pt] (2.5,-0.25) -- (2.5,0.25);
            \draw [line width = 0.5 pt] (1.5,2.021) -- (1,2.309);
            \draw [line width = 0.5 pt] (4,2.309) -- (3.5,2.021);
            %Draw the angles
            \tkzMarkAngle [size=0.8cm](B,A,O)
            \tkzMarkAngle [size=0.8cm](A,O,B)
            \tkzMarkAngle [size=0.8cm](O,B,A)
            %Tick the Angles
            \draw [line width = 0.5 pt] (2.5,3.25) -- (2.5,3.75);
            \draw [line width = 0.5 pt] (4.5,0.288675) -- (4.1,0.52);
            \draw [line width = 0.5 pt] (0.5,0.288) -- (0.9,0.52);
        \end{tikzpicture}}}$
        & 
        \textbf{Equilateral} Triangle \\
        \hline

    \end{tabular}
\end{center}
\end{document}

在此处输入图片描述

相关内容