[Tex/LaTex] Caption a tikzpicture on standalone

captionsfloatspgfplotsstandalonetikz-pgf

Title says it all:

\documentclass{standalone}

\usepackage{tikz}
\usepackage{pgfplots}
\usetikzlibrary{arrows}
\usepackage{caption}

\begin{document}

\begin{figure}
\centering
\begin{tikzpicture}
  \begin{axis}[
    title=myTtitle,
    xlabel=$x$,
    ylabel=$y$]
    \addplot coordinates {
        (10, 1) 
        (20, 2)
    };
  \end{axis}
\end{tikzpicture}
\caption{A caption.}
\end{figure}
\end{document}

Error:

LaTeX Error: Something's wrong–perhaps a missing \item.

on \begin{figure}.

Shall you change standalone to document it will work, but it will make the plot so small in comparison with the standalone version… :/

Best Answer

The same result as with John Kormylo answer you obtain with option preview of standalone package (with out use of mini pages), so see extended version of my comment:

\documentclass[preview]{standalone}
\usepackage{tikz}
\usepackage{pgfplots}
\usepackage{caption}

\begin{document}
    \begin{figure}
    \centering
\begin{tikzpicture}
  \begin{axis}[
    name=border,
    title=myTtitle,
    xlabel=$x$,
    ylabel=$y$]
    \addplot coordinates {
        (10, 1)
        (20, 2)
    };
  \end{axis}
\end{tikzpicture}
\caption{A caption.}
    \end{figure}
\end{document}

enter image description here