# How do I get a % sign in symbolic x coords in pgfplots

I have some data I want to plot in a bar chart where the name on the x-axis should have a % sign in it. So this works:

\documentclass{article}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
ybar,
symbolic x coords={10 perc,20 perc},
]
\addplot coordinates {(10 perc,10) (20 perc,20)};
\end{axis}
\end{tikzpicture}
\end{document}


But if I try something like:

\documentclass{article}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
ybar,
symbolic x coords={10\%,20\%},
]
\end{axis}
\end{tikzpicture}
\end{document}


I get the following error:

ERROR: Missing \endcsname inserted.

--- TeX said ---
\%
l.8         ]


This happens in and out of math mode.

\\\% causes pdflatex to hang.

-

LaTeX has a safe percent macro but it uses an @ name so first give it a name without an @.

\documentclass{article}
\usepackage{pgfplots}
\makeatletter
\let\percent\@percentchar
\makeatother

\begin{document}
\begin{tikzpicture}
\begin{axis}[
ybar,
symbolic x coords={10\percent,20\percent},
]
\end{axis}
\end{tikzpicture}
\end{document}

-
Thanks, this almost works! It gives something like this though: !Plot Not sure why the extra x ticks –  nick Jul 26 '12 at 16:24
Isn't that exactly the same as your first example but with "perc" replaced by % ?? –  David Carlisle Jul 26 '12 at 16:28
hah, right you are, sorry, was miss-reading. this works fine thanks. the only last little niggle is getting there to be a space after the % sign, like if one of the coords was: (Foo 20% Bar,20). thanks again! –  nick Jul 26 '12 at 16:32
can't answer your spacing issue (I've never used tikz except for running MWE from questions on this site) If necessary ask another question on site specifically about the spacing –  David Carlisle Jul 26 '12 at 16:35
@nick I guess you get a space the same way you always get one after a macro: \percent\ bla (i.e. a \ and a space after the macro) or \percent{} bla. –  Caramdir Jul 26 '12 at 16:40

Try this:

\documentclass{article}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[ybar,symbolic x coords={10,20},xticklabel=$\pgfmathprintnumber{\tick}$\,\%]

The default for xticklabel is defined by (p. 225 in the pfgplots manual)
\def\axisdefaultticklabel{$\pgfmathprintnumber{\tick}$}