我在使用 tikz 时遇到了这个问题,我试图创建这个简单的数字线,但是弹出了一堆不必要的空白:
\item
As a real-number-line graph:\\
\begin{tikzpicture}
\begin{axis}[
axis x line=middle,
axis y line=none,
xtick={-3,-2,...,4,5}
]
\addplot[line width=0.4mm, draw=blue][domain=-3:5]{0};
\addplot[draw=blue, fill=white, mark=*] coordinates {(-3,0)(1,0)(5,0)};
\end{axis}
\end{tikzpicture}
\item
Interval Notation:\\
结果如下:
我该如何删除所有这些空白?另外,为什么会有这么多空白?
谢谢。
答案1
tikzpicture
具有默认高度。您需要将其减小到某个较小的值,但不要太小(<16mm),否则您将收到错误:
Package pgfplots Error: Error: Plot height `42.67912pt' is too small. This ca
nnot be implemented while maintaining constant size for labels. Sorry, label si
zes are only approximate. You will need to adjust your height..
看看以下 MWE 是否能满足您的要求:
\documentclass{article}
\usepackage{pgfplots}
\begin{document}
\begin{enumerate}
\item As a real-number-line graph:
\begin{tikzpicture}
\begin{axis}[
height=20mm, width=90mm, % <---
axis x line=bottom,
axis y line=none,
axis line style=-, % <---
xtick={-3,-2,...,4,5},
ymin = 0, ymax = 1, % <---
]
\addplot[draw=blue, thick, fill=white, mark=*]
coordinates {(-3,0) (1,0) (5,0)};
\end{axis}
\end{tikzpicture}
\item Interval Notation:
\end{enumerate}
\end{document}