作为我上一个问题的后续问题。如果我有以下图表:
\documentclass{article}
\usepackage{graphicx} % Required for inserting images
\usepackage{tikz}
\usetikzlibrary{positioning}
\usepackage[margin=2.625cm]{geometry}
\usepackage{subcaption}
\begin{document}
\begin{tikzpicture}
\fill (1.5,1.5) circle [radius=0.05] node[above, yshift=-0.03cm, font=\small]{2} ;
\draw[<-, line width=0.3pt, >=stealth] (0.7,0.0) -- (1.5,1.5) node[xshift=-0.4cm,
yshift=-0.5cm, font=\tiny]{L};
\draw[<-, line width=0.3pt, >=stealth] (1.5,1) -- (1.5,1.5) node[xshift=0.4cm, yshift=-0.13cm,
font=\tiny]{R};
\fill (1.5,1) circle [radius=0.05] node[above, xshift=0.1cm, yshift=-0.03cm, font=\small]{3};
\draw[<-, line width=0.3pt, >=stealth] (0.7,0.0) -- (1.5,1) node[xshift=-0.2cm, yshift=-0.1cm,
font=\tiny]{L};
\draw[<-, line width=0.3pt, >=stealth] (2.3,1) -- (1.5,1) node[xshift=0.35cm, yshift=0.1cm, font=\tiny]{R};
\fill (2.3,1) circle [radius=0.05] node[above, yshift=-0.03cm, font=\small]{4};
\draw[<-, line width=0.3pt, >=stealth] (2.3,0.0) -- (2.3,1) node[xshift=0.1cm, yshift=-0.4cm, font=\tiny]{L};
\draw[<-, line width=0.3pt, >=stealth] (1.5,1.5) -- (2.3,1) node[above, xshift=-0.9cm, yshift=0cm, font=\tiny]{R};
\fill (1.5,0.5) circle [radius=0.05] node[above, xshift=0.1cm, yshift=-0.03cm, font=\small]{5};
\draw[<-, line width=0.3pt, >=stealth] (0.7,0)-- (1.5,0.5) node[xshift=-0.3cm, yshift=-0.05cm, font=\tiny]{L};
\draw[<-, line width=0.3pt, >=stealth] (1.5,1) -- (1.5,0.5) node[pos=0.5, font=\tiny]{R};
\end{tikzpicture}
\end{document}
我如何将“L”和“R”精确地放在行的中间?尝试使用 xshift 和 yshift 来做到这一点真的很麻烦。
答案1
您必须指定路径上的节点,而不是路径末尾的节点,我为倾斜的链接添加了中间和倾斜
我会让你改进这个代码
\documentclass{article}
\usepackage{graphicx} % Required for inserting images
\usepackage{tikz}
\usetikzlibrary{positioning}
\usepackage[margin=2.625cm]{geometry}
\usepackage{subcaption}
\begin{document}
\begin{tikzpicture}[scale=3]
\fill (1.5,1.5) circle [radius=0.05] node[above, yshift=-0.03cm, font=\small]{2} ;
\draw[<-, line width=0.3pt, >=stealth] (0.7,0.0) --node[midway,sloped, above,
font=\tiny]{L} (1.5,1.5) ;
\draw[<-, line width=0.3pt, >=stealth] (1.5,1) --node[midway,right,
font=\tiny]{R} (1.5,1.5) ;
\fill (1.5,1) circle [radius=0.05] node[above, xshift=0.1cm, yshift=-0.03cm, font=\small]{3};
\draw[<-, line width=0.3pt, >=stealth] (0.7,0.0) --node[midway,sloped, above,
font=\tiny]{L} (1.5,1) ;
\draw[<-, line width=0.3pt, >=stealth] (2.3,1) --node[midway,above, font=\tiny]{R} (1.5,1) ;
\fill (2.3,1) circle [radius=0.05] node[above, yshift=-0.03cm, font=\small]{4};
\draw[<-, line width=0.3pt, >=stealth] (2.3,0.0) -- node[midway,right, font=\tiny]{L}(2.3,1);
\draw[<-, line width=0.3pt, >=stealth,brown] (1.5,1.5) -- node[above,sloped,midway, font=\tiny]{R}(2.3,1) ;
\fill (1.5,0.5) circle [radius=0.05] node[above, xshift=0.1cm, yshift=-0.03cm, font=\small]{5};
\draw[<-, line width=0.3pt, >=stealth,blue] (0.7,0)-- node[midway,above,sloped, font=\tiny]{L}(1.5,0.5) ;
\draw[<-, line width=0.3pt, >=stealth,red] (1.5,1) -- node[pos=0.5, right,font=\tiny]{R} (1.5,0.5) ;
\end{tikzpicture}
\end{document}