tikz中矩陣內外不同元素的對齊

tikz中矩陣內外不同元素的對齊

我在將以下 tikzpicture 的不同元素放置在正確的位置時遇到問題。我認為問題的出現​​是因為矩陣內元素的寬度不同。

\documentclass[10pt]{article}

\usepackage[margin=0.75in]{geometry}

\usepackage{tikz}
  \usetikzlibrary{matrix,decorations.pathreplacing,calc,graphs,decorations.markings,intersections,positioning}
\usepackage{mathtools}
\usepackage{amsmath}
\usepackage{amsthm} %for proof 

\begin{document}

\[X=
\begin{tikzpicture}[baseline=-0.5ex]
\matrix [matrix of math nodes,left delimiter=(,right delimiter=),row sep=1cm,column sep=1cm] (m) {
0&\frac{p^{I}_{1S}.F^{-1}_{1S}(y^{f}_{2S}+y^{I}_{2S})}{p^{f}_{2S}.y^{f}_{2S}+p^{I}_{2S}.y^{I}_{2S}}&0&0 \\
\frac{p^{I}_{2S}.F^{-1}_{2S}(y^{f}_{1S}+y^{I}_{1S})}{p^{f}_{1S}.y^{f}_{1S}+p^{I}_{1S}.y^{I}_{1S}}&0&0&0 \\
0&0&0&\frac{p^{I}_{1L}.F^{-1}_{1L}(y^{f}_{2L}+y^{I}_{2L})}{p^{f}_{2L}.y^{f}_{2L}+p^{I}_{2L}.y^{I}_{2L}} \\
0&0&\frac{p^{I}_{1L}.F^{-1}_{1L}(y^{f}_{2L}+y^{I}_{2L})}{p^{f}_{2L}.y^{f}_{2L}+p^{I}_{2L}.y^{I}_{2L}}&0 \\};
\draw[dashed] ($0.5*(m-1-2.north east)+0.5*(m-1-3.north west)$) --
      ($0.5*(m-4-2.south east)+0.5*(m-4-3.south west)$);
\draw[dashed] ($0.5*(m-2-1.south west)+0.5*(m-3-1.north west)$) --
      ($0.5*(m-2-4.south east)+0.5*(m-3-4.north east)$);
\node[above=12pt of m-1-1] (top-1) {1};
\node[above=12pt of m-1-2] (top-2) {2};
\node[above=12pt of m-1-3] (top-3) {1};
\node[above=12pt of m-1-4] (top-4) {2};

\node[left=12pt of m-1-1] (left-1) {1};
\node[left=12pt of m-2-1] (left-2) {2};
\node[left=12pt of m-3-1] (left-3) {1};
\node[left=12pt of m-4-1] (left-4) {2};

\node[rectangle,above delimiter=\{] (del-top-1) at ($0.5*(top-1.south) +0.5*(top-2.south)$) {\tikz{\path (top-1.south west) rectangle (top-2.north east);}};
\node[above=10pt] at (del-top-1.north) {$S$};
\node[rectangle,above delimiter=\{] (del-top-2) at ($0.5*(top-3.south) +0.5*(top-4.south)$) {\tikz{\path (top-3.south west) rectangle (top-4.north east);}};
\node[above=10pt] at (del-top-2.north) {$L$};

\node[rectangle,left delimiter=\{] (del-left-1) at ($0.5*(left-1.east) +0.5*(left-2.east)$) {\tikz{\path (left-1.north east) rectangle (left-2.south west);}};
\node[left=10pt] at (del-left-1.west) {$S$};
\node[rectangle,left delimiter=\{] (del-left-2) at ($0.5*(left-3.east) +0.5*(left-4.east)$) {\tikz{\path (left-3.north east) rectangle (left-4.south west);}};
\node[left=10pt] at (del-left-2.west) {$L$};

\end{tikzpicture}
\]

\end{document}

答案1

像這樣的東西。您需要在選項中定義節點的大小。

nodes={anchor=center,minimum width=3cm,minimum height=2cm}

在此輸入影像描述

程式碼

\documentclass[10pt]{article}

\usepackage[margin=0.75in]{geometry}

\usepackage{tikz}
  \usetikzlibrary{matrix,decorations.pathreplacing,calc,graphs,decorations.markings,intersections,positioning}
\usepackage{mathtools}
\usepackage{amsmath}
\usepackage{amsthm} %for proof 

\begin{document}

\[X=
\begin{tikzpicture}[baseline=-0.5ex]
\matrix [matrix of math nodes,left delimiter=(,right delimiter=),row sep=1cm,column sep=1cm,
nodes={anchor=center,minimum width=3cm,minimum height=2cm}
] (m) {
0&\frac{p^{I}_{1S}.F^{-1}_{1S}(y^{f}_{2S}+y^{I}_{2S})}{p^{f}_{2S}.y^{f}_{2S}+p^{I}_{2S}.y^{I}_{2S}}&0&0 \\
\frac{p^{I}_{2S}.F^{-1}_{2S}(y^{f}_{1S}+y^{I}_{1S})}{p^{f}_{1S}.y^{f}_{1S}+p^{I}_{1S}.y^{I}_{1S}}&0&0&0 \\
0&0&0&\frac{p^{I}_{1L}.F^{-1}_{1L}(y^{f}_{2L}+y^{I}_{2L})}{p^{f}_{2L}.y^{f}_{2L}+p^{I}_{2L}.y^{I}_{2L}} \\
0&0&\frac{p^{I}_{1L}.F^{-1}_{1L}(y^{f}_{2L}+y^{I}_{2L})}{p^{f}_{2L}.y^{f}_{2L}+p^{I}_{2L}.y^{I}_{2L}}&0 \\};
\draw[dashed] ($0.5*(m-1-2.north east)+0.5*(m-1-3.north west)$) --
      ($0.5*(m-4-2.south east)+0.5*(m-4-3.south west)$);
\draw[dashed] ($0.5*(m-2-1.south west)+0.5*(m-3-1.north west)$) --
      ($0.5*(m-2-4.south east)+0.5*(m-3-4.north east)$);
\node[above=12pt of m-1-1] (top-1) {1};
\node[above=12pt of m-1-2] (top-2) {2};
\node[above=12pt of m-1-3] (top-3) {1};
\node[above=12pt of m-1-4] (top-4) {2};

\node[left=12pt of m-1-1] (left-1) {1};
\node[left=12pt of m-2-1] (left-2) {2};
\node[left=12pt of m-3-1] (left-3) {1};
\node[left=12pt of m-4-1] (left-4) {2};

\node[yshift=-2cm,rectangle,above delimiter=\{] (del-top-1) at ($0.5*(top-1.south) +0.5*(top-2.south)$) {\tikz{\path (top-1.south west) rectangle (top-2.north east);}};
\node[above=10pt] at (del-top-1.north) {$S$};
\node[yshift=-2cm,rectangle,above delimiter=\{] (del-top-2) at ($0.5*(top-3.south) +0.5*(top-4.south)$) {\tikz{\path (top-3.south west) rectangle (top-4.north east);}};
\node[above=10pt] at (del-top-2.north) {$L$};

\node[rectangle,left delimiter=\{] (del-left-1) at ($0.5*(left-1.east) +0.5*(left-2.east)$) {\tikz{\path (left-1.north east) rectangle (left-2.south west);}};
\node[left=10pt] at (del-left-1.west) {$S$};
\node[rectangle,left delimiter=\{] (del-left-2) at ($0.5*(left-3.east) +0.5*(left-4.east)$) {\tikz{\path (left-3.north east) rectangle (left-4.south west);}};
\node[left=10pt] at (del-left-2.west) {$L$};
\end{tikzpicture}
\]

\end{document}

相關內容