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 am designing tikz images of numbers arranged in a tabular environment. Each number is formatted according to a particular style (different colors and shape). I first define the style for each number and then arrange them in a tabular environment.

Question: Is there a way to make my code more elegant and/or more systematic?

I would have liked to have been able to define commands for numbers in the style of \81, but couldn't work out how to do it (except for single digits) so I settled for \eightyone. However, now I would like to write a loop over a list of numbers, but the "no-number" notation makes it cumbersome. I would like to be able to handle large collections of numbers. Any suggestion?

Minimum example: Edit: In my real-word example each number has a different style, for simplicity here I made them all circled and green.

\documentclass[margin=0pt]{article}%
\usepackage[svgnames,x11names]{xcolor}%
\usepackage{tikz}%
\usepackage{rotating}% provides sideways environment
\begin{document}%
\newcommand{\mycolor}{Brown4!30!DarkGreen}%
\newcommand*\circled[1]{\tikz[baseline=(char.base)]{%
            \node[shape = circle, draw, inner sep = 1.8pt, fill = green!30!black!10] (char) {#1};}}%
\newcommand{\eightyone}{\color{\mycolor}{\circled{81}}}%
\newcommand{\eightytwo}{\color{\mycolor}{\circled{82}}}%
\newcommand{\eightythree}{\color{\mycolor}{\circled{83}}}%
\newcommand{\eightyfour}{\color{\mycolor}{\circled{84}}}%
\newcommand{\eightyfive}{\color{\mycolor}{\circled{85}}}%
\newcommand{\eightysix}{\color{\mycolor}{\circled{86}}}%
\newcommand{\eightyseven}{\color{\mycolor}{\circled{87}}}%
\newcommand{\eightyeight}{\color{\mycolor}{\circled{88}}}%
\newcommand{\eightynine}{\color{\mycolor}{\circled{89}}}%

\fontfamily{pzc}\selectfont%
\parindent=0pt%
    \begin{tikzpicture}%
        \node[anchor = base, inner sep = 0pt, outer sep = 0pt, scale = 6] {%
            \begin{sideways}%
            \begin{tabular}{ccc}%
               \eightyone    & \eightytwo    & \eightythree   \\%
               \eightyfour   & \eightyfive   &  \eightysix    \\%
               \eightyseven  & \eightyeight  & \eightynine    \\%
            \end{tabular}%
            \end{sideways}%
        };%
    \end{tikzpicture}%
\end{document}%

enter image description here

Also, question in passing, I'd like to center the numbers a bit better, being slanted they are currently leaning too much to the right.

Edit: There is a follow-up on this, in case anyone has an interest in these things: Tikz Nodes Positions and Shapes with a General Number of Nodes

share|improve this question
add comment

2 Answers 2

up vote 7 down vote accepted

Here is another minimal solution using \foreach. I have decided to add it as separate answer for the sake of clarity.

\documentclass{article}%
\usepackage[svgnames,x11names]{xcolor}%
\usepackage{tikz}%
\usetikzlibrary{shapes.geometric}
\usepackage{rotating}% provides sideways environment
\tikzset{
  81/.style={shape = rectangle, rounded corners=.5em, draw=Brown4!30!DarkGreen, inner sep = 1.8pt,
         fill = green!30!black!10,text=Brown4!30!DarkRed,
         font=\fontfamily{pzc}\selectfont,align=center
         },
  82/.style={shape = ellipse, rounded corners=.5em, draw=Brown4!30!DarkGreen, inner sep = 1.8pt,
         fill = green!30!black!10,text=Brown4!30!DarkRed,
         font=\fontfamily{pzc}\selectfont,align=center
         },
  83/.style={shape = star, rounded corners=.5em, draw=Brown4!30!DarkGreen, inner sep = 1.8pt,
         fill = green!30!black!10,text=Brown4!30!DarkRed,
         font=\fontfamily{pzc}\selectfont,align=center
         },
  84/.style={shape = diamond, rounded corners=.5em, draw=Brown4!30!DarkGreen, inner sep = 1.8pt,
         fill = green!30!black!10,text=Brown4!30!DarkRed,
         font=\fontfamily{pzc}\selectfont,align=center
         }
}
\begin{document}%
  \begin{sideways}
    \begin{tikzpicture}
      \foreach \x/\y/\z in {0/0/81,6/0/82}
         \node[anchor = base, inner sep = 0pt, outer sep = 0pt, scale = 6,\z] at (\x,\y) {\z};%
      \foreach \x/\y/\z in {0/-5/83,6/-5/84}
         \node[anchor = base, inner sep = 0pt, outer sep = 0pt, scale = 6,\z] at (\x,\y) {\z};%
    \end{tikzpicture}%
  \end{sideways}
\end{document}%

enter image description here

Here you have to decide the coordinates and number of columns and rows by yourself. Further improvisation is left as home work ;)

share|improve this answer
    
This is superb!! So I'm accepting this one instead. Btw I should have used the standalone class for this purpose, as the image will fill the page better, and also by setting, say, scale = 7 inside the first, common node, the image pretty much fills the page. Of course for tight cropping there is this most excellent solution: tex.stackexchange.com/questions/155751/crop-a-tikzpicture/… –  PatrickT Feb 2 at 2:46
add comment

Here is one method with matrix and tikz:

\PassOptionsToPackage{svgnames,x11names}{xcolor}
\documentclass{article}
\usepackage{rotating}
\usepackage{tikz}
\usetikzlibrary{matrix,shapes.geometric}

\begin{document}

\tikzset{
table/.style={
  matrix of nodes,
  row sep=1ex,
  column sep=2ex,
  nodes={shape = circle, draw=Brown4!30!DarkGreen, inner sep = 1.8pt, 
         fill = green!30!black!10,text=Brown4!30!DarkGreen,
         font=\fontfamily{pzc}\selectfont,align=center},
  },
  81/.style={shape = rectangle, rounded corners=.5em, draw=Brown4!30!DarkGreen, inner sep = 1.8pt,
         fill = green!30!black!10,text=Brown4!30!DarkRed,
         font=\fontfamily{pzc}\selectfont,align=center
         },
  82/.style={shape = ellipse, rounded corners=.5em, draw=Brown4!30!DarkGreen, inner sep = 1.8pt,
         fill = green!30!black!10,text=Brown4!30!DarkRed,
         font=\fontfamily{pzc}\selectfont,align=center
         },
  83/.style={shape = star, rounded corners=.5em, draw=Brown4!30!DarkGreen, inner sep = 1.8pt,
         fill = green!30!black!10,text=Brown4!30!DarkRed,
         font=\fontfamily{pzc}\selectfont,align=center
         }         
}
\begin{sideways}
\begin{tikzpicture}
\matrix (mat) [table]
{
|[81]|81 & |[82]|82 & |[83]|83 \\
84 & 85 & 86 \\
86 & 87 & 88 \\
};
\end{tikzpicture}
\end{sideways}

\end{document}

enter image description here

share|improve this answer
    
That was fast! Thanks Harish. Now I'm afraid there is one thing I should have made clearer: each number will have different styles (colors and shapes). Can I still use your approach? –  PatrickT Feb 2 at 1:45
    
@PatrickT Certainly, see the updated answer. –  Harish Kumar Feb 2 at 1:50
    
thanks! but how do I make a loop work on this? My point was that I wanted to have a collection of objects like \81, \82, \83 and loop over that for n = \1 to n = \100 for instance. Sorry I didn't make that clear enough. –  PatrickT Feb 2 at 1:54
    
@PatrickT Do we have the information of gow many columns and rows are possible? You can use a \foreach with pre-determined set of coordinates and styles. But right now I got to go for some time. –  Harish Kumar Feb 2 at 2:07
    
Sure no problem, thanks for your help! I am experimenting with tables of about 100 numbers at a time (10 by 10), but may also raise that to 50 by 50 for printing on poster-size support. I would look at numbers from 1 to 100, say, from 1001 to 1100, etc.. The shape-color thing is to visually detect certain patterns based on some of the numbers' number-theoretic properties. The purpose is educational. –  PatrickT Feb 2 at 2:11
show 1 more comment

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.