Graphics, Figures & TablesTikz multi line text nodes

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
ahmed
Posts: 7
Joined: Fri Nov 21, 2008 11:06 pm

Tikz multi line text nodes

Post by ahmed »

hello everybody
i wanna to put the equation in the ellipse in a new line and the symbol "\\" doesn't work inside the text braces.
i wanna any methode to put the equations in new line
as it is not like good to put it in the same line with the text.
also another problem , the figure is shifted to the right
any solution
here is the code

Code: Select all

\documentclass{article}
\usepackage[latin1]{inputenc}
\usepackage{tikz}
\usepackage{amsmath}
\usepackage{amssymb}
\usetikzlibrary{shapes,arrows}
\begin{document}
\pagestyle{empty}


% Define block styles
\tikzstyle{decision} = [diamond, draw, fill=blue!20, 
    text width=4.5em, text badly centered, node distance=3cm, inner sep=0pt]
\tikzstyle{block} = [rectangle, draw, fill=blue!20, 
    text width=5em, text centered, rounded corners, minimum height=4em]
\tikzstyle{cloud} = [draw, ellipse,fill=red!20, node distance=3cm,
    minimum height=2em]
    
\begin{tikzpicture}[node distance = 2cm,auto]
    % Place nodes
    \node [block] (Numerical) {Numerical Summary Measures};
    \node [block, below of=Numerical]                  (spread)               {Spread};
    \node [block, left of=spread,node distance=6cm]    (location)             {Location};
    \node [block, right of=spread,node distance=6cm]   (symmetry)             {Symmetry};
    %%Location Measures
    \node [cloud, below of=location,node distance=2cm] (median)               {Median \\$q_{0.5}$ };
    \node [cloud, below of=median,node distance=2cm]   (mean)                 {Mean   \\$\overline{X}=\frac{1}{N}\sum_{i=1}^{N} x_{i}$};
    \node [cloud, below of=mean,node distance=2cm]     (trimean)   		      {Trimean\\$\dfrac{q_{0.25}+2q_{0.5}+q_{0.75}}{4}$};
    \node [cloud, below of=trimean,node distance=2cm]  (trimmed)   		      {Trimmed\\$\overline{x_{\alpha}}=\dfrac{1}{n-2k}\sum_{i=k+1}^{n-k} {x_i}$};
   %%Spread Measures
    \node [cloud, below of=spread,node distance=2cm]   (Range)                {Range};
    \node [cloud, below of=Range,node distance=2cm]    (IQR)    		      {IQR};
    \node [cloud, below of=IQR,node distance=2cm] 	   (STD)    		      {STD};
    \node [cloud, below of=STD,node distance=2cm] 	   (MAD)      	          {MAD};
    \node [cloud, below of=MAD,node distance=2cm] 	   (Trimmed Variance)     {Trimmed Variance};
   %%Symmetry Measures
    \node [cloud, below of=symmetry,node distance=2cm]   (Skewness coefficient) {Skewness coefficient};
    \node [cloud, below of=Skewness coefficient,node distance=2cm]   (Yule-Kendall index) {Yule-Kendall index};
    % Draw arrows
    \draw [->] (Numerical) to (spread);
    \draw [->] (Numerical) to [bend right=20] (location);
    \draw [->] (Numerical) to [bend left =20] (symmetry);
    \draw [->] (median) to (mean) to (trimean) to (trimmed);
    \draw [->] (Range) to (IQR) to  (STD) to (MAD) to (Trimmed Variance);
    \draw [->] (Skewness coefficient) to (Yule-Kendall index);
\end{tikzpicture}

\end{document}
thanks in advance

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

gmedina
Posts: 2313
Joined: Wed Jul 11, 2007 11:45 pm

Tikz multi line text nodes

Post by gmedina »

Hi,

for the first problem, you can use \parbox commands; i.e., instead of

Code: Select all

\node [cloud, below of=location,node distance=2cm] (median)               
  {Median \\$q_{0.5}$ };
you can use something like this:

Code: Select all

\node [cloud, below of=location,node distance=2cm] (median) 
  {\parbox{1.5cm}{\centering Median \\$q_{0.5}$} };
Regarding the other issue, perhaps you should consider scaling the whole object.
1,1,2,3,5,8,13,21,34,55,89,144,233,...
ahmed
Posts: 7
Joined: Fri Nov 21, 2008 11:06 pm

Tikz multi line text nodes

Post by ahmed »

thanks
it works well , i also found another method whic it to
put the text width in the style this makes the pgf fell the existence of the \\ , i don't know why

Code: Select all

\tikzstyle{cloud} = [draw, ellipse,fill=red!20, node distance=3cm,text width=3cm,text centered, minimum height=2em]
but for the second problem, i donot know how to make the resizing you said without affecting the size of picture.
User avatar
gmedina
Posts: 2313
Joined: Wed Jul 11, 2007 11:45 pm

Tikz multi line text nodes

Post by gmedina »

If you want to maintain the actual size of the diagram, it will exceed the right margin; you could use a \makebox command to center it:

Code: Select all

\documentclass{article}
\usepackage[latin1]{inputenc}
\usepackage{tikz}
\usepackage{amsmath}
\usepackage{amssymb}
\usetikzlibrary{shapes,arrows}
\begin{document}
\pagestyle{empty}


% Define block styles
\tikzstyle{decision} = [diamond, draw, fill=blue!20, 
    text width=4.5em, text badly centered, node distance=3cm, inner sep=0pt]
\tikzstyle{block} = [rectangle, draw, fill=blue!20, 
    text width=5em, text centered, rounded corners, minimum height=4em]
\tikzstyle{cloud} = [draw, ellipse,fill=red!20, node distance=3cm,
    minimum height=2em,text width=3.8cm, text badly centered]
    
\makebox[\linewidth]{%
\begin{tikzpicture}[node distance = 2cm,auto]
    % Place nodes
    \node [block] (Numerical) {Numerical Summary Measures};
    \node [block, below of=Numerical]                  (spread)               {Spread};
    \node [block, left of=spread,node distance=6cm]    (location)             {Location};
    \node [block, right of=spread,node distance=6cm]   (symmetry)             {Symmetry};
    %%Location Measures
    \node [cloud, below of=location,node distance=2cm] (median)               {Median \\$q_{0.5}$ };
    \node [cloud, below of=median,node distance=2cm]   (mean)                 {Mean   \\$\overline{X}=\frac{1}{N}\sum_{i=1}^{N} x_{i}$};
    \node [cloud, below of=mean,node distance=2cm]     (trimean)               {Trimean\\$\dfrac{q_{0.25}+2q_{0.5}+q_{0.75}}{4}$};
    \node [cloud, below of=trimean,node distance=2cm]  (trimmed)               {Trimmed\\$\overline{x_{\alpha}}=\dfrac{1}{n-2k}\sum_{i=k+1}^{n-k} {x_i}$};
   %%Spread Measures
    \node [cloud, below of=spread,text width=1.5cm,node distance=2cm]   (Range)                {Range};
    \node [cloud, below of=Range,text width=1.5cm,node distance=2cm]    (IQR)                {IQR};
    \node [cloud, below of=IQR,text width=1.5cm,node distance=2cm]       (STD)                {STD};
    \node [cloud, below of=STD,text width=1.5cm,node distance=2cm]       (MAD)                   {MAD};
    \node [cloud, below of=MAD,node distance=2cm]       (Trimmed Variance)     {Trimmed Variance};
   %%Symmetry Measures
    \node [cloud, below of=symmetry,node distance=2cm]   (Skewness coefficient) {Skewness coefficient};
    \node [cloud, below of=Skewness coefficient,node distance=2cm]   (Yule-Kendall index) {Yule-Kendall index};
    % Draw arrows
    \draw [->] (Numerical) to (spread);
    \draw [->] (Numerical) to [bend right=20] (location);
    \draw [->] (Numerical) to [bend left =20] (symmetry);
    \draw [->] (median) to (mean) to (trimean) to (trimmed);
    \draw [->] (Range) to (IQR) to  (STD) to (MAD) to (Trimmed Variance);
    \draw [->] (Skewness coefficient) to (Yule-Kendall index);
\end{tikzpicture}
}

\end{document}
1,1,2,3,5,8,13,21,34,55,89,144,233,...
Post Reply