Friday, September 27, 2013

Adjusting size of nodes and text labels in tikz (LaTeX)

The following picture is created with tikz, using the same node sizes and text label sizes for every node:


\documentclass[border=3mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows,positioning}
\begin{document}

\begin{tikzpicture}[auto,node distance=.5cm,
    latent/.style={circle,draw,very thick,inner sep=0pt,minimum size=30mm,align=center},
    manifest/.style={rectangle,draw,very thick,inner sep=0pt,minimum width=45mm,minimum height=10mm},
    paths/.style={->, ultra thick, >=stealth'},
]

% Define observed variables
\node [manifest] (things) at (0,0) {things};

% Define latent variables
\node [latent] (all) [left=3.5cm of things] {All};
\node [latent] (random) [above right=3.5cm of things] {random};


% Draw paths from latent to observed variables
\draw [paths] (all) to node { } (things);
\draw [paths] (random) to node { } (things);

\end{tikzpicture}
\end{document}




However, I didn't like the node sizes,  so I changed them using the 'scale' argument within the 'node' command:



\documentclass[border=3mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows,positioning}
\begin{document}

\begin{tikzpicture}[auto,node distance=.5cm,
    latent/.style={circle,draw,very thick,inner sep=0pt,minimum size=30mm,align=center},
    manifest/.style={rectangle,draw,very thick,inner sep=0pt,minimum width=45mm,minimum height=10mm},
    paths/.style={->, ultra thick, >=stealth'},
]

% Define observed variables
\node [manifest, scale=.75] (things) at (0,0) {things};

% Define latent variables
\node [latent] (all) [left=3.5cm of things] {All};
\node [latent, scale=.5] (random) [above right=3.5cm of things] {random};


% Draw paths from latent to observed variables
\draw [paths] (all) to node { } (things);
\draw [paths] (random) to node { } (things);

\end{tikzpicture}
\end{document}




The scale command changes the size of the node, as well as the size of the text label. So, you may want to change the size of the text labels only. You can do this by using one of the following LaTeX text size commands:




\documentclass[border=3mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows,positioning}
\begin{document}

\begin{tikzpicture}[auto,node distance=.5cm,
    latent/.style={circle,draw,very thick,inner sep=0pt,minimum size=30mm,align=center},
    manifest/.style={rectangle,draw,very thick,inner sep=0pt,minimum width=45mm,minimum height=10mm},
    paths/.style={->, ultra thick, >=stealth'},
]

% Define observed variables
\node [manifest, scale=.75] (things) at (0,0) {\Large things};

% Define latent variables
\node [latent] (all) [left=3.5cm of things] {\large All};
\node [latent, scale=.5] (random) [above right=3.5cm of things] {\huge random};


% Draw paths from latent to observed variables
\draw [paths] (all) to node { } (things);
\draw [paths] (random) to node { } (things);

\end{tikzpicture}
\end{document}




Note that you can always change font size locally in LaTeX documents by using one of the following commands:

\tiny
\scriptsize
\footnotesize
\small
\normalsize
\large
\Large
\LARGE
\huge
\Huge 

No comments:

Post a Comment