如何將「L」和「R」精確地放在 tikz 行的中間?

如何將「L」和「R」精確地放在 tikz 行的中間?

作為我上一個問題的後續問題。如果我有下面的圖表:

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

在此輸入影像描述

相關內容