# Adjust position of node label

In the MWE below, how can I get to adjust the position of the node labels? Note that the nodes are defined by

dot/.style={circle,inner sep=1pt,fill,label={#1},name=#1}


but I cannot figure out how to keep the same setting will being able to adjust the positioning of the label. For example, something like dot=M,left or dot=M,right. The original source of the code is gotten from https://tex.stackexchange.com/a/21759/10898

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc}

\tikzset{
right angle quadrant=1, % Make sure it is set, even if not called explicitly
right angle length/.code={\def\rightanglelength{#1}},   % Length of symbol
right angle length=2ex, % Make sure it is set...
right angle symbol/.style n args={3}{
insert path={
let \p0 = ($(#1)!(#3)!(#2)$) in     % Intersection
let \p1 = ($(\p0)!\quadranta*\rightanglelength!(#3)$), % Point on base line
\p2 = ($(\p0)!\quadrantb*\rightanglelength!(#2)$) in % Point on perpendicular line
let \p3 = ($(\p1)+(\p2)-(\p0)$) in  % Corner point of symbol
(\p1) -- (\p3) -- (\p2)
}
}
}

\begin{document}
\begin{tikzpicture}[dot/.style={circle,inner sep=1pt,fill,label={#1},name=#1},
extended line/.style={shorten >=-#1,shorten <=-#1},
extended line/.default=1cm]

\node [dot=L] at (1,0) {};
\node [dot=M] at (4,0) {};
\node [dot=N] at (4,5) {};

\draw [extended line=0.5cm] (L) -- (M) node [below,midway] {3};
\draw [extended line=0.5cm] (L) -- (N) node [above left,midway] {6};
\draw [extended line=0.5cm] ($(L)!(N)!(M)$) -- (N) node [right,midway] {$x$};
\draw [red,right angle symbol={M}{N}{L}];

\end{tikzpicture}
\end{document}


Note, what am looking for is to move the N to the right, L to lower left and M to lower right.

Syntax for labels is

/tikz/label=[<options>]<angle>:<text>


where <angle> helps you to place labels around its position. In your case, you just need to include this second parameter in dot/.style definitition. With something like

dot/.style 2 args={circle,inner sep=1pt,fill,label={#2:#1},name=#1},


you can use \node [dot={L}{below}] at (1,0) {};. As usual in TiKZ you can use expressions like below, above, below left, ... instead of numerical values.

Drawing order is important in TiKZ. With your code, dots are drawn before extended lines, therefore dots appear behind lines. You can put lines behind dots with backgrounds library help. It declares a background layer and all objects placed on it will appear behind objects drawn on default main layer.

With all these modifications your code could be

\PassOptionsToPackage{dvipsnames}{xcolor}
\documentclass[tikz,border=5mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc,backgrounds}

\tikzset{
right angle quadrant=1, % Make sure it is set, even if not called explicitly
right angle length/.code={\def\rightanglelength{#1}},   % Length of symbol
right angle length=2ex, % Make sure it is set...
right angle symbol/.style n args={3}{
insert path={
let \p0 = ($(#1)!(#3)!(#2)$) in     % Intersection
let \p1 = ($(\p0)!\quadranta*\rightanglelength!(#3)$), % Point on base line
\p2 = ($(\p0)!\quadrantb*\rightanglelength!(#2)$) in % Point on perpendicular line
let \p3 = ($(\p1)+(\p2)-(\p0)$) in  % Corner point of symbol
(\p1) -- (\p3) -- (\p2)
}
}
}

\begin{document}
\begin{tikzpicture}[dot/.style 2 args={circle,inner sep=1pt,fill,label={#2:#1},name=#1},
extended line/.style={shorten >=-#1,shorten <=-#1,draw=Cerulean},
extended line/.default=1cm]

\node [dot={L}{below right}] at (1,0) {};
\node [dot={M}{below left}] at (4,0) {};
\node [dot={N}{right}] at (4,5) {};

\begin{scope}[on background layer]
\draw [extended line=0.5cm] (L) -- (M) node [below,midway] {3};
\draw [extended line=0.5cm] (L) -- (N) node [above left,midway] {6};
\draw [extended line=0.5cm] ($(L)!(N)!(M)$) -- (N) node [right,midway] {$x$};
\end{scope}

\draw [red,right angle symbol={M}{N}{L}];

\end{tikzpicture}
\end{document}


• If change the color of the lines, say to Cerulean, then the lines are above the black points. How can I reverse the order? Jan 12, 2014 at 23:20
• @azetina Please, look at the updated answer. Jan 13, 2014 at 10:06
• How to, for example, set the spacing between N and its circle to 0ex?
– Diaa
Jan 6, 2021 at 23:28