
「xticklabels」の間に新しい行を入れて、2 行にして窮屈にならないようにしたいのですが、二重のバックスラッシュ \\ と \n は機能しませんでした。
コード:
\documentclass{standalone}
\usepackage{tikz,pgfplots,pgfplotstable}
\pgfplotsset{compat=1.18}
\usepgfplotslibrary{statistics}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
width=0.9\textwidth,
boxplot/draw direction=y,
axis y line=left,
enlarge y limits,
ylabel={Impact of latency},
xlabel={Game and latency},
ytick={1, 2, 3, 4, 5},
yticklabels={1, 2, 3, 4, 5},
ymajorgrids,
xtick={1, 2, 3, 4},
xticklabels={Chess 0ms , Chess 1000ms, Pong 0ms, Pong 1000ms},
]
\addplot+ [boxplot prepared={lower whisker=1, upper whisker=2}] coordinates {};
\addplot+ [boxplot prepared={lower whisker=2, upper whisker=4}] coordinates {};
\addplot+ [boxplot prepared={lower whisker=1, upper whisker=2}] coordinates {};
\addplot+ [boxplot prepared={lower whisker=4, upper whisker=5}] coordinates {};
\end{axis}
\end{tikzpicture}
\end{document}
答え1
ノード内で行を分割するには、\\
で配置を設定する必要がありますalign
。
xticklabel style={align=center}
そして、あなたは使うことができます
xticklabels={Chess\\ 0ms, Chess\\ 1000ms, Pong\\ 0ms, Pong\\ 1000ms},
完全な例 ( を削除しaxis y line=left
、ボックスの左側に矢印を追加しました):
\documentclass{standalone}
\usepackage{tikz,pgfplots,pgfplotstable}
\pgfplotsset{compat=1.18}
\usepgfplotslibrary{statistics}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
width=0.9\textwidth,
boxplot/draw direction=y,
enlarge y limits,
ylabel={Impact of latency},
xlabel={Game and latency},
ytick={1, 2, 3, 4, 5},
ymajorgrids,
xtick={1, 2, 3, 4},
xticklabels={Chess\\ 0ms, Chess\\ 1000ms, Pong\\ 0ms, Pong\\ 1000ms},
xticklabel style={align=center}
]
\addplot+ [boxplot prepared={lower whisker=1, upper whisker=2}] coordinates {};
\addplot+ [boxplot prepared={lower whisker=2, upper whisker=4}] coordinates {};
\addplot+ [boxplot prepared={lower whisker=1, upper whisker=2}] coordinates {};
\addplot+ [boxplot prepared={lower whisker=4, upper whisker=5}] coordinates {};
\end{axis}
\end{tikzpicture}
\end{document}