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'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}

enter image description here

share|improve this question

3 Answers 3

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}
share|improve this answer

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.

share|improve this answer

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} 
share|improve this answer
    
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 at 8:50

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.