1

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:

enter image description here

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}
DRi
  • 847
SRel
  • 1,313

1 Answers1

3

New lines are treated like spaces (reduced MWE with just one example):

\documentclass{scrbook}
\usepackage{tikz}

\begin{document}

\resizebox{\textwidth}{!}{%
\begin{tikzpicture}
\draw[red] (0,0) rectangle (10,.5);
\end{tikzpicture} % <-- HERE THERE IS A SPACE
}

\resizebox{\textwidth}{!}{% <-- This is good!
\input{rectangle.tex} % <-- HERE THERE IS A SPACE
}
\end{document}

As a matter of fact, you correctly used % after opening the brace for the third argument of \resizebox.

campa
  • 31,130