# Is there an TikZ command to provide the height and width of the picture? [duplicate]

I've found the following How can I compute the distance between two coordinates in TikZ?. So, I know how to find the size of a TikZ picture as follows:

\documentclass{article}
\usepackage[margin=0.5in]{geometry}
\usepackage{fp}
\usepackage{tikz}
\usetikzlibrary{calc}

\makeatletter
\def\calcLength(#1,#2)#3{%%
\pgfpointdiff{\pgfpointanchor{#1}{center}}%%
{\pgfpointanchor{#2}{center}}%%
\pgf@xa=\pgf@x%%
\pgf@ya=\pgf@y%%
\FPeval\@temp@a{\pgfmath@tonumber{\pgf@xa}}%%
\FPeval\@temp@b{\pgfmath@tonumber{\pgf@ya}}%%
\FPeval\@temp@sum{(\@temp@a*\@temp@a+\@temp@b*\@temp@b)}%%
\FProot{\FPMathLen}{\@temp@sum}{2}%%
\FPround\FPMathLen\FPMathLen5\relax
\global\expandafter\edef\csname #3\endcsname{\FPMathLen pt}%%
}
\makeatother

\setlength{\parindent}{0pt}

\begin{document}

\begin{tikzpicture}[baseline=(B)]%%
\coordinate (A) at (0,0);
\coordinate (B) at (10,3);
\draw (A) -- (B);

\coordinate (PUL) at ($(current bounding box.north west)+(-1ex,1ex)$);
\coordinate (PLR) at ($(current bounding box.south east)+(1ex,-1ex)$);
\coordinate (PUR) at (PUL-|PLR);
\coordinate (PLL) at (PUL|-PLR);
\draw (PUL) rectangle (PLR);

\calcLength(PUL,PUR){mywidth}%%
\calcLength(PUL,PLL){myheight}%%

\end{tikzpicture}%%

Here's a rule the width of the picture:

\rule{\mywidth}{4pt}

Here's a rule the height of the picture:

\rule{4pt}{\myheight}

\end{document}


What I'm curious about is whether isn't an easier way to go about this since all I'm interested in is the dimensions of the finished picture.

• Box it and use \ht, \wd fot he box? Mar 23, 2014 at 18:16
• @GonzaloMedina Well there's that too. But is there anything in TikZ that accomplishes the same? Mar 23, 2014 at 18:17
• @Jubobs How embarassing! I even commented on that post. Perhaps this should be closed as a duplicate question. Mar 23, 2014 at 18:21
• @A.Ellett I know :p I even hesitated linking to that question because you had commented on it, but heh, you're not expected to remember every single question or comment on the site. I'll vote to close this one as a duplicate. Mar 23, 2014 at 18:23
• @Jubobs Well I'm glad you did comment because I like the method used in that example better than the method I'm using in this question. Mar 23, 2014 at 18:24