tikzpicture 矩陣環境中的垂直線分隔矩陣條目?

tikzpicture 矩陣環境中的垂直線分隔矩陣條目?

在tikzpicture矩陣環境中,如何製作一條完美的垂直線作為方陣中的線來分隔左側的Cc和G以及右側的D和H?

該線最好完美地設置在左側的 Cc 和 G 以及右側的 D 和 H 之間。

如果可能的話,我想堅持使用 tikzpicture 矩陣環境。

感謝您的任何建議/意見。

這是我失敗的嘗試。 在此輸入影像描述

這是我的特克斯代碼:

\documentclass[10pt,border=3mm,tikz]{standalone}
\usetikzlibrary{matrix}

    \usepackage{amsmath, amsthm, amssymb,mathtools}
    
    
    \begin{document}
    
    
    \begin{tikzpicture}
    \matrix[matrix of math nodes,inner sep=1pt,row sep=1em,column sep=1em] (M)
    {
     & A &  B & Cc & D \\
      & E &  F & G & H\\
    }
    ;
    \draw[ ->] (M-1-2.east) -- (M-1-3.west) node[midway,above,pos=0.3]{\,\tiny ab};
    \draw[ ->] (M-1-3.east) -- (M-1-4.west) node[midway,above,pos=0.3]{\,\tiny bc};
    \draw[-] (M-1-4.north east) -- (M-2-4.south east);
    \end{tikzpicture}
    
    
    \end{document}

答案1

由於 Cc 和 G 沒有右對齊,而 D 和 H 或多或少是左對齊的,因此不可能使其既垂直又位於 Cc 和 D 之間以及 G 和 H 之間,而不違反以下定律:物理,這涉及到一個項目,無法在SE 帖子中解決。相反,我在尋找中點時以Cc和D為參考點,以G為較低點。計算中不使用 H。

您可以使用該calc庫找到兩個頂部節點之間的中間點,建立一個標記座標,並在建立到底部的線時使用該標記來保持水平位置。

調整線

\documentclass[10pt,border=3mm,tikz]{standalone}
\usetikzlibrary{matrix,calc}
\usepackage{amsmath, amsthm, amssymb,mathtools}
\begin{document}
\begin{tikzpicture}
  \matrix[matrix of math nodes,inner sep=1pt,row sep=1em,column sep=1em] (M)
  {
    & A &  B & Cc & D \\
    & E &  F & G & H\\
  }
  ;
  \draw[ ->] (M-1-2.east) -- (M-1-3.west) node[midway,above,pos=0.3]{\,\tiny ab};
  \draw[ ->] (M-1-3.east) -- (M-1-4.west) node[midway,above,pos=0.3]{\,\tiny bc};
  \draw[-] ($(M-1-4.north east)!.5!(M-1-5.north west)$) coordinate (a) -- (a |- M-2-4.south);
\end{tikzpicture}
\end{document}

相關內容