1

I built 2 plots using the following code


\usepackage{pgfplots}
\usepackage{pgfplotstable}%fitting functions
\usepackage{tikz}
\usetikzlibrary{tikzmark}
\usepackage{pgfplotstable}
\usepackage{siunitx}

\pgfkeys{/pgf/number format/.cd,1000 sep={}}

\newcommand{\myfont}{\fontfamily{cmss}\selectfont}% used with mathpazo 

\pgfdeclareplotmark{fat-}
{%
    \pgfsetlinewidth{1}
    \pgfpathmoveto{\pgfqpoint{\pgfplotmarksize}{0pt}}%
    \pgfpathlineto{\pgfqpoint{-\pgfplotmarksize}{0pt}}%
    \pgfusepathqstroke
}%

\pgfplotsset{/pgfplots/error bars/error bar style={very thick,blue,mark size=2.5},/pgfplots/error bars/error mark={fat-}}
%\pgfplotsset{/pgfplots/label shift={0pt}}

\pgfplotsset{compat=1.15}
\pgfplotsset{label style={font=\Large},
            tick label style={font=\Large}}

\pgfplotsset{error bars/.cd,
    x dir=both, x explicit,
    y dir=both, y explicit,
    }


\begin{document}

\begin{figure}
\centering
\begin{tikzpicture}[trim axis left]
\begin{axis}[
    enable tick line clipping=false, % makes all ticks same width
    axis line style=thick,
    axis on top=true,
    width=9cm,
    height=4cm,
    axis x line=bottom,
    x axis line style=-,
    axis y line=none,
    legend style={at={(0.25,0.8)},draw=none,fill=none},
    legend cell align={left},
    x tick style={black,thick},
    x label style=
        {at={(ticklabel cs:0.5)},anchor=near ticklabel},
    xmin=90,xmax=140,
    xtick={90,100,...,140},
    xtick pos=bottom,
    minor x tick num=1,
    xtick align=outside,
    ymajorticks=false,
%   y label style=
%       {at={(ticklabel cs:0.5)},anchor=near ticklabel},
%   ylabel={\myfont norm. heat flow},
]   
    \fill [gray!20] (90,0.56) rectangle (115,2);

    \fill [green!20] (115,0.56) rectangle (140,2);

    \addplot [blue,very thick] file {thermaltie.txt};

    \node at (axis cs: 100,1.3) {\Large\textit{\myfont endo $\uparrow$}};

\end{axis}
\end{tikzpicture}

\vspace{1em}

\begin{tikzpicture}[trim axis left]
\begin{axis}[
    enable tick line clipping=false, % makes all ticks same width
    axis line style=thick,
    axis on top=true,
    width=9cm,
    height=7cm,
    y tick style={black,thick},
    y label style=
        {at={(ticklabel cs:0.5)},anchor=near ticklabel},
    ymin=400,ymax=900,
    ytick={400,500,...,900},
    ytick pos=left,
    ytick align=outside,
    x tick style={black,thick},
    x label style=
        {at={(ticklabel cs:0.5)},anchor=near ticklabel},
    xmin=90,xmax=140,
    xtick={90,100,...,140},
    xtick pos=bottom,
    minor x tick num=1,
    xtick align=outside,
    xlabel={$T$ [\SI{}{\celsius}]},
    ylabel={$G_a$ [J/m$^2$]}
]
    \fill [gray!20] (90,400) rectangle (115,900);

    \fill [green!20] (115,400) rectangle (140.9,900);

    \addplot [only marks,mark=*,mark options={scale=1.7,blue}]
        table [x=x, y=y, y error=ey] {
        x       y       ey
        95      463     14
        100     584     9
        105     727     14
        110     816     5
        114     836     13
        120     766     7
        125     723     5
        130     753     15
    };

    \addplot [only marks,mark=*,mark options={scale=1.5,blue,very thick,fill=green!20},error bars=red] table [x=x, y=y, y error=ey] {
        x           y       ey
        116         833     41
    };

\end{axis}
\end{tikzpicture}
\end{figure}


\end{document}

The outcome is nice, as you can see below, enter image description here but I want to have the output as a standalone file that I can use in a Keynote slide without cropping the edges. As soon as I change \documentclass[a4paper]{article} into \documentclass{standalone} in the code, the pdf gets messed up. Anyone knows why this might happening? enter image description here

  • 1
    You cannot use a figure environment in a plain standalone class. – user194703 Mar 29 at 3:04
  • You are right. It still compiles the same full page pdf after removing the figure environment. It gets messed up only when I replace article with standalone. – Gagik Mar 29 at 3:47
  • Yes, figure is a float but in a standalone documents like this floats do not make much sense. (Where should they float to?) – user194703 Mar 29 at 3:49
  • How would you plot 2 graphs in one plot? – Gagik Mar 29 at 3:53
  • You can just put two axis objects in one tikzpicture. One cannot compile your code without the data file thermaltie.txt, though. – user194703 Mar 29 at 3:56
2

You cannot use a float like a figure environment in a plain standalone class.

However, in the comments you asked how to have two plots in one figure (or picture). Here is one way to have both axes on top of each other: groupplots.

\documentclass[tikz,border=3mm]{standalone}
\usepackage{pgfplots}
\usepgfplotslibrary{groupplots}
%\usepackage{pgfplotstable}%fitting functions
\usepackage{siunitx}

\pgfkeys{/pgf/number format/.cd,1000 sep={}}

\newcommand{\myfont}{\fontfamily{cmss}\selectfont}% used with mathpazo 

\pgfdeclareplotmark{fat-}
{%
    \pgfsetlinewidth{1}
    \pgfpathmoveto{\pgfqpoint{\pgfplotmarksize}{0pt}}%
    \pgfpathlineto{\pgfqpoint{-\pgfplotmarksize}{0pt}}%
    \pgfusepathqstroke
}%

\pgfplotsset{/pgfplots/error bars/error bar style={very thick,blue,mark size=2.5},/pgfplots/error bars/error mark={fat-}}

\pgfplotsset{compat=1.16}
\pgfplotsset{label style={font=\Large},
            tick label style={font=\Large}}

\pgfplotsset{error bars/.cd,
    x dir=both, x explicit,
    y dir=both, y explicit,
    }


\begin{document}

\begin{tikzpicture}%[trim axis left]
\begin{groupplot}[group style={group size=1 by 2,
    vertical sep=4em},
    enable tick line clipping=false, % makes all ticks same width
    axis line style=thick,
    axis on top=true,
    axis x line=bottom,
    x axis line style=-,
    legend style={at={(0.25,0.8)},draw=none,fill=none},
    legend cell align={left},
    x tick style={black,thick},
    x label style=
        {at={(ticklabel cs:0.5)},anchor=near ticklabel},
    xmin=90,xmax=140,
    xtick={90,100,...,140},
    xtick pos=bottom,
    minor x tick num=1,
    xtick align=outside,
    ]   
\nextgroupplot[ width=9cm,
height=4cm,axis y line=none,
]

    \fill [gray!20] (90,0.56) rectangle (115,2);

    \fill [green!20] (115,0.56) rectangle (140,2);

    \addplot [domain=90:140,blue,very thick] {0.56+x*x*exp(-x/10)};

%    \addplot [blue,very thick] file {thermaltie.txt};

    \node at (axis cs: 100,1.3) {\Large\textit{\myfont endo $\uparrow$}};

\nextgroupplot[width=9cm,
    height=7cm,
    y tick style={black,thick},
    y label style=
        {at={(ticklabel cs:0.5)},anchor=near ticklabel},
    ymin=400,ymax=900,
    ytick={400,500,...,900},
    xlabel={$T$ [\SI{}{\celsius}]},
    ylabel={$G_a$ [J/m$^2$]}
    ]
    \fill [gray!20] (90,400) rectangle (115,900);

    \fill [green!20] (115,400) rectangle (140.9,900);

    \addplot [only marks,mark=*,mark options={scale=1.7,blue}]
        table [x=x, y=y, y error=ey] {
        x       y       ey
        95      463     14
        100     584     9
        105     727     14
        110     816     5
        114     836     13
        120     766     7
        125     723     5
        130     753     15
    };

    \addplot [only marks,mark=*,mark options={scale=1.5,blue,very thick,fill=green!20},error bars=red] table [x=x, y=y, y error=ey] {
        x           y       ey
        116         833     41
    };

\end{groupplot}
\end{tikzpicture}
\end{document}

enter image description here

| improve this answer | |
  • Thanks a lot. That works! – Gagik Mar 29 at 4:17

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.