# Multi-line texts in xticklabel from a File in PGFplot

I am using LaTeX, TikZ and PGFplots to generate a bar chart, in which the xticklabel is read from testdata.dat file.

In the following example, the xticklabel is a single line, i.e., Big-Bed, Small-Bed. Now I want to change them to two-line texts i.e. Big \\ Bed, Small \\ Bed respectively.

Unfortunately, when replacing - with \\ in testdata.dat, I found that there are some errors in compiling. Maybe \\ is not allowed in testdat.dat by fileconcents. Could anyone kindly help me out to change the xticklabel text into two-line texts?

\documentclass{article}
\usepackage{pgfplots}
\usepackage{filecontents}

\begin{filecontents}{testdata.dat}
Label X-Position Height
Big-Bed    1    15
Small-Bed    2    20
\end{filecontents}

%
\begin{document}
\begin{tikzpicture}
\begin{axis}[
ybar,
xtick=data,% crucial line for the xticklabels directive
ymin=0,
xticklabels from table={testdata.dat}{Label}
]

x=X-Position,
y=Height
] {testdata.dat};

\end{axis}
\end{tikzpicture}
\end{document}

-

If you want to use line breaks in node names you have to let TikZ switch to some sort of text formatting mode. The easiest is to make an alignment declaration such that it pays attention to the content. Also you can put braces around sensitive node cell contents to protect them (has some limitations probably)

\documentclass{article}
\usepackage{pgfplots}
\usepackage{filecontents}

\begin{filecontents}{testdata.dat}
Label X-Position Height
{Big\\BedHotel\\\$\$} 1 15
{Small\\Bed\&Breakfast} 2 20
\end{filecontents}

%
\begin{document}
\begin{tikzpicture}
\begin{axis}[
ybar,
xtick=data,% crucial line for the xticklabels directive
ymin=0,
xticklabels from table={testdata.dat}{Label},
xticklabel style={align=center}
]