3

I make bar plot with pgfplots:

\documentclass{report}

\usepackage[T2A]{fontenc} % Поддержка русских букв
\usepackage[utf8]{inputenc} % Кодировка utf8
\usepackage[english, russian]{babel} % Языки: русский,

\usepackage{pgfplots}
\pgfplotsset{
every axis legend/.append style={at={(0.5,-0.13)},anchor=north,legend cell align=left},
tick label style={font=\tiny\scriptsize},
legend style={font=\scriptsize},
axis lines=left,
legend style={draw=none},
}
\begin{document}

\begin{figure} [H]
\centering
\begin{tikzpicture}
\begin{axis} [
ylabel={$T$},
ybar,
enlarge x limits=.15,
symbolic x coords={wer,good,neutral,not good,poor},
xtick=data,
bar shift=0pt
]

\addplot coordinates {(wer,1) (good,8)
(neutral,2) (not good,0) (poor,10)};

\end{axis}
\end{tikzpicture}
\caption{Прочность металлоизделий}
\end{figure}

\end{document}

And it works. enter image description here

But when I use Cyrillic characters in symbolic x coords: symbolic x coords={сейчас,good,neutral,not good,poor},, I get an error when compiling.

\documentclass{report}

\usepackage[T2A]{fontenc} % Поддержка русских букв
\usepackage[utf8]{inputenc} % Кодировка utf8
\usepackage[english, russian]{babel} % Языки: русский,

\usepackage{pgfplots}
\pgfplotsset{
every axis legend/.append style={at={(0.5,-0.13)},anchor=north,legend cell align=left},
tick label style={font=\tiny\scriptsize},
legend style={font=\scriptsize},
axis lines=left,
legend style={draw=none},
}
\begin{document}

\begin{figure} [H]
\centering
\begin{tikzpicture}
\begin{axis} [
ylabel={$T$},
ybar,
enlarge x limits=.15,
symbolic x coords={сейчас,good,neutral,not good,poor},
xtick=data,
bar shift=0pt
]

\addplot coordinates {(сейчас,1) (good,8)
(neutral,2) (not good,0) (poor,10)};

\end{axis}
\end{tikzpicture}
\caption{Прочность металлоизделий}
\end{figure}

\end{document}

Errors:

Missing \endcsname inserted ]
Missing \endcsname inserted (neutral,2) (not good,0) (poor,10)};
Missing \endcsname inserted (neutral,2) (not good,0) (poor,10)};
Use of \pgfp@symb@coords@x@ doesn't match its definition (neutral,2) (not good,0) (poor,10)};
Missing \endcsname inserted (neutral,2) (not good,0) (poor,10)};
Missing \endcsname inserted (neutral,2) (not good,0) (poor,10)};
Extra \endcsname (neutral,2) (not good,0) (poor,10)};
Extra \endcsname (neutral,2) (not good,0) (poor,10)};
Illegal parameter number in definition of \pgfmathresult (neutral,2) (not good,0) (poor,10)};
Illegal parameter number in definition of \pgfmathresult (neutral,2) (not good,0) (poor,10)};
Illegal parameter number in definition of \pgfmathresult (neutral,2) (not good,0) (poor,10)};
Illegal parameter number in definition of \pgfmathresult (neutral,2) (not good,0) (poor,10)};
Illegal parameter number in definition of \pgfmathresult (neutral,2) (not good,0) (poor,10)};
Illegal parameter number in definition of \pgfmathresult (neutral,2) (not good,0) (poor,10)};
Illegal parameter number in definition of \pgfmathresult (neutral,2) (not good,0) (poor,10)};
Illegal parameter number in definition of \pgfmathresult (neutral,2) (not good,0) (poor,10)};
Illegal parameter number in definition of \pgfmathresult (neutral,2) (not good,0) (poor,10)};
Illegal parameter number in definition of \pgfmathresult (neutral,2) (not good,0) (poor,10)};
running in backwards compatibility mode (unsuitable tick labels; missing features). Consider writing \pgfplotsset{compat=1.8} into your preamble.

Elsewhere Cyrillic text does not cause errors.

How can this be solved?

5

The list of symbolic coordinates is used in two ways: for printing the names and for referring to them later. This second usage is the problem: what's basically done for the symbolic coordinate good is

\def\PREFIXgood{1}

(where PREFIX is some string, irrelevant for the discussion) so that the macros can then substitute (good,8) with

(\PREFIXgood,8)

The value 1 is automatically assigned, the symbolic coordinate list starts at zero. This process uses \csname (see What exactly do \csname and \endcsname do?) and, unfortunately, Cyrillic letters aren't legal in this context. The letter ч, for example, must be remapped to the slot it is assigned to in the T2A encoding, so LaTeX first translates it into \cyrch, but now this command has to perform some actions that aren't legal in \csname. Only plain alphanumeric ASCII characters are legal in this context.

There are two workarounds: the first is to use xticklabels and the corresponding numbers in \addplot coordinates:

\begin{tikzpicture}
\begin{axis} [
  ylabel={$T$},
  ybar,
  enlarge x limits=.15,
  xticklabels={сейчас,good,neutral,not good,poor},
  xtick=data,
  bar shift=0pt
]
\addplot coordinates {(0,1) (1,8) (2,2) (3,0) (4,10)};
\end{axis}
\end{tikzpicture}

The second workaround is more drastic: using LuaLaTeX (or XeLaTeX): in this case Cyrillic letters become characters like any other and are legal in \csname.

\documentclass[a4paper]{report}

\usepackage[english,russian]{babel} % Языки: русский,

\usepackage{fontspec}
\setmainfont[Ligatures=TeX]{CMU Serif}

\usepackage{pgfplots}
\pgfplotsset{compat=1.9}

\pgfplotsset{
  every axis legend/.append style={
    at={(0.5,-0.13)},
    anchor=north,
    legend cell align=left,
  },
  tick label style={font=\tiny\scriptsize},
  xticklabel style={
    anchor=base,
    yshift=-\baselineskip
  },
  legend style={font=\scriptsize},
  axis lines=left,
  legend style={draw=none},
}

\begin{document}

\begin{figure}
\centering
\begin{tikzpicture}
\begin{axis} [
  ylabel={$T$},
  ybar,
  enlarge x limits=.15,
  symbolic x coords={сейчас,good,neutral,not good,poor},
  xtick=data,
  bar shift=0pt
]
\addplot coordinates {(сейчас,1) (good,8) (neutral,2) (not good,0) (poor,10)};
\end{axis}
\end{tikzpicture}
\caption{Прочность металлоизделий}
\end{figure}

\end{document}

Note the addition of

\pgfplotsset{compat=1.9}

and of

  xticklabel style={
    anchor=base,
    yshift=-\baselineskip
  },

so that labels are aligned to their baselines. You should do this in any case, not only for LuaLaTeX.

The output will be the same:

enter image description here

  • Way with xticklabels helped me. Thank you! – Harrix Jan 11 '14 at 18:02

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.