This is most likely just caused by added spaces. You need to add a %
if a line ends with {
and sometimes also with }
to avoid that the line break is taken as a space. Note that \tikzstyle
is deprecated and also requires a %
after the ]
if it is used outside a tikzpicture
.
The following doesn't produce any shifting:
\begin{figure}
\resizebox{\linewidth}{!}{%
\begin{tikzpicture}[scheme/.style={draw = black, fill = black!10, thin, rectangle, minimum width = 15pt, minimum height = 10pt}]
\node (n1) [scheme] {};
\node (n2) [scheme, at = (n1.east), right = 12pt] {};
\node (n3) [scheme, at = (n2.east), right = 12pt] {};
\node (n4) [scheme, at = (n3.east), right = 12pt] {};
\end{tikzpicture}%
}%
\caption{Test}
\end{figure}
There might be some leading and trailing spaces in the input file as well. Try to add \ignorespaces
before and \unskip
afterwards.
A further cause might be a paragraph indent which can be removed by placing \noindent
before the content.
You can also use \begin{adjustbox}{width=\linewidth} .. \end{adjustbox}
from the adjustbox
package for the scaling. It is more efficient than \resizebox
and also allows special content like verbatim. It adds the \noindent
by itself to play it save.
Yes, the whole PDF page is always included. Options trim
and viewport
only select
the box that is seen by TeX and option clip
only makes the part outside the box
invisible. But option clip
does not read the PDF image page contents, analyzes its page stream operators and rewrites the page stream for the only inclusion of the visible elements.
This is not a trivial task at all. I do not know a freeware tool that is able to do this
automatically except for rendering to a bitmap.
Without converting to a bitmap (and loss of quality) it is not easy to remove the
invisible parts.
With good knowledges of PDF (or PostScript) the removal can also be manually
done by editing the PDF or PostScript files directly. But it depends on the familiarity with the formats, the complexity of the PDF file and the elements that should be removed.
The box could cut through characters. It is possible to select the dot of an i
.
But if you want to remove the stem, you would have to go to the glyph description of the character in the embedded font.
Best Answer
The definition of the macros in the package fail to comment line endings in all of the necessary places. Since TeX interprets these as spaces, spaces are inserted.
The definition of
\tikzmarkin
involves numerous, nested conditional clauses. Here, I just tried to pick the one relevant to you and redefine that.The fix involves adding this to the preamble after loading hf-tikz:
Note that my fix consists of the addition of two
%
signs at the end of lines. Obviously, this should be fixed for all cases and not just the Beamer-rounded-corners-fill-etc.-etc. one, but that is really best done in the package by its maintainer.The results look like this:
Complete code for example: