![调整图形中节点标签的位置](https://linux22.com/image/327769/%E8%B0%83%E6%95%B4%E5%9B%BE%E5%BD%A2%E4%B8%AD%E8%8A%82%E7%82%B9%E6%A0%87%E7%AD%BE%E7%9A%84%E4%BD%8D%E7%BD%AE.png)
问题是节点 (16, 20) 的位置与线相混。如何摆脱这种情况?也就是说,我想将此节点绘制在右侧,这样就不会与线发生冲突。
这就是我迄今为止所做的。
\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}
答案1
我已将below
你的代码right
改为3pt:inner sep=
\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}
输出如下:
Torbjørn T. 的补充说明:我不太明白为什么要使用\foreach
点标签,在任何情况下,您都不会真正循环列表中的多个条目。但是,通过为位置添加一个迭代变量,您可以使用一个循环添加所有标签:
\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}