[Tex/LaTex] Specifying the width and height of a tikzpicture

tikz-pgf

Is it possible to specify the width and height of a tikzpicture? To scale a tikzpicture I use the option scale, i.e. for instance

\begin{tikzpicture}[scale = 2]
...
\end{tikzpicture}

I tried to change the width and height as

\begin{tikzpicture}[width = 2in, height = 3in]
...
\end{tikzpicture}

but this gives me an error "I do not know the key /tikz/width".

Best Answer

EDIT:

I came back here to add information about the tikzscale package, however I found an answer about that already in this thread. I believe you will want to give it a try.


Use resizebox outside of tikzpicture.

\resizebox{width}{height}{object}

For example:

\documentclass{article}
\usepackage{tikz}

\begin{document}
    \begin{figure}
        \centering
        \resizebox{\columnwidth}{!}{%
            \begin{tikzpicture}
                \node [draw] (my node 1) {my node 1};
                \node [draw, anchor = west] (my node 2) at (my node 1.east) {centro};
                \node [draw, anchor = west] at (my node 2.east) {my node 3};
            \end{tikzpicture}%
        }
    \end{figure}
\end{document}