我有一条抛物线及其对称轴的图。在x
轴上x
标有截距。如何将标签移近刻度线?
\documentclass{amsart}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{tikz}
\usetikzlibrary{calc}
\usepackage{pgfplots}
\pgfplotsset{compat=1.11}
\begin{document}
\begin{tikzpicture}
\begin{axis}[width=2.5in, height=2.5in, axis lines=middle, clip=false,
axis lines=middle, clip=false,
xmin=-7.56,xmax=23.56,
ymin=-150,ymax=150,
restrict y to domain=-150:150,
xtick={-3},
xticklabel style={font=\tiny, below left},
xticklabels={\makebox[0pt][r]{$-$}$3$},
extra x ticks={19},
extra x tick style={font=\tiny, xticklabel style={below right}},
extra x tick labels={19},
ytick={\empty},
axis line style={latex-latex},
xlabel=\textit{x}, ylabel=\textit{y},
axis line style={shorten >=-7.5pt, shorten <=-7.5pt},
xlabel style={at={(ticklabel* cs:1)}, xshift=7.5pt, anchor=north west},
ylabel style={at={(ticklabel* cs:1)}, yshift=7.5pt, anchor=south west}
]
%The parabola y = x^{2} - 16x - 57 is drawn over the interval [8-11*sqrt(2), 8+11*sqrt(2)].
%Its x-intercepts are (-3,0) and (19,0), and its vertex is (8,-121).
\addplot[domain={8-11*sqrt(2)}:{8+11*sqrt(2)}] {x^2 - 16*x - 57};
%The axis of symmetry is drawn.
\addplot[dashed, latex-latex, domain=-140:140] (8,x) node[pos=0.2, anchor=south, font=\scriptsize, sloped]{$x=8$};
\end{axis}
\end{tikzpicture}
\end{document}
答案1
如果添加draw
到xticklabel style
,您会看到节点文本和边框之间有一些填充,这是inner sep
(默认 0.333em):
通过向相关样式inner sep
添加(或其他值)来减少,将实现您的要求。以下是零内部 sep:inner sep=0pt
\documentclass{amsart}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{tikz}
\usetikzlibrary{calc}
\usepackage{pgfplots}
\pgfplotsset{compat=1.11}
\begin{document}
\begin{tikzpicture}
\begin{axis}[width=2.5in, height=2.5in, axis lines=middle, clip=false,
axis lines=middle, clip=false,
xmin=-7.56,xmax=23.56,
ymin=-150,ymax=150,
restrict y to domain=-150:150,
xtick={-3},
xticklabel style={font=\tiny, inner sep=0pt, below left},
xticklabels={\makebox[0pt][r]{$-$}$3$},
extra x ticks={19},
extra x tick style={font=\tiny, xticklabel style={below right}},
extra x tick labels={19},
ytick={\empty},
axis line style={latex-latex},
xlabel=\textit{x}, ylabel=\textit{y},
axis line style={shorten >=-7.5pt, shorten <=-7.5pt},
xlabel style={at={(ticklabel* cs:1)}, xshift=7.5pt, anchor=north west},
ylabel style={at={(ticklabel* cs:1)}, yshift=7.5pt, anchor=south west}
]
%The parabola y = x^{2} - 16x - 57 is drawn over the interval [8-11*sqrt(2), 8+11*sqrt(2)].
%Its x-intercepts are (-3,0) and (19,0), and its vertex is (8,-121).
\addplot[domain={8-11*sqrt(2)}:{8+11*sqrt(2)}] {x^2 - 16*x - 57};
%The axis of symmetry is drawn.
\addplot[dashed, latex-latex, domain=-140:140] (8,x) node[pos=0.2, anchor=south, font=\scriptsize, sloped]{$x=8$};
\end{axis}
\end{tikzpicture}
\end{document}
答案2
移动标签的另一种方法(以防它们干扰其他元素)是在below left
或之后添加一些距离below right
。编辑除非与库一起使用,否则此选项已弃用positioning
。(非常感谢 Torbjørn T.!)
\documentclass{amsart}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{tikz}
\usetikzlibrary{calc,positioning}
\usepackage{pgfplots}
\pgfplotsset{compat=1.11}
\begin{document}
\begin{tikzpicture}
\begin{axis}[width=2.5in, height=2.5in, axis lines=middle, clip=false,
axis lines=middle, clip=false,
xmin=-7.56,xmax=23.56,
ymin=-150,ymax=150,
restrict y to domain=-150:150,
xtick={-3},
xticklabel style={font=\tiny, below left=-0.4em},
xticklabels={\makebox[0pt][r]{$-$}$3$},
extra x ticks={19},
extra x tick style={font=\tiny, xticklabel style={below right=-0.4em}},
extra x tick labels={19},
ytick={\empty},
axis line style={latex-latex},
xlabel=\textit{x}, ylabel=\textit{y},
axis line style={shorten >=-7.5pt, shorten <=-7.5pt},
xlabel style={at={(ticklabel* cs:1)}, xshift=7.5pt, anchor=north west},
ylabel style={at={(ticklabel* cs:1)}, yshift=7.5pt, anchor=south west}
]
%The parabola y = x^{2} - 16x - 57 is drawn over the interval [8-11*sqrt(2), 8+11*sqrt(2)].
%Its x-intercepts are (-3,0) and (19,0), and its vertex is (8,-121).
\addplot[domain={8-11*sqrt(2)}:{8+11*sqrt(2)}] {x^2 - 16*x - 57};
%The axis of symmetry is drawn.
\addplot[dashed, latex-latex, domain=-140:140] (8,x) node[pos=0.2, anchor=south, font=\scriptsize, sloped]{$x=8$};
\end{axis}
\end{tikzpicture}
\end{document}