
我想使用盡可能緊湊的繪圖pgfplots
。
我有以下程式碼:
\documentclass{standalone}
\usepackage{graphicx}
\usepackage{tikz}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}
[
width=7.5cm,
xlabel={Size of the data set list},
ylabel={Gas cost},
grid=major,
domain=1:100,
xmin=0,xmax=10,
ymin=0,ymax=10,
ytick={0,2,...,12},
samples=21,
]
\addplot {x};
\end{axis}
\end{tikzpicture}
\end{document}
輸出如下:
我不知道為什麼,但 y 軸的標籤和它的線之間有額外的換行符。如何刪除 y 軸標籤和 y 軸線之間的多餘空間?
答案1
即使您安裝的版本是v1.18.1
,您也必須compat
明確設定該選項以請求使用版本 1.18 的所有功能。如果省略它,您會在日誌中收到以下警告:
Package pgfplots Warning: running in backwards compatibility mode
(unsuitable tick labels; missing features). Consider writing
\pgfplotsset{compat=1.18} into your preamble. on input line 4.
微量元素:
\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\begin{document}
\begin{tikzpicture}
\begin{axis}
[
width=7.5cm,
xlabel={Size of the data set list},
ylabel={Gas cost},
grid=major,
domain=1:100,
xmin=0,xmax=10,
ymin=0,ymax=10,
ytick={0,2,...,12},
samples=21,
]
\addplot {x};
\end{axis}
\end{tikzpicture}
\end{document}