Tikz 中的矩阵元素对齐

Tikz 中的矩阵元素对齐

我尝试将矩阵的元素左对齐,但没有成功。有什么想法吗?

\documentclass{beamer}
\usepackage{xcolor}
\definecolor{lava}{rgb}{0.81, 0.06, 0.13}
\definecolor{myblue}{rgb}{0.0, 0.30, 0.60}
\usepackage{tikz}
\usetikzlibrary{matrix}  


\begin{document}



\begin{frame}{xxxxx}
\underline{\textbf{Example}}
\begin{itemize}
\item[$\rightarrow$] Let's consider two systems of linear equations that correspond to the same coefficient matrix $\mathbf{A}$
\end{itemize}




\begin{tikzpicture}[>=stealth,thick,baseline]
   \tikzstyle{column 8}=[myblue]
    \matrix [matrix of math nodes,column/.style={anchor=base west},ampersand replacement=\&](A){ 
    3 x_1  \&+ 5x_2    \& -4x_3   \& = \&7\\
    - 3 x_1 \& -2x_2  \& +4x_3   \& = \&  -1\\
      6  x_1 \& +x_2   \& -8x_3    \& =\&   -4\\
   };
   \end{tikzpicture}


\end{frame}

\end{document}

答案1

您是否必须使用tikz来编写方程组(作为矩阵)?如果没有,您可以使用简单的array

\documentclass[table]{beamer}
\definecolor{lava}{rgb}{0.81, 0.06, 0.13}
\definecolor{myblue}{rgb}{0.0, 0.30, 0.60}

\begin{document}
\begin{frame}{xxxxx}
\underline{\textbf{Example}}
\begin{itemize}
\item[$\rightarrow$] Let's consider two systems of linear equations that correspond to the same coefficient matrix $\mathbf{A}$
\end{itemize}

\[\setlength\arraycolsep{1pt}
\begin{array}{rrr >{\color{myblue}}r}
  3 x_1 + & 5x_2 - & 4x_3 = &   7\\
- 3 x_1 - & 2x_2 + & 4x_3 = &  -1\\
  6 x_1 + &  x_2 - & 8x_3 = &  -4\\
\end{array}
\]
\end{frame}
\end{document}

在此处输入图片描述

答案2

要左对齐矩阵元素,您可以通过cells={anchor=west}或设置每个单元格的样式nodes={anchor=west}

\documentclass{beamer}
\usepackage{xcolor}
\definecolor{lava}{rgb}{0.81, 0.06, 0.13}
\definecolor{myblue}{rgb}{0.0, 0.30, 0.60}
\usepackage{tikz}
\usetikzlibrary{matrix}  


\begin{document}



\begin{frame}{xxxxx}
\underline{\textbf{Example}}
\begin{itemize}
    \item[$\rightarrow$] Let's consider two systems of linear equations that correspond to the same coefficient matrix $\mathbf{A}$
\end{itemize}



\centering
\begin{tikzpicture}[>=stealth,thick,baseline]
    \tikzstyle{column 8}=[myblue]
    \matrix [matrix of math nodes,ampersand replacement=\&,cells={anchor=west}](A){ 
        3 x_1  \&+ 5x_2    \& -4x_3   \& = \&7\\
        - 3 x_1 \& -2x_2  \& +4x_3   \& = \&  -1\\
          6  x_1 \& +x_2   \& -8x_3    \& =\&   -4\\
    };
\end{tikzpicture}


\end{frame}

\end{document}

在此处输入图片描述

相关内容