在使用 tikz 时,我遇到了一个问题,我无法让轴标签占用多行。在某些情况下,轴上的文本很长,因此变得不太清晰。在下面的例子中,如果标签
啊啊啊啊啊啊
已损坏(即垂直延伸):
啊啊啊啊啊
啊啊啊啊
您建议我如何实施这一变革?
我曾尝试手动输入 AAAA//AAAA,但 tikz 似乎无法识别。
\begin{document}
\centering
\pgfplotstableread{
x y
AAAAAAAAAAAAAA 0.09
B 0.06
C 0.04
D 0.02
}{\mytablee}
\begin{tikzpicture}
\begin{axis} [
ymin=0,
symbolic x coords={AAAAAAAAAAAAAA,B,C,D},
xtick=data
]
\addplot
plot [mark=none, black, dashed]
table {\mytablee};
\end{axis}
\node[above,font=\large\bfseries] at (current bounding box.north) {Test};
\node[below,font=\large] at (current bounding box.south) {Sample};
\end{tikzpicture}
\end{document}
答案1
通过添加x tick label style={text width=1.7cm,align=center}
,您的xtick label
s 将换行。您需要\\
在标签中添加 来指示断点。
\documentclass[border=3pt]{standalone}
\usepackage{pgfplots}
\pgfplotstableread{
x y
AAAAAAA\\AAAAAAA 0.09
B 0.06
C 0.04
D 0.02
}{\mytablee}
\begin{document}
\begin{tikzpicture}
\begin{axis} [
x tick label style={text width=1.7cm,align=center}, % <-- added
ymin=0,
symbolic x coords={AAAAAAA\\AAAAAAA,B,C,D},
xtick=data
]
\addplot
plot [mark=none, black, dashed]
table {\mytablee};
\end{axis}
\node[above,font=\large\bfseries] at (current bounding box.north) {Test};
\node[below,font=\large] at (current bounding box.south) {Sample};
\end{tikzpicture}
\end{document}