如何在 tikz 格子图中的线上放置标记

如何在 tikz 格子图中的线上放置标记

我有一个菱形格子的 tikz 图(例如,一个群的子群)。我如何在这个菱形的两个相对侧放置标记?这些标记看起来类似于我们通常放置在全等三角形两侧的等号符号。这是我目前拥有的代码:

\begin{center}
\begin{tikzpicture}[scale=1.5,auto]
\node (AcapB) at (1,1) {$A \cap B$};
\node (A) at (0,2) {$A$};
\node (B) at (2,2) {$B$};
\node (G) at (1,3) {$G$};

\path[-]
(AcapB) edge (A)
(AcapB) edge (B)
(A) edge (G)
(B) edge (G)
;
\end{tikzpicture}
\end{center}

答案1

\documentclass[tikz]{standalone}

\begin{document}
\begin{tikzpicture}[scale=1.5,auto]
\node (AcapB) at (1,1) {$A \cap B$};
\node (A) at (0,2) {$A$};
\node (B) at (2,2) {$B$};
\node (G) at (1,3) {$G$};

\path[-]
(AcapB) edge node[midway,sloped, rotate=90,anchor=center] {$=$}(A) 
(AcapB) edge node[midway,sloped, rotate=90,anchor=center] {$=$} (B)
(A) edge node[midway,sloped, rotate=90,anchor=center] {$=$} (G)
(B) edge node[midway,sloped, rotate=90,anchor=center] {$=$} (G)
;
\end{tikzpicture}
\end{document}

在此处输入图片描述

您也可以定义一种风格:

\tikzset{mymark/.style={midway,sloped, rotate=90,anchor=center}
    }

代码:

\documentclass[tikz]{standalone}
\tikzset{mymark/.style={midway,sloped, rotate=90,anchor=center}
}

\begin{document}
\begin{tikzpicture}[scale=1.5,auto]
\node (AcapB) at (1,1) {$A \cap B$};
\node (A) at (0,2) {$A$};
\node (B) at (2,2) {$B$};
\node (G) at (1,3) {$G$};

\path[-]
(AcapB) edge node[mymark] {$=$}(A) 
(AcapB) edge node[mymark] {$=$} (B)
(A) edge node[mymark] {$=$} (G)
(B) edge node[mymark] {$=$} (G)
;
\end{tikzpicture}
\end{document}

答案2

使用 PSTricks 只是为了好玩!

\documentclass[preview,border=12pt,12pt]{standalone}
\usepackage{pst-node}
\begin{document}
\nointerlineskip
$
\begin{psmatrix}[rowsep=2cm,colsep=2cm]
    & G\\
A & & B\\
& A\cap B
\end{psmatrix}
\psset{nodesep=3pt,nrot=:U}
\ncline{1,2}{2,1}\ncput{\|}
\ncline{1,2}{2,3}\ncput{\|}
\ncline{3,2}{2,1}\ncput{\|}
\ncline{3,2}{2,3}\ncput{\|}
$
\end{document}

在此处输入图片描述

节省更多按键

\documentclass[preview,border=12pt,12pt]{standalone}
\usepackage{pst-node}
\def\X#1#2{\ncline{#1}{#2}\ncput{\|}}

\begin{document}
\nointerlineskip
$
\psmatrix[rowsep=2,colsep=2]
    & G\\
A & & B\\
& A\cap B
\endpsmatrix
\psset{nodesep=3pt,nrot=:U}
\X{1,2}{2,1}\X{1,2}{2,3}\X{3,2}{2,1}\X{3,2}{2,3}
$
\end{document}

相关内容