# Wrong line spacing when changing the font size inside of a rectangle

i'm trying to change the font size inside of a rectangle and always the line space between the last and the second last line is getting wrong. How can that be fixed?

\documentclass[]{article}
\usepackage{tikz}
\usetikzlibrary{shapes}

\begin{document}
\begin{tikzpicture}
\tikzstyle{block} = [rectangle, draw, text centered, thick, node distance = 2cm, text width=1cm]
\node[block]                (init)  {1 \\  2 \\ 3  \\ 4};
\node[block,right of=init]  (second){\scriptsize 1 \\ 2 \\ 3  \\ 4};
\node[block,right of=second](third) {1 \\ \scriptsize 2 \\ 3  \\ 4};
\end{tikzpicture}
\end{document}


-

## 3 Answers

Workaround that works. When changing the fontsize for the entire node, I prefer using the font option instead.

\documentclass[]{article}
\usepackage{tikz}
\usetikzlibrary{shapes}

\begin{document}
\begin{tikzpicture}
\tikzstyle{block} = [rectangle, draw, text centered, thick, node distance = 2cm, text width=1cm]
\node[block]                (init)  {1 \\  2 \\ 3  \\ 4};
\node[block,right of=init,font=\scriptsize]  (second){1 \\ 2 \\ 3 \\ 4};
\node[block,right of=second,font=\scriptsize](third) {{\normalsize 1} \\ 2 \\ 3 \\ 4};
\end{tikzpicture}
\end{document}

-

Put the rows in a tabular:

\documentclass[]{article}
\usepackage{tikz}
\usetikzlibrary{shapes}

\newcommand{\mylist}[2][]{#1\begin{tabular}{@{}c@{}}#2\end{tabular}}

\begin{document}
\begin{tikzpicture}
\tikzstyle{block} = [rectangle, draw, text centered, thick,
node distance = 2cm, text width=1cm]
\node[block]                (init)  {\mylist{1 \\  2 \\ 3  \\ 4}};
\node[block,right of=init]  (second){\mylist[\scriptsize]{1 \\ 2 \\ 3  \\ 4}};
\node[block,right of=second](third) {\mylist[\scriptsize]{\normalsize 1 \\ 2 \\ 3  \\ 4}};
\end{tikzpicture}
\end{document}


The optional argument is the "global" size, that you can override for single rows.

-

I prefer the solution of Torbjørn T. but I would like to understand why the option font works ?

Another possibility is

\documentclass[]{article}
\usepackage{tikz}
\usetikzlibrary{shapes}

\begin{document}
\begin{tikzpicture}
\tikzstyle{block} = [rectangle, draw, text centered, thick,
node distance = 2cm,
text width=1cm]
\node[block]                (init)  {1 \\  2 \\ 3  \\ 4};
\node[block,right of=init]  (second){{\scriptsize 1} \\{\normalsize 2}\\{\scriptsize 3}\\{\normalsize4 }\vfill};
\node[block,right of=second](third) {1 \\ \scriptsize 2 \\ 3  \\ 4\vfill};
\end{tikzpicture}

\end{document}

-
Yeah, I would like to know that myself. I just tried it, and found that it worked, but why it works, I can't say. –  Torbjørn T. Dec 8 '11 at 15:32
It must be the way LaTeX treats paragraphs that's causing it. If I recall correctly the default line spacing is the same for an entire paragraph and depends on the text size at the start of the paragraph. When not using the font command the text size is changed after the paragraph is started and hence the line spacing is not changed. –  jonalv Aug 12 '14 at 8:50