我该如何调试错误“\XC@definec@lor 的参数有一个多余的}”?

我该如何调试错误“\XC@definec@lor 的参数有一个多余的}”?

以下代码输出错误:

Argument of \XC@definec@lor has an extra }.
<inserted text> 
                \par 
l.26     \end{axis}

但是,我无法调试并找到导致错误的代码。

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{pgfplots}
% \usepgfplotslibrary{statistics}
\pgfplotsset{compat=1.14}
% \usepackage{tikz}
\usetikzlibrary{patterns}

\begin{document}

\begin{figure}[tb]
\centering
\hspace*{-0.32cm}
\begin{tikzpicture}[font=\scriptsize]
    \begin{axis}[ybar stacked,
    height=4.5cm,width=9cm,
    ymin=0,ymax=5,
    ylabel style = {align=center},
    ylabel={\# relevant score},
    symbolic x coords={Launch,Options,Text Input,Text\\Display,Fixed-item\\List,Dynamic-\\item List},
    xticklabel style={align=center},
    nodes near coords,
%   nodes near coords align={vertical},
%     nodes near coords style={/pgf/number format/fixed,
%     /pgf/number format/fixed zerofill,
%     /pgf/number format/precision=2},
%     every node near coord/.append style={font=\scriptsize},
    ]
        \addplot coordinates
            {(Launch,3.93) (Options,4) (Text Input,4.38) (Text\\Display,3.35) (Fixed-item\\List,3.44) (Dynamic-\\item List,4.32)};
    \end{axis}
\end{tikzpicture}
% \vspace*{-0.5cm}
\caption{Relevance evaluation result from experiment participants}
\label{fig:user_scores}
\end{figure}

\end{document}

答案1

问题在于换行符。类似地这个很好的答案,您可以定义没有它们的符号坐标,但将它们放在标签中。

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{pgfplots}
% \usepgfplotslibrary{statistics}
\pgfplotsset{compat=1.14}
% \usepackage{tikz}
\usetikzlibrary{patterns}

\begin{document}

\begin{figure}[tb]
\centering
\hspace*{-0.32cm}
\begin{tikzpicture}[font=\scriptsize]
    \begin{axis}[ybar stacked,
    height=4.5cm,width=9cm,
    ymin=0,ymax=5,
    ylabel style = {align=center},
    ylabel={\# relevant score},
    symbolic x coords={Launch,Options,Text Input,
    Text Display,Fixed-item List,Dynamic-item List},
    xticklabels={,Launch,Options,Text Input,
    Text\\ Display,Fixed-\\item List,Dynamic-\\item List},
    xticklabel style={align=center},
    nodes near coords,
%   nodes near coords align={vertical},
%     nodes near coords style={/pgf/number format/fixed,
%     /pgf/number format/fixed zerofill,
%     /pgf/number format/precision=2},
%     every node near coord/.append style={font=\scriptsize},
    ]
        \addplot coordinates
            {(Launch,3.93) (Options,4) (Text Input,4.38)
             (Text Display,3.35)
            (Fixed-item List,3.44) (Dynamic-item List,4.32)
            };
    \end{axis}
\end{tikzpicture}
% \vspace*{-0.5cm}
\caption{Relevance evaluation result from experiment participants}
\label{fig:user_scores}
\end{figure}
\end{document}

在此处输入图片描述

相关内容