tikz 行の真ん中に「L」と「R」を正確に配置するにはどうすればよいですか?

tikz 行の真ん中に「L」と「R」を正確に配置するにはどうすればよいですか?

前回の質問の続きです。次のグラフがあったとします。

\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}

ここに画像の説明を入力してください

関連情報