Layout structure and TikZ pictures

The following image

is a scan of a series of papers I would like to try to write in latex/tikz. Here they are some explanations.

1) Each paper contains many exercises. An example of exercise is [S(19)][]:

2) Exact exercise position is not really important and should be similar to the words in a text: from left to right and then again on the next row.

3) Each exercise is made of two or more side by side figures (in this page example, rectangles). For instance, the previous exercise was made of two rectangles, the first one containing, S(19) and the second one, emtpy.

4) The following is how I ideally would like to write some of the exercises in the image.

Exercise 1 - [S(19)][]

exercise
rectangle
S_symbol
circle
19
rectangle
empty


Exercise 2 - [S(S(10))][S()][]

exercise
rectangle
S_symbol
circle
S_symbol
circle
10
rectangle
S_symbol
circle
empty
rectangle
empty


I used Latex many years ago and I just started to study TikZ. I would appreciate some Latex and TikZ advices how to structure this work.

Thank you in advance!

• put the images as links and we can convert them for you – percusse Oct 8 '16 at 23:07
• Really sorry but I don't understand what you mean. – Spiffhero Oct 8 '16 at 23:14
• Welcome! You mean you want to do it by indentation or something? I'd strongly recommend considering alternative syntax in that case. – cfr Oct 9 '16 at 2:34
• No, I don't need to use indentation. For [S(19)][] I could write something like: \exercise { \rectangle {\S_symbol \Circle 19 } \rectangle \empty} – Spiffhero Oct 9 '16 at 6:58

As you implied, you probably want to use tikz. It is probably possible to define macros to get something more like the syntax you've described, but I'd recommend using the tikz syntax directly to preserve flexibility (since you seem to want a lot of control over the style).

In the example below I've defined a macro for circling things (intended for text, but can also be other things) since you seem to use that a lot. Depending on what you need to do frequently you might want to define other macros (or tikz styles) as well.

I've shown one way to draw some of the exercises you've given. Hopefully it's clear how to extend the technique.

\documentclass{article}
\usepackage{tikz,wasysym}
\usetikzlibrary{shapes, positioning}

\newcommand{\ellipsed}[2][]{\tikz[baseline]{\node[ellipse, draw, inner sep=1pt, anchor=base, minimum width=1.3em, #1] {#2};}}
\tikzstyle{blocks}=[rectangle split, draw, rectangle split parts=#1, anchor=base]
\tikzstyle{horizontal}=[rectangle split horizontal]
\newcommand{\emptyblock}{\tikz[baseline=-.25em, scale=.5]{\path[use as bounding box] (-1,-1) rectangle (1,1);}}

\begin{document}
\begin{tikzpicture}
\node[blocks=2, rectangle split horizontal] (ex1)
{
S \ellipsed{19}
\nodepart{two}
\emptyblock
};

\node[blocks=3, horizontal, right=1em of ex1.north east, anchor=north west] (ex2)
{
S \ellipsed{S \ellipsed{10}}
\nodepart{two}
S \ellipsed{\vphantom{1}}
\nodepart{three}
\emptyblock
};

\node[blocks=2, below=1em of ex1.south west, anchor=north west] (ex3)
{
\renewcommand\arraystretch{1.5}
$\begin{array}{ccc} \ellipsed[fill=lightgray]{1} & \ellipsed{1} & \ellipsed[fill=lightgray]{10}\\ \ellipsed{10} & \ellipsed[fill=lightgray]{100} & \ellipsed{10}\\ \ellipsed{100} & \ellipsed{1} & \ellipsed{100} \end{array}$
\nodepart{two}
\emptyblock
};

\node[blocks=2, horizontal, right=1em of ex3.north east, anchor=north west] (ex4)
{
+ \ellipsed{700 \sun} \ellipsed{30 \sun} \ellipsed{7 \sun}
\nodepart{two}
\emptyblock
};

\node[blocks=2, horizontal, below=1em of ex4.south west, anchor=north west, rectangle split part fill={lightgray, white}] (ex5)
{
\emptyblock
\nodepart{two}
\emptyblock
};
\end{tikzpicture}
\end{document}


It's probably easiest to do the more complicated pictures like umbrellas, candles, etc. by importing images via \includegraphics, which works fine inside tikz code. There are also plenty of symbols packages where you might find some of those pictures pre-made (like wasysym, which I've used). If you really need some blocks filled with patterns rather than solid colors, take a look at this question.

You could also do each exercise as a separate tikzpicture and let LaTeX decide how to do the layout--it will flow the pictures across the page like text. This may be easier, but will probably result in a less efficient use of space. I think the relative positioning within a single picture makes a nicer output and is not too much more complicated.

• I tried to use your snippet and it works great! The logical structure you propose is clear and looks well adapted to my problem. Now I will spend some time to fine tune it and probably I will be back with some other question. Thanks a lot!! – Spiffhero Oct 10 '16 at 9:33