0

I have the following LaTeX file:

\documentclass[a4paper, 12pt]{report}
\usepackage{fancyhdr, caption, pgfplots, pdfpages, graphicx}
\pagestyle{fancy}
\fancyhead{}
\renewcommand{\headrulewidth}{0pt}
\setboolean{@twoside}{false}
\setlength\parindent{0pt}
\begin{document}
\includepdf[pages=-]{example-image.pdf}
\input{File 1}
\includepdf[pages=-]{example-image.pdf}
\input{File 1}
\includepdf[pages=-]{example-image.pdf}
\end{document}

File 1 is:

Some text

\begin{figure} \begin{center} \begin{tikzpicture} \pgfplotsset{every x tick label/.append style={font=\tiny}, compat=1.3} \begin{axis}[ title={Title}, xlabel={X Label}, ylabel={Y Label}, xmin=-100, xmax=100, ymin=0, ymax=145, ytick={0,10,...,140}, xtick={-100,-75,...,100}, ymajorgrids=true, xmajorgrids=true, grid style=dashed, legend pos=outer north east, ] \addplot[ color=blue, mark=*, ] coordinates { (-100,1)(-75,1)(-50,1)(-25,1)(0,30)(25,60)(50,105)(75,10)(100,13) }; \end{axis} \end{tikzpicture} \caption*{Caption} \end{center} \end{figure}

(In case it makes a difference, my actual file has more documents added to it than this, and the plots in File 1 and File 2 are different from each other and have many more addplots; I made this just as a MWE. It still reproduced the same problem when compiled.)

When I compile the document, all the \includepdfs are in the correct order, but the plots in both of the LaTeX files in the \input both go to the bottom of the document, even though I didn't place any of them there. The text in the \includepdfs stay in the correct place, but are separated from the plots. I need them to be in the positions I placed them in the file. They don't need to be on new pages (they're plots made with pgfplots), and (from my research) that's why I used \input instead of \include.

I also tried putting a line between each line of code but that didn't change anything.

What could be causing this problem?

David Carlisle
  • 757,742
  • \input just includes the input file at that point, it never moves. What is in the files you input? does it contain floats such as figures or tables? – David Carlisle Nov 08 '21 at 21:19
  • a MWE needs to be something that shows the problem, we can not run this as we do not have any of the files. – David Carlisle Nov 08 '21 at 21:21
  • @DavidCarlisle The files contain plots using tikzpicture and \pgfplotsset. – Just_A_User Nov 08 '21 at 21:22
  • @DavidCarlisle How should I make in an MWE. Attach some files? I thought perhaps there was a problem with the way I wrote the code that could be pointed out; I guess that's not the case. – Just_A_User Nov 08 '21 at 21:23
  • they will not move either. Please provide an example that we can debug, otherwise not really possible to help – David Carlisle Nov 08 '21 at 21:23
  • make an example (you can use example-image.pdf for the pdfs as it is available for tests, and provide the input files that do not appear where you expect in a separate code block in teh question) – David Carlisle Nov 08 '21 at 21:24
  • @DavidCarlisle I have added a full MWE; I hope it's clear now. – Just_A_User Nov 08 '21 at 21:40
  • 1
    well there you go, as I guessed in the first comment. you have a figure environment. This is unrelated to \input you would get the same if you copied the code directly to the main document. The only function of figure is to specify that its content may be moved. – David Carlisle Nov 08 '21 at 21:43
  • https://tex.stackexchange.com/questions/2275/keeping-tables-figures-close-to-where-they-are-mentioned – David Carlisle Nov 08 '21 at 21:45
  • @DavidCarlisle Great coincidence, I got the suggestion to add the figure from your answer to get the caption to work. So if I remove it I won't be able to have the caption. – Just_A_User Nov 08 '21 at 21:46
  • documents have captions so that you can reference the moved insert but the link I give shows how you can get captions with non floats if you want that. – David Carlisle Nov 08 '21 at 21:47
  • that said you can use \clearpage after each \input and the figure will not float past the clearpage. – David Carlisle Nov 08 '21 at 21:56
  • @DavidCarlisle Using \begin{figure}[!htbp] as suggested by the linked answer worked, thanks so much for the help. Feel free to write it as an answer if you wish. – Just_A_User Nov 08 '21 at 21:57
  • glad you got it working, I'll close as dup. – David Carlisle Nov 08 '21 at 21:57

0 Answers0