Making a tikzpicture Subfigure

1,060

After successfully guessing the packages you used and correcting the mistake of not closing both \resizeboxes, it worked just fine.

There was a } missing after \end{tikzpicture} and the second \resizebox was also not complete (see comments).

\documentclass{article}
\usepackage{tikz}
\usepackage{pgfplots}
\usepackage{pgfplotstable}
\usepackage{subcaption}
\begin{document}
\begin{figure}
\pgfplotstableread[col sep=comma]{
Test, 0
Rater1- Rater 2+ (Disagreement), 0.007
Rater1+ Rater 2- (Disagreement), 0.58
Rater1- Rater 2- (Agreement), 98.47
Rater1+ Rater 2+ (Agreement), 0.95
}
\piedata
\begin{subfigure}[b]{0.42\textwidth}
        \centering
        \resizebox{\linewidth}{!}{
\begin{tikzpicture}
\begin{axis}[
xbar,
xlabel={\% Observed},
yticklabels from table={\piedata}{[index]0},
ytick=data,
axis lines=left,
xmin=0,
enlarge y limits,
nodes near coords={\pgfmathprintnumber\pgfplotspointmeta\%}
]
\addplot table[x index=1,y expr=\coordindex] {\piedata};
\end{axis}
\end{tikzpicture}} % added } here to close the first \resizebox 
\end{subfigure}
\begin{subfigure}[b]{0.42\textwidth}
        \centering
        % and closed this one too
        \resizebox{\linewidth}{!}{insert other subfigure here}
\end{subfigure}
\end{figure}
\end{document}

Btw.: the usual error message for these things is

File ended while scanning use of ...

followed by some command name, which may be unknown to most users. But it tells you, that something wasn't closed. To get a hint where to find the problem, you should look into the log file itself. TeXStudio and other TeX IDEs tend to only tell half the story in the error tab. In the log file (shown in the log tab, go there by selecting the error in the error tab, then change to the log tab) the error looks like this:

Runaway argument?
{ \begin {tikzpicture} \begin {axis}[ xbar, xlabel={\% Observed}, yti\ETC.
! File ended while scanning use of \Gscale@box@dd.
...

The interesting part is the line before File ended .... It is the start of the argument which wasn't closed with }. There are no line breaks here, but usually it's enough to find it in the source.

Share:
1,060

Related videos on Youtube

Admin
Author by

Admin

Updated on July 25, 2020

Comments

  • Admin
    Admin over 3 years

    I'm trying to create a subfigure with my bar chart. However, the \pgfplotstableread command seems to be getting in the way of the subfigure function. Any help is very much appreciated... Thank you in advance!

    \begin{figure}
    \pgfplotstableread[col sep=comma]{
    Test, 0
    Rater1- Rater 2+ (Disagreement), 0.007
    Rater1+ Rater 2- (Disagreement), 0.58
    Rater1- Rater 2- (Agreement), 98.47
    Rater1+ Rater 2+ (Agreement), 0.95
    }
    \piedata
    \begin{subfigure}[b]{0.42\textwidth}
            \centering
            \resizebox{\linewidth}{!}{
    \begin{tikzpicture}
    \begin{axis}[
    xbar,
    xlabel={\% Observed},
    yticklabels from table={\piedata}{[index]0},
    ytick=data,
    axis lines=left,
    xmin=0,
    enlarge y limits,
    nodes near coords={\pgfmathprintnumber\pgfplotspointmeta\%}
    ]
    \addplot table[x index=1,y expr=\coordindex] {\piedata};
    \end{axis}
    \end{tikzpicture}
    \end{subfigure}
    \begin{subfigure}[b]{0.42\textwidth}
            \centering
            \resizebox{\linewidth}{!}{
    %%insert other subfigure here}
    \end{subfigure}
    \end{figure}
    
    • Mensch
      Mensch over 6 years
      Welcome to TeX.SE! Please make your code snippet compilable ...
    • Mace
      Mace over 6 years
      Have you tried putting \pgfplotstableread inside the subfigure environment?
    • Mike
      Mike over 6 years
      After successfully guessing the packages you used and correcting the mistake of not closing both \resizeboxes, it worked just fine. There is a } missing after \end{tikzpicture} and the second \resizebox is also not complete.
    • Stefan Pinnow
      Stefan Pinnow over 6 years
      I'm voting to close this question as off-topic because the issue was solved by correcting some typos.
    • percusse
      percusse over 6 years
      @StefanPinnow It's a bit more constructive if we ask the commenter first to write an answer first. They might have gotten caught up with other things.
    • samcarter_is_at_topanswers.xyz
      samcarter_is_at_topanswers.xyz over 6 years
      @Mike Would you like to write an answer?
    • Mike
      Mike over 6 years
      @samcarter: ok, done