2

How can I add caption under my function, for example [Fig 1], and how can I refer to that figure?

My Code:

\begin{tikzpicture}
    \begin{axis}[
        xlabel=$x$,
        ylabel=$\mu(x)$
    ]
    % invoke external gnuplot as
    % calculator:
    \addplot[smooth,samples=180,domain=0.0001:20] {1/(1+(1/x))};
    \end{axis}
\end{tikzpicture}
3
  • \begin{figure}\begin{tikzpicture}...\end{tikzpicture}\caption{Caption}\label{fig:figure}\end{figure}?
    – cfr
    Feb 8, 2015 at 16:02
  • I tried that and it just disappears when I add the figure tag..
    – MrDi
    Feb 8, 2015 at 16:20
  • Then we need a minimal document which shows the problem when compiled.
    – cfr
    Feb 9, 2015 at 2:53

1 Answer 1

3

You can put your plot inside figure environment and add the caption as usual.

\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.11}
\begin{document}
  \begin{figure}
    \centering
    \begin{tikzpicture}
    \begin{axis}[
        xlabel=$x$,
        ylabel=$\mu(x)$
    ]
    % invoke external gnuplot as
    % calculator:
    \addplot[smooth,samples=180,domain=0.0001:20] {1/(1+(1/x))};
    \end{axis}
\end{tikzpicture}
  \caption{This is my plot}\label{fig:myplot}
  \end{figure}

  From \ref{fig:myplot} I don't get nothing.
\end{document}

enter image description here

4
  • the caption appears as "From ?? I don't get nothing"
    – MrDi
    Feb 8, 2015 at 16:09
  • @user28952: Did you compile the document twice?
    – Jake
    Feb 8, 2015 at 16:36
  • It works now, but when I add abstract tag and some writing, the figure disappears, but it reappears if I remove the figure tags and just leave the tikzpicture tag without the caption.
    – MrDi
    Feb 8, 2015 at 16:52
  • ypu then should post a minimal example where the problem occurs.
    – MaxNoe
    Feb 8, 2015 at 16:56

You must log in to answer this question.

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