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}

여기에 이미지 설명을 입력하세요

관련 정보