In the code below, I included this .tex file into my document (with the relevant lines commented out, like \begin and \end{document}), but, for some reason, the plot appears on a page by itself. I wanted to have this plot float within my document, but I cannot for some reason. I used the \include command within my document and could not get it to work. I then put the code into this standalone document and it appears that an extra page is being created.
Can you assist me in getting the file to show up without all this extra space so that I can maneuver the figure about my document instead of it showing up in a page by itself? Thanks!
CODE
\documentclass[crop, tikz]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\usepackage{filecontents}
\RequirePackage{fontspec}
\begin{filecontents*}{data2.dat}
0 0.10206670000
1 0.09905792000
2 0.06677074000
3 0.02062632000
4 0.00180701100
5 0.00002654813
6 0.00003744502
7 0.00004003021
8 0.00002708582
9 0.00002307745
10 0.00003643514
11 0.00004641169
12 0.00004744656
13 0.00003082966
14 0.00003775425
15 0.00008938722
16 0.00013548500
17 0.00015285560
18 0.00014095270
19 0.00011902230
20 0.00011660580
21 0.00007680599
22 0.00004823680
23 0.00007528155
24 0.00012932520
25 0.00014396080
26 0.00009415951
27 0.00006138856
28 0.00007132459
29 0.00007670367
30 0.00008301680
31 0.00010145180
32 0.00015893710
33 0.00023337950
34 0.00027370890
35 0.00026749480
36 0.00023144810
37 0.00019094270
38 0.00017619290
39 0.00021714180
40 0.00021507670
41 0.00017499700
42 0.00010223320
43 0.00005734080
44 0.00013067910
45 0.00012689820
46 0.00013588770
47 0.00012935150
48 0.00011225500
49 0.00013967980
50 0.00020306920
51 0.00015598630
52 0.00002845892
53 0.00022813320
54 0.00034332840
55 0.00035366590
56 0.00029860290
57 0.00014724470
58 0.00027776550
59 0.00057385510
60 0.00068391180
61 0.00078191920
62 0.00071762080
63 0.00050012280
64 0.00037338890
65 0.00026202910
66 0.00018668800
67 0.00026404690
68 0.00039164640
69 0.00043375420
70 0.00037268550
71 0.00027936230
72 0.00035795920
73 0.00043023800
74 0.00035592530
75 0.00014477900
76 0.00014335430
77 0.00034946590
78 0.00039751280
79 0.00037979610
80 0.00036745820
81 0.00030650400
82 0.00033379680
83 0.00016950630
84 0.00015314110
85 0.00021218250
86 0.00026757990
87 0.00029684980
88 0.00021983490
89 0.00021712020
90 0.00030226340
\end{filecontents*}
%
\begin{document}
\begin{figure}%
\begin{tikzpicture}
\begin{axis}[%
scaled y ticks=false,
xtick={0,50,...,90},xmin=10,xmax=90,
yticklabel style={/pgf/number format/fixed,
/pgf/number format/precision=4},
ymax = 0.010,ymin=0,
restrict y to domain = 0:0.01,
no marks,
xlabel = {Frequency (Hz)},
ylabel = {Amplitude (V)},
extra x ticks = {60, 120, 180, 240, 300, 360},
extra x tick labels = {60},
extra x tick style = {
font = \tiny,
tick label style = {fill = blue!30, rotate = 45, anchor = west, text width = 1em},
grid = major,
grid style={dotted, blue},
},
]
\addplot[fill=cyan, opacity=.3] table {data2.dat} --(400,0)-- (0,0);
\end{axis}
\end{tikzpicture}
\end{figure}
\end{document}
includecommand and use offigureenvironment is wrong (at least you need to advarwidthoption tostandalone option, otherwise are inserted blank page before image). If you like to insert image code tofigureenvironment in your document, try to useinput. It in difference to\includenot insert new page. – Zarko Feb 26 '20 at 21:03\includebut you do not show how you use it (\includeis normally used to include something like a whole chapter, it issn't usually suitable for figures although not necessarily wrong. – David Carlisle Feb 26 '20 at 21:40\includealways forces a new page before and after the inclusion, is that the issue? is this a duplicate of the site's highest voted question https://tex.stackexchange.com/questions/246/when-should-i-use-input-vs-include – David Carlisle Feb 26 '20 at 21:45standalone is not intended to supportfigureenvironment nor displayed equations. This limitation you can avoid with optionvarwidth`. However, what is your problem? See @DavidCarlisle comments. – Zarko Feb 26 '20 at 21:47standaloneor\input(and definitely not\include) but if you do want it in a separate file it should just have thetikzpictureenvironment, no\documentclassor\begin{document}or\usepackage. – David Carlisle Feb 26 '20 at 22:23