以下是绘制 x+y=4 图形的代码。现在我正在考虑绘制 x+y=100 图形,为此,给定的代码需要进行哪些更改。
\documentclass[12pt,a4paper]{article}
\usepackage[a4paper,bindingoffset=0.2in,left=0.7in,right=0.7in,top=0.7in,bottom=0.7in,footskip=.25in]{geometry}
\usepackage[centertags]{amsmath}
\usepackage{latexsym}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{amsthm}
\usepackage{newlfont}
\usepackage{enumerate}
\usepackage{makeidx}
\usepackage{tikz}
\usetikzlibrary{backgrounds,intersections}
\begin{document}
\begin{tikzpicture}
\draw[thick,latex-latex] (-2,0) -- (5,0)node[right]{$x$};
\draw[thick,latex-latex] (0,-2) -- (0,5)node[above]{$y$};
\node at (-0.3,-0.3) {O};
\foreach \x in {-1,1,2,3,4}{
\node[fill,circle,inner sep=1.5pt,label=below:$\x$] at (\x,0) {};
\node[fill,circle,inner sep=1.5pt,label=left:$\x$] at (0,\x) {};
}
\draw[thick,stealth-stealth, shorten >= -2cm, shorten <= -2cm,name path =b ] (0,4) -- (4,0)
node[pos=0.65,above,sloped] {$ $};
\foreach \x/\y/\name in {0/4/B,4/0/A}{
\node[fill,circle,inner sep=2.5pt,label={[inner sep=0pt]above right:\name($\x, \y$)}] at (\x,\y) {};
}
\end{tikzpicture}
\end{document}
答案1
有几种方法,一种解决方案是将所有坐标更改为 0 到 100 的比例并修复缩放比例,另一种解决方案是从给定的坐标(所有坐标乘以 25)计算新标签。比这更快的方法是通过将标签与坐标分开来伪造所有内容。基于更最小下面是您的代码版本。
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{intersections}
\begin{document}
\begin{tikzpicture}
\draw[thick,latex-latex] (-2,0) -- (5,0)node[right]{$x$};
\draw[thick,latex-latex] (0,-2) -- (0,5)node[above]{$y$};
\node at (-0.3,-0.3) {O};
\foreach \x/\l in {-1/-25,1/25,2/50,3/75,4/100}{
\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 >= -2cm, shorten <= -2cm,name path =b ] (0,4) -- (4,0)
node[pos=0.65,above,sloped] {$ $};
\foreach \x/\y/\name/\m/\n in {0/4/B/0/100,4/0/A/100/0}{
\node[fill,circle,inner sep=2.5pt,label={[inner sep=0pt]above right:\name($\m, \n$)}] at (\x,\y) {};
}
\end{tikzpicture}
\end{document}
但我赞同 JPi 的建议:熟悉 pgfplots。