如何使 PGf 图中的条形标签变为多行?

如何使 PGf 图中的条形标签变为多行?

我的文档中有以下简单图表:

\begin{tikzpicture}
\begin{axis}[
ybar,
enlargelimits=0.15,
legend style={at={(0.5,-0.2)},
anchor=north,legend columns=-1},
ylabel={\# of Respondents},
symbolic x coords={Short label,A longer label,A quite long label that should be two lines,Another long label I want to multiline},
xtick=data,
nodes near coords,
nodes near coords align={vertical},
x tick label style={rotate=45,anchor=east},
]
\addplot coordinates {(Short label,1) (A longer label,151)
(A quite long label that should be two lines,19) (Another long label I want to multiline,14)};
\end{axis}
\end{tikzpicture}

最后两个标签目前几乎使图表的大小翻倍,并且有足够的空间让它们各自成为相应列下的两个较短的行。有什么办法吗?我尝试插入\\但没有效果。

答案1

尝试改为x tick label style

    x tick label style={font=\small, rotate=45, anchor=north east, 
                        text width=10em, inner sep=2pt, align=right},

在此处输入图片描述

但是,请尝试使标签更短...

相关内容