6

I create a picture of array which consists of nodes. I wonder how I can set the font size for the label which is below every cell (for example make it as scriptsize). This are my definitions:

\def\cells#1#2#3#4#5#6#7{
  \foreach [count=\i from 0] \j  in {1,...,#1} {
    \node[cell,label=below:\i] (cell\i) at (\i*0.5,0) {};
  }
}

\tikzset{
  cell/.style = {draw, minimum width=0.5cm, minimum height=0.5cm, minium size = 0.5cm}
}

enter image description here

  • 1
    Why does your \cells command take seven arguments when you only use one? – Svend Tveskæg Sep 13 '14 at 13:09
10

Just add \scriptsize:

\node[cell,label=below:{\scriptsize \i}]

You can change the font or whatever in the same way.

  • I didn't expected it will be so easy. Thanks! – Ziva Sep 12 '14 at 21:13
12

I know it's more tedious for this simple example, but for educational purposes it might be interesting to see how to add proper TikZ styles to the label:

\node[cell,label={[font=\small, red, rotate=20]below:\i}]

Note that the braces around the value in label={[]stuff} are necessary.

3

A PSTricks solution:

\documentclass{article}

\usepackage{multido,pstricks}
\psset{dimen = m}

\begin{document}

\def\cells{11} % number of cells
\begin{pspicture}(\cells,1.4)
  \multido{\r = 0.5+1, \i = 0+1}{\cells}{%
    \psframe(!\r\space 0.5 sub 0.4)(!\r\space 0.5 add 1.4)
    \rput(\r,0.9){$0$}
    \rput(\r,0.1){\scriptsize $\i$}}
\end{pspicture}

\end{document}

output

  • 7
    I like to imagine the people posting "A PSTricks Solution" answers to TikZ questions to be brave warriors, vigorously fighting their last stand against the horde of TiKZ questions flooding the realms of TeX.SX. I know it's silly, but your Viking avatar just fits perfectly into this scenario. :-D +1 – Fritz Sep 13 '14 at 23:17
1

Just 4 fun with PSTricks.

\documentclass[pstricks,border=12pt,12pt]{standalone}

\begin{document}
\begin{pspicture}[dimen=m](11,1.5)
    \foreach \i in {0,...,10}{\rput(\i,.5){\psframe(1,1)\rput(.5,.5){0}\uput[-90](.5,0){\i}}}
\end{pspicture}
\end{document}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.