I am having a project in which I use Tikz for making my graphics. I "externalize" the coding by using a tikz-editor. I then simply save the achieved tikz-code in a separate .tex
file in which only stands
\begin{tikz} <> \end{tikz}
I wrap this code inside a figure
environment combined with \resizebox
and by using \insert
. I want that the picture directly starts at the left shown border and go completely to the right. However, (maybe because of nested \input
?) every time I call \input
, the image is having a wider margin to the right.
\documentclass{scrbook}
\usepackage{tikz}
\usepackage[showframe,includeheadfoot, left=3cm,right=2cm,top=2cm,bottom=2cm]{geometry}
\begin{document}
\noindent native tikz-code:\\
\begin{figure}[h!]
\centering
\resizebox{\textwidth}{!}{%
\begin{tikzpicture}
\draw[red] (0,0) rectangle (10,.5);
\end{tikzpicture}
}
\end{figure}
\noindent input 1x:\\
\begin{figure}[h!]
\centering
\resizebox{\textwidth}{!}{%
\input{rectangle.tex}
}
\end{figure}
\noindent input 2x:\\
\begin{figure}[h!]
\centering
\resizebox{\textwidth}{!}{%
\input{rectangle_nested.tex}
}
\end{figure}
\noindent input 3x:\\
\begin{figure}[h!]
\centering
\resizebox{\textwidth}{!}{%
\input{rectangle_nested_2.tex}
}
\end{figure}
\end{document}
Compiling this, results in this image:
Including a .pdf
via \includegraphics
works, however I don't use the precompiled version, as I have to rerun the code from my main-file for creating citations I use in the graphic etc. So I just want to include the tikz-commands from an external file but not creating any margins. Many thanks.
EDIT: rectangle.tex
just contains the tikz-code:
\begin{tikzpicture}
\draw[red] (0,0) rectangle (10,.5);
\end{tikzpicture}
and rectangle_nested.tex
just:
\input{rectangle.tex}
\input
.\resizebox
is taking those spaces into account.%
after every\input
:\input{whatever}%
. New lines are treated like spaces.\noindent native tikz-code:\` never use
\\ ` before afigure
also you should almost never need\noindent
in a latex document.