3

I am drawing a TikZ picture as a standalone file and then I use \includestandlaone in my main document. When I insert the file the picture is not centered even though I use \centering. How can I fix this?

MWE:

Main file

\documentclass{article}
\usepackage{standalone}
\usepackage[T1]{fontenc} 
\usepackage[english]{babel}
\usepackage{textcomp}
\usepackage{amsmath,amsfonts,amssymb,mathtools,bm,amsthm,commath,esvect}
\usepackage{graphicx}
\usepackage[export]{adjustbox}
\usepackage{caption}
\usepackage{subcaption}
\usepackage{lipsum}
\usepackage{standalone}
\usepackage{tikz}
\usepackage{forest}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\usetikzlibrary{arrows,decorations.markings}

\begin{document}

\begin{figure}
\centering
\includestandalone[max width=0.5\textwidth]{./fig/partA_inventory_diagram}
\end{figure}

\end{document}

Standalone file

\documentclass[tikz,border=5pt]{standalone}    
\begin{document}
\usetikzlibrary{arrows,decorations.markings}
\begin{tikzpicture}[>=stealth]


% define origin of coordinate system
\coordinate (origin) at (0,0);

\draw[<->] (0,-3) -- (0,7) node[above] {Inventory $Q$};
\draw[->] (origin) -- (10,0) node[right] {Time $t$};

\end{tikzpicture}
\end{document}
3
  • can you move \usetikzlibrary part before \begin{document} and try? and also remove the empty line before figure environment and add \noindent
    – percusse
    Oct 10, 2017 at 11:59
  • 1
    Does that even work for you? I get ! LaTeX Error: Option clash for package adjustbox., which can be fixed by making \usepackage[export]{adjustbox} the first package to be loaded. (And doing that it works fine.) Oct 10, 2017 at 12:02
  • @TorbjørnT. it works when I made it the first package to be loaded. Thank you.
    – lala_12
    Oct 10, 2017 at 14:00

1 Answer 1

2

Do not ignore errors!

Your code produces an error saying

! LaTeX Error: Option clash for package adjustbox.

which is caused by the fact that the standalone package loads the adjustbox package without options, and when you try to load again, with more options, you get an error.

Whenever a package is loaded more than once, the options passed to it the second time has to be a subset of the options passed to it the first time. Hence, load adjustbox before standalone, i.e. do

\usepackage[export]{adjustbox}
\usepackage{standalone}

instead of

\usepackage{standalone}
\usepackage[export]{adjustbox}

and you're fine.

2

You must log in to answer this question.

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