3

I would like to use \scalebox to scale a TikZ picture (included with \input) that is located inside a center environment (I don't need a float environment in this specific case). But \scalebox introduces a slight shift to the left such that the content is not exactly centered anymore.

\documentclass[DIV=10]{scrartcl}

\usepackage[ngerman]{babel}
\usepackage[no-math]{fontspec}
\usepackage{microtype}
\usepackage{tikz}
\usepackage{filecontents}

\begin{document}

\begin{filecontents*}{temp.tikz}
  \begin{tikzpicture}
    \fill (0,0) rectangle (1,1);
  \end{tikzpicture}
\end{filecontents*}

\thispagestyle{empty}

\begin{center}
\scalebox{1.0}{%
  \input{temp.tikz}%
}
\end{center}

\end{document}

For demonstration purposes, I used 1.0 as a scale factor. You would expect the output to be the same as without using the \scalebox environment, but that is not the case.

What is the cause of this problem and how may I solve it?

  • 1
    Try T% -- it looks the same for me then – user31729 Feb 16 '16 at 19:21
  • @ChristianHupfer Thanks, looks better, although there's still some very small shift, but that might be due to rounding errors when the scale factor is 1.0. However, when using \include to include some tikzpicture environment, adding % does not work for me. – ph4nt0m Feb 16 '16 at 19:33
  • Well, you did not mention that you would use \include the tikzpicture – user31729 Feb 16 '16 at 19:34
  • @ChristianHupfer Sorry, I tried some different combinations and did not suspect that this would make any difference. In order to keep the MWE as simple as possible, I omitted those details. – ph4nt0m Feb 16 '16 at 19:36
  • Well, I just tried to use \include within \scalebox -- there were errors. \input does work and appending % after \input{foo}` does work too – user31729 Feb 16 '16 at 19:45
3

A tikz picture is just like a letter.

If you go

\begin{center}
a
\end{center}

then the a is centered, but if you go

\begin{center}
\fbox{
a}
\end{center}

the box is centred but the a is off-center as there is a word space on the left.

\begin{center}
\fbox{%
a}
\end{center}

is like

\begin{center}
\fbox{a}
\end{center}

and again the a is centred.

The same positioning of a happens if you use \mbox or \scalebox but it is easier to see what is happening with \fbox.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.