Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I've drawn a rectangle like this:

\draw[color=orange, fill=orange, opacity=0.1] (Q3term1) rectangle (Q3term2);

and essentially, what I want is to do is stretch the rectangle by 10% horizontally and stretch is vertically by 5%, so something like:

\draw[color=orange, fill=orange, opacity=0.1] ($(1.1,1.05)*(Q3term1)$) rectangle ($(0.9,0.95)*(Q3term1)$);

If there is a way to do it without the calc library, that'd be good too.

Thanks.

share|improve this question
1  
Do you want to scale the rectangle about that amount or the coordinates? –  Qrrbrbirlbel Aug 30 '13 at 3:22
    
Wow, yes that's exactly what I want... I can't believe how much I failed at finding this... Thanks. Oh whoops, you change your answer! Well whyat you had was what I wanted. I guess I want to scale the rectangle. –  user968243 Aug 30 '13 at 3:28
    
Yes, I only took a look at your second code line and that can be done without the calc library with xscale and yscale but that does scale the coordinate, not the rectangle. The 0,0 coordinate would also be un-affected by this. There is scale around which you could use to scale around ($(Q3term1)!.5!(Q3term2)$) but this works only for the same scale in both directions. Maybe it can be easier done with a node like in tikz: Can we set the corner coordinates of a rectangle? –  Qrrbrbirlbel Aug 30 '13 at 3:31

1 Answer 1

up vote 2 down vote accepted

If you don’t need to specify the corners of the rectangle relatively, you can use a rectangle node for this.

The \pgfpointlineattime{<factor>}{<p1>}{<p2>} macro is the low-level PGF version of ($(<p1>)!<factor>!(<p2>)$) which is also used in the placement of nodes along a straight line with the pos=<factor> option.

If you want to add a specific padding length, you can use the fit library with inner xsep and inner ysep.

The backgrounds library is only used to add a simply grid to the picture.

Code

\documentclass[tikz]{standalone}
\usetikzlibrary{calc,backgrounds,fit}
\makeatletter
\tikzset{
  from/.code args={#1 to #2}{%
    \pgfextract@process\tikz@fromto@first{\tikz@scan@one@point\pgfutil@firstofone#1\relax}%
    \pgfextract@process\tikz@fromto@second{\tikz@scan@one@point\pgfutil@firstofone#2\relax}%
    % The next line sets "at".
    \pgfextract@process\tikz@node@at
      {\pgfpointlineattime{.5}{\tikz@fromto@first}{\tikz@fromto@second}}%
    \pgfpointdiff{\tikz@fromto@first}{\tikz@fromto@second}%
    \tikzset{
      shape=rectangle,
      anchor=center,
      inner sep=+0pt,
      outer sep=+0pt,
      minimum width/.expanded={abs(\the\pgf@x)},
      minimum height/.expanded={abs(\the\pgf@y)}}%
  }
}
\makeatother
\begin{document}
\begin{tikzpicture}[gridded,nodes={orange, draw, fill, fill opacity=.5}]
\path (1,1) coordinate (a)
      (3,4) coordinate (b)
      (4,1) coordinate (a')
      (6,4) coordinate (b');

\node[from=(a) to (b), xscale=1.1, yscale=1.05] {};
\node[fit=(a')(b'), inner xsep=.1cm, inner ysep=.07cm] {};
\end{tikzpicture}
\end{document}

Output

enter image description here

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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