tikz 节点中标签的对齐

tikz 节点中标签的对齐

请考虑以下示例。

\documentclass[12pt]{standalone}
\usepackage{tikz}
\usepackage{fontspec}
\usetikzlibrary{decorations.text}
\usetikzlibrary{positioning,decorations.pathreplacing,calc}
\usetikzlibrary{decorations.pathreplacing,calligraphy}
\begin{document}
\begin{tikzpicture}
\draw[help lines,step=5mm,gray!20] (-3,-2) grid (4,3);
\draw (-2,-1) -- (2,-1);
\draw (-2,2) -- (2,2);
\draw (-2,2) -- (-2,-1) node[midway, sloped, below] {\footnotesize subalterns};
\draw (2,2) -- (2,-1) node[midway, sloped, above] {\footnotesize subalterns};
\node [above left] at (-2,2) {Every};
\node [above right] at (2,2) {No};
\node [below left] at (-2,-1) {Some};
\draw (-2,2) -- (0,0.5) node[anchor=mid, midway, sloped] {\footnotesize contradic};
\draw (0,0.5) -- (2,-1) node[midway, sloped] {\footnotesize tories};
\draw (-2,-1) -- (0,0.5) node[anchor=mid, midway, sloped] {\footnotesize contradic};
\draw (0,0.5) -- (2,2) node[anchor=mid, midway, sloped] {\footnotesize tories};
\node [below right, text width=1.9cm] at (2,-1) {Not every or not any};
\draw[decoration={calligraphic brace,mirror, amplitude=5pt}, decorate, line width=1pt] (-2.7,-1.5) node {} -- (2.7,-1.5);
\draw[decoration={calligraphic brace, amplitude=5pt}, decorate, line width=1pt] (-2.7,2.5) node {} -- (2.7,2.5);
\node at (0, 2.9) {Contraries};
\node at (0, -1.9) {Subcontraries};
\end{tikzpicture}
\end{document}

输出

如您所见,标签存在两个问题(我认为它们是相互关联的):a) 标签“Every”和“No”彼此不对齐(奇怪的是,如果我输入“No (...)”而不是“No”,它们就会对齐);b) 对角线上的标签(我想在没有线的情况下显示)似乎没有居中,即它们与两条对角线相交点的距离不相同(0,0.5)。您有什么建议吗?提前谢谢您!

答案1

这是因为这些节点的深度和高度不同。解决这个问题的一种方法是同步所有节点的深度和高度,可以通过添加

nodes={text depth=0.25ex,text height=1.25ex}

到 的选项tikzpicture

\documentclass[12pt]{standalone}
\usepackage{tikz}
\usepackage{fontspec}
\usetikzlibrary{decorations.text}
\usetikzlibrary{positioning,decorations.pathreplacing,calc}
\usetikzlibrary{decorations.pathreplacing,calligraphy}
\begin{document}
\begin{tikzpicture}[nodes={text depth=0.25ex,text height=1.25ex}]
\draw[help lines,step=5mm,gray!20] (-3,-2) grid (4,3);
\draw (-2,-1) -- (2,-1);
\draw (-2,2) -- (2,2);
\draw (-2,2) -- (-2,-1) node[midway, sloped, below] {\footnotesize subalterns};
\draw (2,2) -- (2,-1) node[midway, sloped, above] {\footnotesize subalterns};
\node [above left] at (-2,2) {Every};
\node [above right] at (2,2) {No};
\node [below left] at (-2,-1) {Some};
\draw (-2,2) -- (0,0.5) node[anchor=mid, midway, sloped] {\footnotesize contradic};
\draw (0,0.5) -- (2,-1) node[midway, sloped] {\footnotesize tories};
\draw (-2,-1) -- (0,0.5) node[anchor=mid, midway, sloped] {\footnotesize contradic};
\draw (0,0.5) -- (2,2) node[anchor=mid, midway, sloped] {\footnotesize tories};
\node [below right, text width=1.9cm] at (2,-1) {Not every or not any};
\draw[decoration={calligraphic brace,mirror, amplitude=5pt}, decorate, line width=1pt] (-2.7,-1.5) node {} -- (2.7,-1.5);
\draw[decoration={calligraphic brace, amplitude=5pt}, decorate, line width=1pt] (-2.7,2.5) node {} -- (2.7,2.5);
\node at (0, 2.9) {Contraries};
\node at (0, -1.9) {Subcontraries};
\end{tikzpicture}
\end{document}

在此处输入图片描述

为了删除节点所在的线,您可以按照 Rmano 的建议添加fill=white。由于路径的长度都相同,因此您可以使用pos=0.15,例如,并拨动适当的锚点将它们放置在相同的距离之外。我建议使用符号坐标,这样您可以更轻松地进行调整。

\documentclass[12pt]{standalone}
\usepackage{tikz}
\usepackage{fontspec}
\usetikzlibrary{positioning,decorations.pathreplacing,calligraphy}
\begin{document}
\begin{tikzpicture}[nodes={text depth=0.25ex,text height=1.25ex}]
 \draw[help lines,step=5mm,gray!20] (-3,-2) grid (4,3);
 \draw (-2,-1) coordinate (BL) node [below left]{Some} -- 
  (2,-1) coordinate (BR) node[below right, text width=1.9cm]  {Not every or not any} --
  (2,2) coordinate (TR) node[above right] {No} -- 
  (-2,2) coordinate (TL) node [above left] {Every}
  -- cycle (0,0.5) coordinate (M);
 \begin{scope}[font=\footnotesize]
  \path (TL) -- (BL) node[midway, sloped, below] {subalterns};
  \path (TR) -- (BR) node[midway, sloped, above] {subalterns};
  \begin{scope}[nodes={pos=0.15, sloped,fill=white}]
   \draw (M) -- (TL) node[anchor=east] {contradic};
   \draw (M) -- (BR) node[anchor=west] {tories};
   \draw (M) -- (BL) node[anchor=east] {contradic};
   \draw (M) -- (TR) node[anchor=west] {tories};
  \end{scope}
 \end{scope}
 \draw[decoration={calligraphic brace,mirror, amplitude=5pt}, decorate, line width=1pt] (-2.7,-1.5)  -- (2.7,-1.5);
 \draw[decoration={calligraphic brace, amplitude=5pt}, decorate, line width=1pt]
 (-2.7,2.5)  -- (2.7,2.5);
 \node at (0, 2.9) {Contraries};
 \node at (0, -1.9) {Subcontraries};
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容