Graphics, Figures & TablesError when putting a tikzpicture in a figure

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
jldicarlo
Posts: 1
Joined: Tue Sep 17, 2019 7:39 pm

Error when putting a tikzpicture in a figure

Post by jldicarlo »

Hello. Long time user, first time poster. This error one has me stymied. I did a lot of searching and only came up with one post that was even close but the solution did not help me.

I wrote a loop to pull in a bunch of output files to create tikzpictures. Basically they are "time stamps" of output so I can see what is going on in my optimization model. If I don't try to put them in figures or subfigures, they generate just fine. The minute I try to use figures (individually) or subfigures (so, all time stamps for one facility are subfigures of one big figure) it doesn't work. It gets through the four subfigures then doesn't like the end figure.

My preamble has a LOT of packages in it and I realize that this COULD be some kind of incompatibility thing. But oddly enough, if I only input ONE .tex file in my main document, that works fine. So SOMETHING I am doing in this short file is causing the issue.

I think these are the main packages I use plus those "associated with" figures:

% Packages
\usepackage{graphicx,amsmath,epsf, amssymb, wasysym}
\usepackage{setspace}
\usepackage{color}
\usepackage{lineno}
\usepackage[usenames,dvipsnames]{xcolor}
\usepackage{fancyvrb}
\usepackage{url}
\usepackage[font=small,labelfont=bf]{caption}
\usepackage{floatrow}
\usepackage{lipsum} %nonsense text for testing
\usepackage{adjustbox}
\usepackage[acronym,toc,nonumberlist]{glossaries}
\usepackage [english]{babel}
\usepackage[T1]{fontenc}
\usepackage[latin1]{inputenc}
\usepackage [autostyle, english = american]{csquotes}
\usepackage{enumitem}
\usepackage{relsize}
\usepackage{verbatim} % Allows for comment environment
\usepackage{standalone}
\usepackage[font=footnotesize]{subcaption}


Here is the file I am trying to compile. My REAL code calls other files via \input{}, but again, that doesn't seem to be the issue so to avoid having to explain the multiple custom nodes, I subbed four lines of the code from the input file instead.

\documentclass[crop=false]{standalone}
\usepackage{import}
\usepackage{preamble}

\newcommand{\MaxTP}{4}

\begin{document}

% No "figures" WORKS
\foreach \b in {{FA},{FB},{FC}}
{
\foreach \c in {1,2,...,\MaxTP}
{
\begin{tikzpicture} [font=\sffamily]
\node (t) [left=of f1] {From Tap/Tie-in};
\node (w) [below=of f3, yshift=-0.5cm]{To Injection Well(s)};
\node (s) [right=of f3] {To Pipeline};
\node (d) [above=of f1] {From Pipeline};
\end{tikzpicture}
}
}

% Add "figures"....does not work
\foreach \b in {{FA},{FB},{FC}}
{
\begin{figure}
\centering
\foreach \c in {1,2,...,\MaxTP}
{
\subcaptionbox {Time Period: \c}
{\begin{tikzpicture} [font=\sffamily]
\node (t) [left=of f1] {From Tap/Tie-in};
\node (w) [below=of f3, yshift=-0.5cm]{To Injection Well(s)};
\node (s) [right=of f3] {To Pipeline};
\node (d) [above=of f1] {From Pipeline};
\end{tikzpicture}
}
}
\caption{Facility: \b}
\end{figure}
}

\end{document}

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

Stefan Kottwitz
Site Admin
Posts: 10335
Joined: Mon Mar 10, 2008 9:44 pm

Error when putting a tikzpicture in a figure

Post by Stefan Kottwitz »

Welcome to the forum!

Which error message do you get? That information was missing above.

I get a lot of errors just because that code is incomplete. No TikZ loaded, no positioning library loaded, etc.

Stefan
LaTeX.org admin
Post Reply