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 was doing a figure based on drawing some rectangles which the area represents the relative amount of such element and I encounter two unexpected situations:

(1) I decided to go with rectangles to draw the figure (shown here below). Once I've finished the drawing I was willing to apply the style in order to obtain round edges and put them in white. Then I got the surprise that it can not be applied a style to the rectangles.

(2) The way I was building up the legend doesn't work since when the node is created using positioning the drawing cursor doesn't move from the origin.

\documentclass[11pt]{article} 
\usepackage{color}
\usepackage{pgfplotstable,booktabs,array,colortbl,siunitx}
\usetikzlibrary{calc}
\usepackage{tikz}
\usetikzlibrary{positioning}

\begin{document}

\thispagestyle{empty} %Please, no page numbers or similar

\begin{tikzpicture}[scale=.3,yscale=-1]

% Defining stuff
\def\sep{0}
\definecolor{auxColori}{RGB}{124,121,247}
\definecolor{FAcolor}{RGB}{222,209,111}
\definecolor{Hcolor}{RGB}{146,209,105}
\definecolor{Gcolor}{RGB}{113,130,227}
\definecolor{CDIcolor}{RGB}{242,162,121}
\definecolor{CLIcolor}{RGB}{93,186,172}
\definecolor{CIDcolor}{RGB}{204,102,201}
\definecolor{Othercolor}{RGB}{191,96,124}
\definecolor{auxColor}{RGB}{120,190,240}
\definecolor{Qcolor}{RGB}{255,128,128}

% Drawing the rectangles
\draw [fill=Othercolor] (0,0) ++(-2.5,0) rectangle +(4.5,4);%18 other

\pgfmathsetmacro{\CIDheight}{7/2}
\pgfmathsetmacro{\CLIheight}{12/2}
\pgfmathsetmacro{\CDIheigth}{2*\sep+4+\CIDheight+\CLIheight}
\pgfmathsetmacro{\CDIwidth}{67/\CDIheigth}
\draw [fill=CIDcolor] (0,{\sep+4}) rectangle +(2,\CIDheight);% 7 CID
\draw [fill=CLIcolor] (0,{2*\sep+4+\CIDheight}) rectangle +(2,\CLIheight);%12 CLI
\draw [fill=CDIcolor] ({2+\sep},0) rectangle +(\CDIwidth,\CDIheigth);%67  CDI

\pgfmathsetmacro{\Gheight}{8/2.5}
\pgfmathsetmacro{\Hheight}{6/2.5}
\pgfmathsetmacro{\FAheight}{2*\sep+4+\Gheight+\Hheight}
\pgfmathsetmacro{\FAwidth}{69/\FAheight}
\pgfmathsetmacro{\Qwidth}{\sep+2.5+\FAwidth}
\pgfmathsetmacro{\Qheight}{90/\Qwidth}
\draw [fill=Gcolor] (0,{\sep+4}) rectangle +(-2.5 ,\Gheight);% 8 G              
\draw [fill=Hcolor]  (0,{2*\sep+4+\Gheight}) rectangle +(-2.5,\Hheight);%6 H
\draw [fill=FAcolor] ({-2.5+\sep},0) rectangle +(-\FAwidth,\FAheight);%69 FA
\draw [fill=Qcolor] (0,{\FAheight+\sep}) rectangle +(-\Qwidth,\Qheight);%90 Q


% Creating the legend
\tikzset{nameSt/.style={anchor=west}}
\draw[draw=Qcolor, fill=Qcolor] (10,0) node[nameSt] (Qname) {Q} ++(-.5,-.5) rectangle +(.5,.5);
\draw[draw=FAcolor, fill=FAcolor] node[nameSt, below=of Qname] (FAname) {FA} ++(-.5,-.5) rectangle +(.5,.5);
\draw[draw=Gcolor, fill=Gcolor] node[nameSt, below=of FAname] (Gname) {G} ++(-.5,-.5) rectangle +(.5,.5);


\end{tikzpicture}

\end{document}

figure

Any hints?

share|improve this question
    
Can you reproduce your unexpected behavior in a minimal working example (MWE)? –  Qrrbrbirlbel Sep 7 '13 at 0:00
add comment

1 Answer

up vote 3 down vote accepted

Here is a solution for rectangles with rounded corners using style

\tikzset{
wrcorners/.style = {rounded corners=6pt,line width=1.8pt,draw=white}
}

and nodes for the legend

\tikzset{nameSt/.style=
{anchor=west,rectangle,
 minimum width=10pt,minimum height=10pt,
}}
\draw[] (8,1) node[nameSt,draw=Qcolor, fill=Qcolor,label=right:Q] (Qname) {};
\draw[] node[nameSt, draw=FAcolor, fill=FAcolor,below=of Qname,label=right:FA] (FAname) {} ;
\draw[] node[nameSt,draw=Gcolor, fill=Gcolor, below=of FAname,label=right:G] (Gname) {}; 

The result is

Rounded corners + legend

Here's the full code

\documentclass[11pt]{article} 
\usepackage{color}
\usepackage{pgfplotstable,booktabs,array,colortbl,siunitx}
\usetikzlibrary{calc}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows}
\usetikzlibrary{positioning}
\tikzset{
    wrcorners/.style = {rounded corners=6pt,line width=1.8pt,draw=white}
}


\begin{document}

\thispagestyle{empty} %Please, no page numbers or similar

\begin{tikzpicture}[scale=.3,yscale=-1]

% Defining stuff
\def\sep{0}
\definecolor{auxColori}{RGB}{124,121,247}
\definecolor{FAcolor}{RGB}{222,209,111}
\definecolor{Hcolor}{RGB}{146,209,105}
\definecolor{Gcolor}{RGB}{113,130,227}
\definecolor{CDIcolor}{RGB}{242,162,121}
\definecolor{CLIcolor}{RGB}{93,186,172}
\definecolor{CIDcolor}{RGB}{204,102,201}
\definecolor{Othercolor}{RGB}{191,96,124}
\definecolor{auxColor}{RGB}{120,190,240}
\definecolor{Qcolor}{RGB}{255,128,128}

% Drawing the rectangles
\draw [fill=Othercolor,wrcorners] (0,0) ++(-2.5,0) rectangle +(4.5,4);%18 other
\pgfmathsetmacro{\CIDheight}{7/2}
\pgfmathsetmacro{\CLIheight}{12/2}
\pgfmathsetmacro{\CDIheigth}{2*\sep+4+\CIDheight+\CLIheight}
\pgfmathsetmacro{\CDIwidth}{67/\CDIheigth}
\draw [fill=CIDcolor,wrcorners] (0,{\sep+4}) rectangle +(2,\CIDheight);% 7 CID
\draw [fill=CLIcolor,wrcorners] (0,{2*\sep+4+\CIDheight}) rectangle +(2,\CLIheight);%12 CLI
\draw [fill=CDIcolor,wrcorners] ({2+\sep},0) rectangle +(\CDIwidth,\CDIheigth);%67  CDI

\pgfmathsetmacro{\Gheight}{8/2.5}
\pgfmathsetmacro{\Hheight}{6/2.5}
\pgfmathsetmacro{\FAheight}{2*\sep+4+\Gheight+\Hheight}
\pgfmathsetmacro{\FAwidth}{69/\FAheight}
\pgfmathsetmacro{\Qwidth}{\sep+2.5+\FAwidth}
\pgfmathsetmacro{\Qheight}{90/\Qwidth}
\draw [fill=Gcolor,wrcorners] (0,{\sep+4}) rectangle +(-2.5 ,\Gheight);% 8 G              

\draw [fill=Hcolor,wrcorners]  (0,{2*\sep+4+\Gheight}) rectangle +(-2.5,\Hheight);%6 H
\draw [fill=FAcolor,wrcorners] ({-2.5+\sep},0) rectangle +(-\FAwidth,\FAheight);%69 FA
\draw [fill=Qcolor,wrcorners] (0,{\FAheight+\sep}) rectangle +(-\Qwidth,\Qheight);%90 Q

% Creating the legend
%\tikzset{nameSt/.style={anchor=west}}
%\draw[draw=Qcolor, fill=Qcolor] (10,0) node[nameSt] (Qname) {Q} ++(-.5,-.5) rectangle +(.5,.5);
%\draw[draw=FAcolor, fill=FAcolor] node[nameSt, below=of Qname] (FAname) {FA} ++(-.5,-.5) rectangle +(.5,.5);
%\draw[draw=Gcolor, fill=Gcolor] node[nameSt, below=of FAname] (Gname) {G} ++(-.5,-.5) rectangle +(.5,.5);

% Creating the legend
\tikzset{nameSt/.style=
{anchor=west,rectangle,
minimum width=10pt,minimum height=10pt,
}}
\draw[] (8,1) node[nameSt,draw=Qcolor, fill=Qcolor,label=right:Q] (Qname) {};
\draw[] node[nameSt, draw=FAcolor, fill=FAcolor,below=of Qname,label=right:FA] (FAname) {} ;
\draw[] node[nameSt,draw=Gcolor, fill=Gcolor, below=of FAname,label=right:G] (Gname) {}; 

\end{tikzpicture}

\end{document}
share|improve this answer
add comment

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.