减少刻度线周围的空白

减少刻度线周围的空白

我在 x 轴上有两个刻度标记:-\sqrt{3}\sqrt{3}。我已将它们水平移动,以减少它们遮挡的函数草图量。(我使用了选项axis on top。)包含刻度标记 的框周围的空白太多\sqrt{3}。我如何减少空白以使此刻度标记不会遮挡草图?

\documentclass[10pt]{amsart}
\usepackage{tikz}
\usetikzlibrary{calc,angles,positioning,intersections,quotes,decorations.markings}
\usepackage{tkz-euclide}
\usetkzobj{all}
\usepackage{pgfplots}
\pgfplotsset{compat=1.11}


\begin{document}

\noindent \hspace*{\fill}
\begin{tikzpicture}
\begin{axis}[width=5in,axis equal image,axis on top,
    axis lines=middle,
    xmin=-10,xmax=10,samples=201,
    xlabel=$x$,ylabel=$y$,
    ymin=-11,ymax=10,
    restrict y to domain=-11:10,
    enlargelimits={abs=0.25cm},
    axis line style={latex-latex},
    ticklabel style={font=\tiny,fill=white},
    xtick={\empty},ytick={\empty},
    extra x ticks={-1.732, 1.732},
    extra x tick labels={\hspace*{-10pt}$-\sqrt{3}$, $\sqrt{3}$\hspace*{-5pt}},
    %extra y ticks={-3},
    %extra y tick labels={$-3$},
    %extra y tick style={y tick label style={right, xshift=2.5pt}},
    xlabel style={at={(ticklabel* cs:1)},anchor=north west},
    ylabel style={at={(ticklabel* cs:1)},anchor=south west}
]
/pgfplots/xlabel shift={10pt};
\addplot[samples=501,domain=-9:-1.1789,blue] {(x^(2) - 3)/ (x + 1)} node[anchor=east,pos=0.9,font=\footnotesize]{$y=f(x)$};
\addplot[samples=501,domain=-0.72508:9,blue] {(x^(2) - 3)/ (x + 1)};
\addplot [dashed, latex-latex,domain=-10:10] {x - 1} node [pos=0.9, anchor=south, font=\footnotesize, sloped]{$y=x-1$};
\addplot [dashed, latex-latex,domain=-10:10] (-1,x) node [pos=0.1, anchor=south, font=\footnotesize, sloped]{$x=-1$};
\end{axis}
\end{tikzpicture}
\hspace{\fill}

\end{document}

答案1

pgfplots这样做的方式inner sep=0pt

ticklabel style={font=\tiny,fill=white,inner sep=0pt},   
extra x tick labels={\hspace*{-10pt}$-√{3}$, $√{3}$\hspace*{-7pt}},   %% -5pt changed to -7pt

在此处输入图片描述

您也可以使用,fill=none这样就没有白色填充了。

答案2

您可以完全隐藏宽度:

在此处输入图片描述

\documentclass[10pt]{amsart}
\usepackage{tikz}
\usetikzlibrary{calc,angles,positioning,intersections,quotes,decorations.markings}
\usepackage{tkz-euclide}
\usetkzobj{all}
\usepackage{pgfplots}
\pgfplotsset{compat=1.11}


\begin{document}

\noindent \hspace*{\fill}
\begin{tikzpicture}
\begin{axis}[width=5in,axis equal image,axis on top,
    axis lines=middle,
    xmin=-10,xmax=10,samples=201,
    xlabel=$x$,ylabel=$y$,
    ymin=-11,ymax=10,
    restrict y to domain=-11:10,
    enlargelimits={abs=0.25cm},
    axis line style={latex-latex},
    ticklabel style={font=\tiny,fill=white},
    xtick={\empty},ytick={\empty},
    extra x ticks={-1.732, 1.732},
    extra x tick labels={\hspace*{-10pt}{\makebox(0,0){$-\sqrt{3}$}}, {\makebox(0,0){$\sqrt{3}$}}\hspace*{-5pt}},
    %extra y ticks={-3},
    %extra y tick labels={$-3$},
    %extra y tick style={y tick label style={right, xshift=2.5pt}},
    xlabel style={at={(ticklabel* cs:1)},anchor=north west},
    ylabel style={at={(ticklabel* cs:1)},anchor=south west}
]
/pgfplots/xlabel shift={10pt};
\addplot[samples=501,domain=-9:-1.1789,blue] {(x^(2) - 3)/ (x + 1)} node[anchor=east,pos=0.9,font=\footnotesize]{$y=f(x)$};
\addplot[samples=501,domain=-0.72508:9,blue] {(x^(2) - 3)/ (x + 1)};
\addplot [dashed, latex-latex,domain=-10:10] {x - 1} node [pos=0.9, anchor=south, font=\footnotesize, sloped]{$y=x-1$};
\addplot [dashed, latex-latex,domain=-10:10] (-1,x) node [pos=0.1, anchor=south, font=\footnotesize, sloped]{$x=-1$};
\end{axis}
\end{tikzpicture}
\hspace{\fill}

\end{document}

相关内容