1

when i run this .tex file as input

\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.12}
\usepackage{subcaption}
\usepackage{graphics}
\usepackage{tikz}

\begin{document}
\begin{figure}[t!p]
\caption{Value}
\centering
\begin{subfigure}{0.7\textwidth}
\centering
\resizebox{\linewidth}{!}{
\begin{tikzpicture}[scale=0.5]
\begin{axis}[\axisoptsa]
\addplot table [y=0 , x=row]{file.csv};
\addlegendentry{Ciao}
\addplot table [y=1, x=row ]{file.csv};
\addlegendentry{Bau}
\end{axis}
\end{tikzpicture}
}
\caption{Tot}
\label{tot}
\end{subfigure}
\\
\par\bigskip 
\begin{subfigure}{.3\textwidth}
\centering
\resizebox{\linewidth}{!}{
\begin{tikzpicture}
\begin{axis}[\axisoptsa]
\addplot table [y=0 , x=Row Labels]{file1.csv};
\addlegendentry{Ciao}
\addplot table [y=1, x=Row Labels]{file1.csv};
\addlegendentry{Bau}
\end{axis}
\end{tikzpicture}  
}
\caption{Micro}
\label{Micro}
\end{subfigure}%
\qquad\qquad
\begin{subfigure}{.3\textwidth}
\centering
\resizebox{\linewidth}{!}{
\begin{tikzpicture}
\begin{axis}[\axisoptsa]
\addplot table [y=0 , x=Row Labels]{file2.csv};
\addlegendentry{Ciao}
\addplot table [y=1, x=Row Labels]{file2.csv};
\addlegendentry{Bau}
\end{axis}
\end{tikzpicture} 
} 
\caption{Small}
\label{Small}
\end{subfigure}%
\\
\begin{subfigure}{.3\textwidth}
\centering
\resizebox{\linewidth}{!}{
\begin{tikzpicture}
\begin{axis}[\axisoptsa]
\addplot table [y=0 , x=Row Labels]{EMR_VA_classe3.csv};
\addlegendentry{Ciao}
\addplot table [y=1, x=Row Labels]{EMR_VA_classe3.csv};
\addlegendentry{Bau}
\end{axis}
\end{tikzpicture} 
} 
\caption{Medium}
\label{ Medium }
\end{subfigure}%
\qquad\qquad
\begin{subfigure}{.3\textwidth}
\centering
\resizebox{\linewidth}{!}{
\begin{tikzpicture}
\begin{axis}[\axisoptsa]
\addplot table [y=0 , x=Row Labels]{file3.csv};
\addlegendentry{Ciao}
\addplot table [y=1, x=Row Labels]{file3.csv};
\addlegendentry{Bau}
\end{axis}
\end{tikzpicture} 
} 
\caption{Big}
\label{Big}
\end{subfigure}
\end{figure}
   \end{document}

it works perfectly. However, when I insert the second one, with different data, in works but the caption skips a number (from Figure 1 to Figure 3). This does not happen if I put the caption at the bottom, but I really need it at the top. Does someone know why this happens?

Edit I hope now the MWE is within the standards. Pls let me know

  • 1
    Please make your MWE complete that it can be compiled! – Zarko Nov 12 '15 at 17:18
  • Try adding the option figureposition=t to \usepackage[...]{caption} and position=b to \usepackage[...]{subcaption}. The default of them is auto but this includes guessing and this might get wrong in your case, especially since you have different caption positions of main and sub-caption in figures. (See caption package manual for details.) – Axel Sommerfeldt Nov 14 '15 at 7:01
  • Thanks Alex, but it doesnt work for this case =( – Mino Nov 16 '15 at 8:56
  • I cannot compile your new document: ! Undefined control sequence. \pgfkeyscurrentkey ->\axisoptsa. (I'm using TeXlive 2015 w/ updates.) When I try to comment out the usage of \axisoptsa and building all the CSV files on my own to have example data, I still get an error: ! Package pgfplots Error: Sorry, could not retrieve column 'row' from table '\\ pgfplotstableread@filename@@table@name '. Please check spelling (or introduce n ame aliases)... I'm sorry, I'm not familiar with pgfplots at all, so I need an example document I CAN compile to examine the problem. – Axel Sommerfeldt Nov 17 '15 at 8:32
  • ...and furthermore you even claim yourself that your example code is NOT showing the problem, one need to add further figures for showing the problem. But we need example code which actually DO show the problem. – Axel Sommerfeldt Nov 17 '15 at 8:38
4

Since your MWE is not complete. I can anly guess, what is your problem. The following approximation of your MWE gives results as you like to obtain (if I understand correctly your question):

enter image description here

I'm very sure, that this figure composition haven't any influence on tikz or pgfplots pictures in subfigure.

\documentclass{article}
    \usepackage{subcaption}
    \usepackage{graphicx}

    \begin{document}
\begin{figure}[htbp]
    \caption{Value}
    \centering
\begin{subfigure}{0.7\textwidth}
    \centering
    \caption{Tot}
    \label{tot}
\includegraphics[width=0.9\hsize]{example-image}% instead example-image 
                                                % you can put here tikz 
                                                % or pgfplots picture
\end{subfigure}

\bigskip
\begin{subfigure}{.3\textwidth}
    \centering
    \caption{Micro}
    \label{Micro}
\includegraphics[width=0.9\hsize]{example-image}
\end{subfigure}%
    \hfil
\begin{subfigure}{.3\textwidth}
    \centering
    \caption{Small}
    \label{Small}
\includegraphics[width=0.9\hsize]{example-image}
\end{subfigure}%

\bigskip
\begin{subfigure}{.3\textwidth}
\centering
    \caption{Medium}
    \label{ Medium }
\includegraphics[width=0.9\hsize]{example-image}
\end{subfigure}%
    \hfil
\begin{subfigure}{.3\textwidth}
    \centering
    \caption{Big}
    \label{Big}
\includegraphics[width=0.9\hsize]{example-image}
\end{subfigure}
    \end{figure}

text
    \begin{figure}[htb]
    \caption{Value}
    \label{tot}
\includegraphics[width=0.9\hsize]{example-image}
    \end{figure}
    \end{document}

Edit: In code I add one more figure to show, that the numbering of figures work properly. I left old image (with only one figure), for new You need just to test given MWE.

Addendum: here is example where instead example-image I insert some dummy pgfplots images. As can be seen, also there is not problem with numbering of images:

enter image description here

New MWE is:

\documentclass{article}
    \usepackage{pgfplots}
    \pgfplotsset{compat=1.12}
    \usepackage{subcaption}
    \usepackage{graphicx}

    \usepackage{lipsum}

    \begin{document}
\lipsum[1]

\begin{figure}[htbp]
    \caption{Value}
    \centering
\begin{subfigure}{0.7\textwidth}
    \centering
    \caption{Tot}
    \label{tot}
\begin{tikzpicture}
    \begin{axis}[width = 8cm, height=4cm,
                ylabel = {$y(t)$},  xlabel = {t},
          legend style = {at={(1.02,0.5)}, anchor=west},%, legend columns=-1
                  grid,
                ]
\addplot coordinates {(1, 1)    (9, 5)};
\addplot coordinates {(1, 5)    (9, 1)};
        \legend{case 1, case 2}
    \end{axis}
\end{tikzpicture}
\end{subfigure}

\bigskip
\begin{subfigure}{.3\textwidth}
    \centering
    \caption{Micro}
    \label{Micro}
\begin{tikzpicture}
    \begin{axis}[width = 4cm, height=4cm,
                ylabel = {$y(t)$},  xlabel = {t},
          legend style = {at={(1.02,0.5)}, anchor=west},%, legend columns=-1
                  grid,
                ]
\addplot coordinates {(1, 1)    (9, 5)};
\addplot coordinates {(1, 5)    (9, 1)};
        \legend{case 1, case 2}
    \end{axis}
\end{tikzpicture}
\end{subfigure}%
    \hfil
\begin{subfigure}{.3\textwidth}
    \centering
    \caption{Small}
    \label{Small}
\begin{tikzpicture}
    \begin{axis}[width = 4cm, height=4cm,
                ylabel = {$y(t)$},  xlabel = {t},
          legend style = {at={(1.02,0.5)}, anchor=west},%, legend columns=-1
                  grid,
                ]
\addplot coordinates {(1, 1)    (9, 5)};
\addplot coordinates {(1, 5)    (9, 1)};
        \legend{case 1, case 2}
    \end{axis}
\end{tikzpicture}
\end{subfigure}%

\bigskip
\begin{subfigure}{.3\textwidth}
\centering
    \caption{Medium}
    \label{ Medium }
\begin{tikzpicture}
    \begin{axis}[width = 4cm, height=4cm,
                ylabel = {$y(t)$},  xlabel = {t},
          legend style = {at={(1.02,0.5)}, anchor=west},%, legend columns=-1
                  grid,
                ]
\addplot coordinates {(1, 1)    (9, 5)};
\addplot coordinates {(1, 5)    (9, 1)};
        \legend{case 1, case 2}
    \end{axis}
\end{tikzpicture}
\end{subfigure}%
    \hfil
\begin{subfigure}{.3\textwidth}
    \centering
    \caption{Big}
    \label{Big}
\begin{tikzpicture}
    \begin{axis}[width = 4cm, height=4cm,
                ylabel = {$y(t)$},  xlabel = {t},
          legend style = {at={(1.02,0.5)}, anchor=west},%, legend columns=-1
                  grid,
                ]
\addplot coordinates {(1, 1)    (9, 5)};
\addplot coordinates {(1, 5)    (9, 1)};
        \legend{case 1, case 2}
    \end{axis}
\end{tikzpicture}
\end{subfigure}
    \end{figure}

\lipsum[2]

    \begin{figure}[htb]
    \caption{Value}
    \label{tot}
\begin{tikzpicture}
    \begin{axis}[width = 8cm, height=4cm,
                ylabel = {$y(t)$},  xlabel = {t},
          legend style = {at={(1.02,0.5)}, anchor=west},%, legend columns=-1
                  grid,
                ]
\addplot coordinates {(1, 1)    (9, 5)};
\addplot coordinates {(1, 5)    (9, 1)};
        \legend{case 1, case 2}
    \end{axis}
\end{tikzpicture}
    \end{figure}
    \end{document}

In my MWE I omit all resizebox construction, to my opinion they not serve for anything. If you like to have smaller/biger images, adequately change image size (with width and height).

  • 1
    Thank you @Zarko sorry for my MWE. You got it right, as I do. The problem is that, as I wrote, when I run a second figure, the caption of this latter, instead of being "Figure 2", is "Figure 3". – Mino Nov 16 '15 at 8:59
  • 1
    Please provide complete MWE, which demonstrate your problem. I (and others) can only guess, what is going wrong. What you describe in normal circumstances cannot happen! Test my upgrade answer, it confirm this. – Zarko Nov 16 '15 at 9:46
  • is it alright now? thanks for your suggestions – Mino Nov 17 '15 at 9:30
  • I changed my code according to suggestions, can someone find why it still gives me the wrong caption numbering? – Mino Nov 18 '15 at 8:23
  • 1
    @Giacomo, I can not compile your MWE as is, because I haven't your csv files. I suggest you, that you first test my answer and see, if the image numbers are in right order. After this in it replace example-image with your real image. If after then you receive error, than is something wrong in your image. If this is case and you need help, ask new question, where you provide your pgfplot image with included table file.csv and all pgfplotset or tikzset definition. I will try to make dummy example with pgfplots, that you will see, that they as such can not cause your problem. – Zarko Nov 18 '15 at 9:47

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.