Tikz:如何将文本放在指定位置?

Tikz:如何将文本放在指定位置?

我该如何修正\node紧接在前的 3 行表达式,\end{tikzpicture}以便指示的“标签”a、b、c 靠近尾随注释中描述的点?

\documentclass[tikz,border=10pt]{standalone}
\usetikzlibrary{arrows.meta,decorations.markings,plotmarks}

\begin{document}

\begin{tikzpicture}[
    middlearrow/.style 2 args={
        decoration={markings, mark=at position 0.5 with {\arrow{>}, \node[#1]{#2};}
        },
        postaction={decorate}
    },
]
\draw (0,0) rectangle (4,4);
\draw (0,4) -- (2, 0) -- (4, 4);
\draw[middlearrow={below}{$\sigma$}]    (0,0) -- (2,0);
\draw[middlearrow={below}{$\sigma$}]    (4,0) -- (2,0);
\draw[middlearrow={above}{$\nu_{x}$}]   (0,4) -- (4,4);
\draw[middlearrow={right}{$\sigma$}]    (0,4) -- (2,0);
\draw[middlearrow={right}{$\sigma$}]    (4,4) -- (2,0);
(0,0) \node[anchor=north east] {$x$};
(4,0) \node[anchor=north west] {$a$};  % want it near corner (4, 0)
(0,2) \node[anchor=east]{$b$};        % want it near point (0, 2)
(4,2) \node[anchor=west]{$c$};        % want it near point (4, 2)
\end{tikzpicture}

\end{document}

三处标签放错

请温柔一点!我意识到这是一个非常基本问题。但我是 TikZ 的初学者,仍在尝试理解其奇怪的几种不同语法方案的混合以及令人眼花缭乱的命令、操作和选项。

笔记:如果您能建议对代码进行任何简化,我也会很感激!

答案1

要将节点放置在某个坐标处,您可以使用\node

\node at (0,0) {origin};

或者\draw

\draw (0,0) node {origin};

因此最后四行必须重写。

\draw (0,0) node[anchor=north east] {$x$}
      (4,0) node[anchor=north west] {$a$}  % want it near corner (4, 0)
      (0,2) node[anchor=east]{$b$}        % want it near point (0, 2)
      (4,2) node[anchor=west]{$c$};        % want it near point (4, 2)

在此处输入图片描述

使用以下代码也可以获得相同的结果

\documentclass[tikz,border=10pt]{standalone}
\usetikzlibrary{decorations.markings}

\begin{document}
\begin{tikzpicture}[
    middlearrow/.style 2 args={
        decoration={markings, mark=at position 0.5 with {\arrow{>}, \node[#1]{#2};}
        },
        postaction={decorate}
    },
]
\draw[middlearrow={below}{$\sigma$}]    (0,0)node[anchor=north east]{$x$} -- (2,0);
\draw[middlearrow={below}{$\sigma$}]    (4,0)node[anchor=north west]{$a$} -- (2,0);
\draw[middlearrow={above}{$\nu_{x}$}]   (0,4) -- (4,4);
\draw[middlearrow={right}{$\sigma$}]    (0,4) -- (2,0);
\draw[middlearrow={right}{$\sigma$}]    (4,4) -- (2,0);
\draw (0,0) -- (0,4) node[midway,left]{$b$};
\draw (4,0) -- (4,4) node[midway,right]{$c$};
\end{tikzpicture}
\end{document}

相关内容