0

I am trying to put two figures side by side using the subfig package (I´ve done this in the past, even with tikzpictures) but I am facing a problem.

Whenever I try to compile my document I get multiple errors including:

Paragraph ended before \pgfplots@addplotimpl@table@startprocessing was complete. }
Extra }, or forgotten \endgroup. }
Package PGF Math Error: Sorry, an internal routine of the floating point unit '0.0'.. }
Illegal unit of measure (pt inserted). }

Trying to debug this I commented the tikzpicture enviroments and it compiled succesfully, then I commented everything but the tikzpicture part and it compiled again!

What could be causing this set of errors?

My MWE is:

\documentclass[12pt,letterpaper,twoside]{report}

\usepackage{pgfplots}
\usepackage{pgfplotstable}
\usepackage{subfig}  
\begin{document}
    \begin{figure}
    \centering
    \subfloat[caption1.]
    {\label{label1}%
        \begin{tikzpicture}
    \begin{axis}[%
    scatter/classes={%
        a={mark=o,draw=red},b={draw=blue}},
    xlabel={Pieza},
    ylabel={Medición},legend pos=outer north east]
    \addplot[scatter,only marks,ycomb,%
    scatter src=explicit symbolic]%
    table[meta=label] {
        x y label
        1   0.2842  a
        2   0.2985  a
        3   0.2509  a
        4   0.2314  a
        5   0.2091  a
        6   0.2046  a
        7   0.3177  a
        8   0.215   a
        9   0.2057  a
        10  0.2244  a


    };
    \addplot[scatter,only marks,ycomb,%
    scatter src=explicit symbolic]%
    table[meta=label] {
        x y label
        1   0.1284  b
        2   0.1857  b
        3   0.1068  b
        4   0.2618  b
        5   0.2061  b
        6   0.3119  b
        7   0.3589  b
        8   0.2599  b
        9   0.2745  b
        10  0.2044  b



    };
    \legend{LVDT,CMM}

    \end{axis}
    \end{tikzpicture}
} 
    \quad
    \subfloat[caption2.]
    {\label{label2}%
    \begin{tikzpicture}
    \begin{axis}[%
    scatter/classes={%
        a={mark=o,draw=black}},
    xlabel={Temperatura (\(^{\circ}\)C)},
    ylabel={Perpendicularidad (\(^{\circ}\)}]
    \addplot[scatter,only marks,%
    scatter src=explicit symbolic]%
    table[meta=label] {
        x y label
        51.24       -0.4545 a
        60.13       0.046   a
        58.68       -0.1905 a
        54.03       -0.339  a
        55.16       0.3885  a
        56.62       0.1 a
        54.09       0.0365  a
        58.06       -0.1215 a
        57.05       0.126   a
        52.26       0.4025  a

    };
    \end{axis}
    \end{tikzpicture}
} 
    \caption{caption3}\label{label3}
\end{figure}
\end{document}

My commented tikzpicture environment MWE is:

\documentclass[12pt,letterpaper,twoside]{report}

\usepackage{pgfplots}
\usepackage{pgfplotstable}
\usepackage{subfig}  
\begin{document}
    \begin{figure}
    \centering
    \subfloat[caption1.]
    {\label{label1}%
%       \begin{tikzpicture}
%   \begin{axis}[%
%   scatter/classes={%
%       a={mark=o,draw=red},b={draw=blue}},
%   xlabel={Pieza},
%   ylabel={Medición},legend pos=outer north east]
%   \addplot[scatter,only marks,ycomb,%
%   scatter src=explicit symbolic]%
%   table[meta=label] {
%       x y label
%       1   0.2842  a
%       2   0.2985  a
%       3   0.2509  a
%       4   0.2314  a
%       5   0.2091  a
%       6   0.2046  a
%       7   0.3177  a
%       8   0.215   a
%       9   0.2057  a
%       10  0.2244  a
%       
%       
%   };
%   \addplot[scatter,only marks,ycomb,%
%   scatter src=explicit symbolic]%
%   table[meta=label] {
%       x y label
%       1   0.1284  b
%       2   0.1857  b
%       3   0.1068  b
%       4   0.2618  b
%       5   0.2061  b
%       6   0.3119  b
%       7   0.3589  b
%       8   0.2599  b
%       9   0.2745  b
%       10  0.2044  b
%       
%       
%       
%   };
%   \legend{LVDT,CMM}
%   
%   \end{axis}
%   \end{tikzpicture}
} 
    \quad
    \subfloat[caption2.]
    {\label{label2}%
%   \begin{tikzpicture}
%   \begin{axis}[%
%   scatter/classes={%
%       a={mark=o,draw=black}},
%   xlabel={Temperatura (\(^{\circ}\)C)},
%   ylabel={Perpendicularidad (\(^{\circ}\)}]
%   \addplot[scatter,only marks,%
%   scatter src=explicit symbolic]%
%   table[meta=label] {
%       x y label
%       51.24       -0.4545 a
%       60.13       0.046   a
%       58.68       -0.1905 a
%       54.03       -0.339  a
%       55.16       0.3885  a
%       56.62       0.1 a
%       54.09       0.0365  a
%       58.06       -0.1215 a
%       57.05       0.126   a
%       52.26       0.4025  a
%       
%   };
%   \end{axis}
%   \end{tikzpicture}
} 
    \caption{caption3}\label{label3}
\end{figure}
\end{document}

My MWE with everything but the tikzpictures commented is:

\documentclass[12pt,letterpaper,twoside]{report}

\usepackage{pgfplots}
\usepackage{pgfplotstable}
\usepackage{subfig}  
\begin{document}
%   \begin{figure}
%   \centering
%   \subfloat[caption1.]
%   {\label{label1}%
        \begin{tikzpicture}
    \begin{axis}[%
    scatter/classes={%
        a={mark=o,draw=red},b={draw=blue}},
    xlabel={Pieza},
    ylabel={Medición},legend pos=outer north east]
    \addplot[scatter,only marks,ycomb,%
    scatter src=explicit symbolic]%
    table[meta=label] {
        x y label
        1   0.2842  a
        2   0.2985  a
        3   0.2509  a
        4   0.2314  a
        5   0.2091  a
        6   0.2046  a
        7   0.3177  a
        8   0.215   a
        9   0.2057  a
        10  0.2244  a


    };
    \addplot[scatter,only marks,ycomb,%
    scatter src=explicit symbolic]%
    table[meta=label] {
        x y label
        1   0.1284  b
        2   0.1857  b
        3   0.1068  b
        4   0.2618  b
        5   0.2061  b
        6   0.3119  b
        7   0.3589  b
        8   0.2599  b
        9   0.2745  b
        10  0.2044  b



    };
    \legend{LVDT,CMM}

    \end{axis}
    \end{tikzpicture}
%} 
%   \quad
%   \subfloat[caption2.]
%   {\label{label2}%
    \begin{tikzpicture}
    \begin{axis}[%
    scatter/classes={%
        a={mark=o,draw=black}},
    xlabel={Temperatura (\(^{\circ}\)C)},
    ylabel={Perpendicularidad (\(^{\circ}\)}]
    \addplot[scatter,only marks,%
    scatter src=explicit symbolic]%
    table[meta=label] {
        x y label
        51.24       -0.4545 a
        60.13       0.046   a
        58.68       -0.1905 a
        54.03       -0.339  a
        55.16       0.3885  a
        56.62       0.1 a
        54.09       0.0365  a
        58.06       -0.1215 a
        57.05       0.126   a
        52.26       0.4025  a

    };
    \end{axis}
    \end{tikzpicture}
%} 
%   \caption{caption3}\label{label3}
%\end{figure}
\end{document}

1 Answer 1

2

The problem is that you are asking pgfplotstable to read inline table data from the ... argument in \subfloat[caption x.]{...}. As soon as the \subfloat macro is expanded, this braced argument is tokenized, with the consequence that single end-of-lines in your table data become indistinguishable from spaces: both become space tokens1 when tokenized. The immediate consequence is that pgfplotstable can't read the tables, since it can't see where lines end.

There are several ways to solve this problem. Depending on how other subcaption-like packages that provide an environment are implemented (for instance, subcaption has a subfigure environment), simply switching to such a solution could work. But if the environment body is read as a delimited argument, which is a possibility, the problem with remain.

Another way, and this is the one I'll propose here, consists in reading your table data elsewhere, in a place where single end-of-lines are quite distinct from spaces. This can be done with the \pgfplotstableread command that allows one to read table data and store the result in a macro of your choice.

I added \pgfplotsset{compat=1.16} to ensure reproducibility of the code. I also set the document in landscape mode, otherwise the arrangement of the two subfigures wouldn't be very compelling due to lack of space—you may of course find other solutions for portrait mode.

\documentclass[landscape]{article}
\usepackage{geometry}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\usepackage{pgfplotstable}
\usepackage{subfig}

\pgfplotstableread{
x   y       label
1   0.2842  a
2   0.2985  a
3   0.2509  a
4   0.2314  a
5   0.2091  a
6   0.2046  a
7   0.3177  a
8   0.215   a
9   0.2057  a
10  0.2244  a
}\myFirstTable

\pgfplotstableread{
x   y       label
1   0.1284  b
2   0.1857  b
3   0.1068  b
4   0.2618  b
5   0.2061  b
6   0.3119  b
7   0.3589  b
8   0.2599  b
9   0.2745  b
10  0.2044  b
}\mySecondTable

\pgfplotstableread{
x       y        label
51.24   -0.4545  a
60.13   0.046    a
58.68   -0.1905  a
54.03   -0.339   a
55.16   0.3885   a
56.62   0.1      a
54.09   0.0365   a
58.06   -0.1215  a
57.05   0.126    a
52.26   0.4025   a
}\myThirdTable

\begin{document}

  \begin{figure}
    \centering
    \subfloat[caption1.]
      {%
        \label{label1}%
        \begin{tikzpicture}
          \begin{axis}[%
              scatter/classes={%
              a={mark=o,draw=red},b={draw=blue}},
              xlabel={Pieza},
              ylabel={Medición},legend pos=outer north east]
          \addplot[scatter, only marks, ycomb, scatter src=explicit symbolic]
            table[meta=label] {\myFirstTable};
          \addplot[scatter, only marks, ycomb, scatter src=explicit symbolic]
            table[meta=label] {\mySecondTable};
          \legend{LVDT,CMM}
          \end{axis}
        \end{tikzpicture}%
      }%
    \quad
    \subfloat[caption2.]
      {%
        \label{label2}%
        \begin{tikzpicture}
          \begin{axis}[%
          scatter/classes={%
              a={mark=o,draw=black}},
          xlabel={Temperatura (\(^{\circ}\)C)},
          ylabel={Perpendicularidad (\(^{\circ}\))}]
          \addplot[scatter, only marks, scatter src=explicit symbolic]
            table[meta=label] {\myThirdTable};
          \end{axis}
        \end{tikzpicture}%
      }%
    \caption{caption3}\label{label3}
  \end{figure}

\end{document}

screenshot


Footnote

  1. That is, character tokens with character code 32 and category code 10.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .