3

I'm quite new to using LaTeX, I only recently visited a course about how to use it and I now have to write a code to pass this course.

Anyway, I've encountered a problem as I tried to make a bar chart for the first time. Everything went well until I inserted the option nodes near coords. I now get the error messages: (although the pdf picture looks correct)

    line 20: Undefined control sequence. \end{axis}
    line 20: Argument of \XC@definec@lor has an extra }. \end{axis}
    line 20: Paragraph ended before \XC@definec@lor was complete. \end{axis}

And this is the code I wrote so far:

\documentclass{article}
\usepackage{polyglossia}
\setmainlanguage{german}
\usepackage{pgfplotstable}
\pgfplotsset{compat=1.16}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
title={\textbf{Wie findest du den Englischunterricht?}}, 
ybar,
ymin={0},
symbolic x coords={sehr gut, gut, mittelmässig, schlecht, sehr schlecht, keine/\\ungültige\\Antwort},
width={12.58cm}, 
height={7cm},
xticklabel style={align=center},
xtick=data, 
nodes near coords
]
\addplot coordinates {(sehr gut,53) (gut,35) (mittelmässig,7) (schlecht,0) (sehr schlecht,0) (keine/\\ungültige\\Antwort,3)};
\end{axis}
\end{tikzpicture}
\end{document}

I am using XeLaTeX, TeXStudio and, as visible in the code, the pgfplots version 1.16.

So: Why am I getting these error messages and how can I fix these errors?

Thank you already for your help :)

2

There are expansion issues with the \\. Rather than playing with \noexpand, \expandafter and the like, I'd suggest to avoid these altogether.

\documentclass{article}
\usepackage{polyglossia}
\setmainlanguage{german}
\usepackage{pgfplotstable}
\pgfplotsset{compat=1.16}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
title={\textbf{Wie findest du den Englischunterricht?}}, 
ybar,
ymin={0},
symbolic x coords={sehr gut, gut, mittelmässig, schlecht, sehr schlecht, 
keine/ ungültige Antwort
},
x tick label style={text width=1.5cm},
width={12.58cm}, 
height={7cm},
xticklabel style={align=center},
xtick=data, 
nodes near coords
]
\addplot coordinates {(sehr gut,53) (gut,35) (mittelmässig,7) (schlecht,0) 
(sehr schlecht,0) (keine/ ungültige Antwort,3)}; %(keine/\\ungültige\\Antwort,3)
\end{axis}
\end{tikzpicture}
\end{document}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.