在下图中,我有一个标记为 的点(2, 16/3)
。我希望 的字体2
为, 和的scriptsize
字体为。16
3
tiny
\documentclass[10pt]{amsart}
\usepackage{amsmath}
\usepackage{tikz}
\usetikzlibrary{calc,intersections}
\usepackage{pgfplots}
\pgfplotsset{compat=1.11}
\begin{document}
\begin{tikzpicture}
\begin{axis}[width=3in, height=3in, clip=false,
axis lines=middle,
xmin=-2,xmax=8,
ymin=-3,ymax=11,
restrict y to domain=-3:11,
axis line style={latex-latex},
xlabel=$x$,ylabel=$y$,
xtick={\empty},ytick={\empty},
axis line style={shorten >=-12.5pt, shorten <=-12.5pt},
xlabel style={at={(ticklabel* cs:1)}, xshift=12.5pt, anchor=north west},
ylabel style={at={(ticklabel* cs:1)}, yshift=12.5pt, anchor=south west}
]
\addplot[latex-latex, domain=-2:8] {(-4/3)*x + 8};
\addplot[latex-latex, dashed, domain=-2:8] {16/3};
\coordinate (A) at (2,16/3);
\coordinate (label_for_ell) at (8,-8/3);
\coordinate (label_for_horizontal_line) at (8,16/3);
\draw[fill] (A) circle [radius=1.5pt];
\end{axis}
\draw node[anchor=west, inner sep=0, font=\scriptsize] at ($(label_for_horizontal_line) +(0.15,0)$){$y=\dfrac{16}{3}$};
\draw node[anchor=north west, inner sep=0, font=\scriptsize] at ($(label_for_ell) +({atan(-4/3)}:0.15)$){$y = \dfrac{-4}{3}x + 8$};
\draw[draw=gray, shorten <=1mm, shorten >=1mm] (A) -- ($(A) +({0.5*(atan(-4/3)+180)}:0.75)$) node[anchor=south west, font=\scriptsize, inner sep=0] {$\left(2, \, \raisebox{0.2em}{$\tiny{16}$}/\raisebox{-0.2em}{$\tiny{3}$}\right)$};
\end{tikzpicture}
\end{document}
答案1
像这样?
\documentclass{article}
\usepackage{amsmath}
\usepackage{tikz}
\usetikzlibrary{arrows.meta, calc, intersections}
\makeatletter% stolen from memoir.cls
\DeclareRobustCommand*{\slashfracstyle}[1]{%
{\m@th\ensuremath{\mbox{\fontsize\sf@size\z@\selectfont #1}}}}
\DeclareRobustCommand*{\slashfrac}[2]{\leavevmode
\raise.5ex\hbox{\slashfracstyle{#1}}\kern-.13em/%
\kern-.15em\lower.25ex\hbox{\slashfracstyle{#2}}}
\makeatother
\begin{document}
\begin{tikzpicture}[>=Latex]
% coordinate axes
\draw[<->] (-2,0) -- (10,0) node[right] {$x$};
\draw[<->] (0,-2) -- (0,10) node[above] {$y$};
% line (-4/3)*x + 8
\draw[name path=A,
thick,latex-latex, domain=-1:7] plot (\x,-4*\x/3 + 8)
node[right] {$y=\dfrac{-4}{3}x + 8$};
\draw[name path=B,
dashed,<->] (-1,16/3) -- + (8,0) node[right] {$y=\dfrac{18}{3}$};
\path[name intersections={of=A and B, by={d}}]
node[circle, fill, inner sep=2pt,
pin=60:{(2,\slashfrac{15}{3})}] at (d) {};
\end{tikzpicture}
\end{document}
图表以纯 TikZ 图片重新绘制,因为其中的代码(当然根据我的观点)更简单、更短。使用 pgf 图如下:
\documentclass{article}
\usepackage{amsmath}
\usepackage{pgfplots}
\pgfplotsset{compat=1.11}
\usetikzlibrary{arrows.meta, calc, intersections}
\makeatletter% stolen from memoir.cls
\DeclareRobustCommand*{\slashfracstyle}[1]{%
{\m@th\ensuremath{\mbox{\fontsize\sf@size\z@\selectfont #1}}}}
\DeclareRobustCommand*{\slashfrac}[2]{\leavevmode
\raise.5ex\hbox{\slashfracstyle{#1}}\kern-.13em/%
\kern-.15em\lower.25ex\hbox{\slashfracstyle{#2}}}
\makeatother
\begin{document}
\begin{tikzpicture}[>=Latex]
\begin{axis}[width=3in, height=3in, clip=false,
axis lines=middle,
xmin=-2,xmax=8,
ymin=-3,ymax=11,
axis line style={latex-latex},
xlabel=$x$,ylabel=$y$,
xtick={\empty},ytick={\empty},
axis line style={shorten >=-12.5pt, shorten <=-12.5pt},
xlabel style={at={(ticklabel* cs:1)}, xshift=1em,right},
ylabel style={at={(ticklabel* cs:1)}, yshift=1em, above}
]
% lines
\addplot[name path=A,thick,<->, domain=-2:8] {(-4/3)*x + 8}
node[right] {$y=-\dfrac{4}{3}x + 8$};;
\addplot[name path=B,dashed,<->, domain=-2:8] {16/3}
node[right] {$y=\dfrac{18}{3}$};
% intersection
\path[name intersections={of=A and B, by={d}}]
node[circle, fill, inner sep=2pt,
pin=60:{(2,\slashfrac{15}{3})}] at (d) {};
\end{axis}
\end{tikzpicture}
\end{document}
结果与第一个纯 TikZ 示例相同。
编辑:
如果您出于某种原因不喜欢\slashfrac
在文档序言中包含定义代码(哪里有自然空间),您可以将其移到里面tikzpicture
:
\documentclass{article}
\usepackage{amsmath}
\usepackage{verbatim}
\usepackage{pgfplots}
\pgfplotsset{compat=1.14}
\usetikzlibrary{arrows.meta, calc, intersections}
\usepackage[active,tightpage]{preview}
\PreviewEnvironment{tikzpicture}
\setlength\PreviewBorder{1em}
\begin{document}
\begin{tikzpicture}[>=Latex]
%---------------------------------------------------------------%
\makeatletter
\DeclareRobustCommand*{\slashfracstyle}[1]{%
{\m@th\ensuremath{\mbox{\fontsize\sf@size\z@\selectfont #1}}}}
\DeclareRobustCommand*{\slashfrac}[2]{\leavevmode
\raise.5ex\hbox{\slashfracstyle{#1}}\kern-.13em/%
\kern-.15em\lower.25ex\hbox{\slashfracstyle{#2}}}
\makeatother
%---------------------------------------------------------------%
\begin{axis}[width=3in, height=3in, clip=false,
axis lines=middle,
xmin=-2,xmax=8,
ymin=-3,ymax=11,
axis line style={latex-latex},
xlabel=$x$,ylabel=$y$,
xtick={\empty},ytick={\empty},
axis line style={shorten >=-12.5pt, shorten <=-12.5pt},
xlabel style={at={(ticklabel* cs:1)}, xshift=1em,right},
ylabel style={at={(ticklabel* cs:1)}, yshift=1em, above}
]
% lines
\addplot[name path=A,thick,<->, domain=-2:8] {(-4/3)*x + 8}
node[right] {$y=-\dfrac{4}{3}x + 8$};;
\addplot[name path=B,dashed,<->, domain=-2:8] {16/3}
node[right] {$y=\dfrac{18}{3}$};
% intersection
\path[name intersections={of=A and B, by={d}}]
node[circle, fill, inner sep=2pt,
pin=60:{(2,\slashfrac{15}{3})}] at (d) {};
\end{axis}
\end{tikzpicture}
\end{document}