[Tex/LaTex] Remove “white parts” of tikz picture

bounding boxtikz-pgf

I have a tikz picture, which consists of a visible part on the left side and a white part on the right side (for some constructive reasons). Now I would like to redefine the size so that the new picture just consists of the left part (without scaling).

How do you do that?

Best Answer

You have to explicitly set the bounding box of the picture. TikZ provides the use as bounding box option to do that. For example

\documentclass{report}
\usepackage{tikz}

\begin{document}
a
\begin{tikzpicture}
    \path[use as bounding box, draw] (0,0) rectangle (2,2); % The draw option is given just for demonstration.
    \draw (0,0) circle [radius=1cm];
\end{tikzpicture}
b
\end{document}

If you want to shrink an already established bounding box, you have to reset it with \pgfresetboundingbox first:

\documentclass{report}
\usepackage{tikz}

\begin{document}
a
\begin{tikzpicture}
    \draw (0,0) circle [radius=1cm];
    \pgfresetboundingbox
    \path[use as bounding box, draw] (0,0) rectangle (2,2);
\end{tikzpicture}
b
\end{document}

Other useful options for modifying the bounding box are the trim left and trim right options to tikzpicture. Section 15.7 “Establishing a Bounding Box” of the TikZ manual (v2.10) has all the details.