6

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

enter image description here

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

\tikzset{
    right angle quadrant/.code={
        \pgfmathsetmacro\quadranta{{1,1,-1,-1}[#1-1]}     % Arrays for selecting quadrant
        \pgfmathsetmacro\quadrantb{{1,-1,-1,1}[#1-1]}},
    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.

6

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/.code={
        \pgfmathsetmacro\quadranta{{1,1,-1,-1}[#1-1]}     % Arrays for selecting quadrant
        \pgfmathsetmacro\quadrantb{{1,-1,-1,1}[#1-1]}},
    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}

enter image description here

  • If change the color of the lines, say to Cerulean, then the lines are above the black points. How can I reverse the order? – azetina Jan 12 '14 at 23:20
  • @azetina Please, look at the updated answer. – Ignasi Jan 13 '14 at 10:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.