# Adjust the position of node label in graph

Question is the position of node (16, 20) is mixing with line. How to get rid from this? That is i want to plot this node in right side so there is no chance of collision with line.

This is what i have done so far.

\documentclass[12pt, a4paper]{article}
\usepackage[a4paper,top=1 in,bottom=1 in,left=0.7 in,right=0.7 in]{geometry}
\usepackage[utf8]{inputenc}
\usepackage[misc]{ifsym}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{graphicx}
\usepackage{tikz}
\usepackage{pst-tree}
\usetikzlibrary{intersections}
\begin{document}
\begin{center}
\begin{tikzpicture}
\draw[thick,latex-latex] (-1,0) -- (13,0)node[right]{$x$};
\draw[thick,latex-latex] (0,-1) -- (0,13)node[above]{$y$};
\node at (-0.3,-0.3) {};
\foreach \x/\l in {,1/2,2/4,3/6,4/8,5/10,6/12,7/14,8/16,9/18,10/20,11/22,12/24}{
\node[fill,circle,inner sep=1.5pt,label=below:$\l$] at (\x,0) {};
\node[fill,circle,inner sep=1.5pt,label=left:$\l$] at (0,\x) {};
}
\draw[thick,stealth-stealth, shorten >= -4cm, shorten <= -1cm,name path =b ](2,4) -- (6,8);
\draw[thick,stealth-stealth, shorten >= -1cm, shorten <= -1.5cm,name path =b ](10,8) -- (6,12);
\foreach \x/\y/\name/\m/\n in {4/6//8/12}{
\node[fill,circle,inner sep=2.5pt,label={[inner sep=0pt]below right:\name($\m, \n$)}] at (\x,\y) {};
}
\foreach \x/\y/\name/\m/\n in {2/4//4/8}{
\node[fill,circle,inner sep=2.5pt,label={[inner sep=0pt]below right:\name($\m, \n$)}] at (\x,\y) {};
}
\foreach \x/\y/\name/\m/\n in {6/8//12/16}{
\node[fill,circle,inner sep=2.5pt,label={[inner sep=0pt]below :\name($\m, \n$)}] at (\x,\y) {};
}
\foreach \x/\y/\name/\m/\n in {10/8//20/16}{
\node[fill,circle,inner sep=2.5pt,label={[inner sep=0pt]below left:\name($\m, \n$)}] at (\x,\y) {};
}
\foreach \x/\y/\name/\m/\n in {8/10//16/20}{
\node[fill,circle,inner sep=2.5pt,label={[inner sep=0pt]below left:\name($\m, \n$)}] at (\x,\y) {};
}
\foreach \x/\y/\name/\m/\n in {6/12//12/24}{
\node[fill,circle,inner sep=2.5pt,label={[inner sep=0pt]below left:\name($\m, \n$)}] at (\x,\y) {};
}
\draw (9,11) node[anchor=north west,rotate=0] {$x-y=-4$};
\draw (2.1,13) node[anchor=north west,rotate=0] {$2x-y-2=0$};

\end{tikzpicture}
\end{center}

\end{document}

• If you look at your code, how have you currently positioned that specific label? What do you think you need to change to move it to the right? Feb 8, 2016 at 7:27
• (16, 20) just cutting the line that is only the problem. Feb 8, 2016 at 7:44
• You can shift it a little bit to the left with xshift: \foreach \x/\y/\name/\m/\n in {8/10//16/20}{ \node[fill,circle,inner sep=2.5pt,label={[inner sep=0pt, xshift=-1mm]left:\name($\m, \n$)}] at (\x,\y) {}; Feb 8, 2016 at 8:00

I've changed below to right and changed inner sep= to 3pt in your code:

\documentclass[12pt, a4paper]{article}
\usepackage[a4paper,top=1 in,bottom=1 in,left=0.7 in,right=0.7 in]{geometry}
\usepackage[utf8]{inputenc}
%\usepackage[misc]{ifsym}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{graphicx}
\usepackage{tikz}
\usepackage{pst-tree}
\usetikzlibrary{intersections}
\begin{document}
\begin{center}
\begin{tikzpicture}
\draw[thick,latex-latex] (-1,0) -- (13,0)node[right]{$x$};
\draw[thick,latex-latex] (0,-1) -- (0,13)node[above]{$y$};
\node at (-0.3,-0.3) {};
\foreach \x/\l in {,1/2,2/4,3/6,4/8,5/10,6/12,7/14,8/16,9/18,10/20,11/22,12/24}{
\node[fill,circle,inner sep=1.5pt,label=below:$\l$] at (\x,0) {};
\node[fill,circle,inner sep=1.5pt,label=left:$\l$] at (0,\x) {};
}
\draw[thick,stealth-stealth, shorten >= -4cm, shorten <= -1cm,name path =b ](2,4) -- (6,8);
\draw[thick,stealth-stealth, shorten >= -1cm, shorten <= -1.5cm,name path =b ](10,8) -- (6,12);
\foreach \x/\y/\name/\m/\n in {4/6//8/12}{
\node[fill,circle,inner sep=2.5pt,label={[inner sep=0pt]below right:\name($\m, \n$)}] at (\x,\y) {};
}
\foreach \x/\y/\name/\m/\n in {2/4//4/8}{
\node[fill,circle,inner sep=2.5pt,label={[inner sep=0pt]below right:\name($\m, \n$)}] at (\x,\y) {};
}
\foreach \x/\y/\name/\m/\n in {6/8//12/16}{
\node[fill,circle,inner sep=2.5pt,label={[inner sep=0pt]below right:\name($\m, \n$)}] at (\x,\y) {};
}
\foreach \x/\y/\name/\m/\n in {10/8//20/16}{
\node[fill,circle,inner sep=2.5pt,label={[inner sep=0pt]below left:\name($\m, \n$)}] at (\x,\y) {};
}
\foreach \x/\y/\name/\m/\n in {8/10//16/20}{
\node[fill,circle,inner sep=2.5pt,label={[inner sep=3pt]right:\name($\m, \n$)}] at (\x,\y) {};
}
\foreach \x/\y/\name/\m/\n in {6/12//12/24}{
\node[fill,circle,inner sep=2.5pt,label={[inner sep=0pt]below left:\name($\m, \n$)}] at (\x,\y) {};
}

\draw (9,11) node[anchor=north west,rotate=0] {$x-y=-4$};
\draw (2.1,13) node[anchor=north west,rotate=0] {$2x-y-2=0$};

\end{tikzpicture}
\end{center}

\end{document}


With the following output:

Additional note by Torbjørn T.: I don't really see why you use \foreach for the point labels, in none of the cases do you actually loop over multiple entries in a list. However, by adding one more iteration variable for the position you can add all the labels with one loop:

\documentclass[12pt, a4paper]{article}
\usepackage{tikz}
\usetikzlibrary{intersections}
\begin{document}
\begin{center}
\begin{tikzpicture}
\draw[thick,latex-latex] (-1,0) -- (13,0)node[right]{$x$};
\draw[thick,latex-latex] (0,-1) -- (0,13)node[above]{$y$};
\node at (-0.3,-0.3) {};
\foreach \x/\l in {,1/2,2/4,3/6,4/8,5/10,6/12,7/14,8/16,9/18,10/20,11/22,12/24}{
\node[fill,circle,inner sep=1.5pt,label=below:$\l$] at (\x,0) {};
\node[fill,circle,inner sep=1.5pt,label=left:$\l$] at (0,\x) {};
}
\draw[thick,stealth-stealth, shorten >= -4cm, shorten <= -1cm,name path =b ](2,4) -- (6,8);
\draw[thick,stealth-stealth, shorten >= -1cm, shorten <= -1.5cm,name path =b ](10,8) -- (6,12);
\foreach \x/\y/\name/\m/\n/\pos in
{4/6//8/12/below right,
2/4//4/8/below right,
6/8//12/16/below right,
10/8/\hspace{3pt}/20/16/below left,
8/10//16/20/right,
6/12//12/24/below left}
{
\node[fill,circle,inner sep=2.5pt,label={[inner sep=0pt]\pos:\name($\m, \n$)}] at (\x,\y) {};
}
\draw (9,11) node[anchor=north west,rotate=0] {$x-y=-4$};
\draw (2.1,13) node[anchor=north west,rotate=0] {$2x-y-2=0$};
\end{tikzpicture}
\end{center}
\end{document}

• This is exactly what i want and one more thing thanks to ignasi Feb 8, 2016 at 8:34
• I don't think what I added was reason enough to post a new answer, so I took the liberty of adding it to yours. Feel free to roll back my edit if you don't think like it. Feb 8, 2016 at 11:59
• @Torbjørn T., No that's great! I always appreciate a better solution, thanks for editing. Feb 8, 2016 at 12:36