0

Let's say I have the following string list of symbol: {a,b,+,9,3}.

Is there a way to print each element of this list with the possibility - EDIT 1: to control the space between each symbol and - to change some property (e.g. the rotate angle or color shade) and all this using pic and decoration if possible?

So, with this kind of code (1,2):

\documentclass[tikz]{standalone}
\usepackage{tikz}
\usetikzlibrary{decorations.markings,positioning}

\tikzset{%
symbols/.pic={% https://tex.stackexchange.com/a/350347/262081
    \node{a,b,+,9,3};% Not working !!!!!!!!!!!!!!!!!!!
},%
    inlinesymbols/.style={%
        decoration={%
            markings,%
            mark =%
                between positions 0 and 1 step 5mm % adjust step size here
                with {{\pgfmathsetmacro{\myangle}{360*rnd}%
                      \pic[rotate=\myangle] {symbols};}% https://tex.stackexchange.com/a/576704/262081
                    }%
        },%
        postaction={decorate}%
    },%
}%

\begin{document}
\begin{tikzpicture} 
\path[inlinesymbols] (0,0) -- (2,0);%
\end{tikzpicture}
\end{document}

I would like to obtain something like this:

enter image description here

With the horizontal space between each symbol set for e.g. by decoration mark step (set to 5mm in the exemple above) or something else.

If it's not possible with a Tikz decoration or even a pic I'm also aware of alternative ways but with the possibility of changing some parameters (as the rotation angle) if possible.

EDIT 2: Why I want that ?

I would like to be able to inline (horizontally) draw a list of symbol regardless of the number of elements in this list and with the possibility of controling the space between each symbol and some property (e.g. rotation, shade, color) set for all symbol (i.e. the property is aplied to all symbols globally).

So, the use of Tikz pics and decoration are not mandatory but I like to use them.

EDIT 4: Final Working attempt

The Sandy G's answer below can be use in a Pic and so in a decoration:

\documentclass[tikz]{standalone}
\usepackage{tikz}
\usetikzlibrary{decorations.markings}

\newcommand{\hsp}{.5}

\tikzset{symbols/.pic={%
    \foreach \s[count=\n from 0] in {a,b,c,f}{%
    \pgfmathsetmacro{\myangle}{360*rnd}%
    \node[anchor=base, inner sep=0pt, outer sep=0pt, rotate=\myangle] at (\hsp*\n,0){\s};%
}},%
    inlinesymbols/.style={%
        decoration={%
            markings,%
            mark =%
                between positions 0 and 1 step 30mm % adjust step size here
                with {\pic[red] {symbols};}%
        },%
        postaction={decorate}%
    },%
}%

\begin{document}
\begin{tikzpicture}%[baseline]
\pic[red] {symbols};%
\path[inlinesymbols] (0,-1) -- (4,-1);%
\end{tikzpicture}
\end{document}

enter image description here

This permits to repeat the pattern and also - as Sandy G's method does - to individually set property to one symbol (as for the rotate angle in the above exemple) and globally (as for the red color in e.g.).

EDIT 3: First attempt

I tried something using listoftitems package in order to slipt the comma separated list and loop under the list elements (compared to the previous M(Non)WE above, the new lines of code are encapsulated between the tags: % < Begin NEW > and % < End NEW >).

\documentclass[tikz]{standalone}
\usepackage{tikz}
\usetikzlibrary{decorations.markings,positioning}
\usepackage{listofitems}

\def\mysymbollist{a,b,+,9,3}

\tikzset{%
% < Begin NEW >
\setsepchar{,}%
\readlist\mylist\mysymbollist
\foreachitem\x\in\mylist{%
\def\mymacroname{symbols\xcnt}%
\mymacroname/.pic={%
    \node{\x};%
},}%
% < End NEW >
    inlinesymbols/.style={%
        decoration={%
            markings,%
            mark =%
                between positions 0 and 1 step 20mm % adjust step size here
                with {% < Begin NEW >
                     {\foreachitem\x\in\mylist{%
                     \def\mypicname{symbols\xcnt}%
                     \pgfmathsetmacro{\myangle}{360*rnd}%
                      \pic[rotate=\myangle] {\mypicname};}%
                      }%
                      % < End NEW >
                    }%
        },%
        postaction={decorate}%
    },%
}%

\begin{document}
\begin{tikzpicture} 
\path[inlinesymbols] (0,0) -- (2,0);%
\end{tikzpicture}
\end{document}

But I got an error :

Incomplete \iffalse; all text was ignored after line 32.

Also the space between two symbols print is not controlled.

Any idea to fix the error and control space between symbols print?

M(Non)WE inspirational sources:

2 Answers 2

3

Not sure if this is exactly what you're looking for, but it's a simple solution.

enter image description here

The call is \symlist[<options>]{a,b,+,9,3}

<options> can be any attribute(s) recognized by tikz nodes. Spacing is controlled globally by setting \hsp (unit = cm).

Here is the code:

\documentclass{article}

\usepackage{tikz}

\newcommand{\hsp}{.5}

\newcommand{\symlist}[2][]{\begin{tikzpicture}[baseline]
\foreach \s[count=\n] in {#2}{\node[anchor=base, inner sep=0pt, outer sep=0pt, #1] at (\hsp*\n,0){\s};
}\end{tikzpicture}}

\begin{document}

Here is a symbol list \symlist{a,b,+,9,3} inline.

Here is a symbol list \symlist[red, rotate=30]{a,b,+,9,3} inline.

Here is a symbol list \symlist[blue, xscale=-.7]{a,b,+,9,3} inline.

\end{document}
2
  • Perfect ! Your solution is compatible with Pic and Decoration (see my question EDIT 4). Thanks a lot !
    – zetyty
    Mar 19, 2022 at 11:58
  • Replacing [count=\n] by [count=\n from 0] permits to remove the first horizontal space to the left of the first symbol a
    – zetyty
    Mar 24, 2022 at 9:23
1

I'm not sure I understand the problem...

    \documentclass{article}
    \usepackage{tikz}
    \begin{document}
    \begin{tikzpicture}[text height=2ex, text depth=0.5ex]
        \node at (0,0) [rotate=0]{a};
        \node at (0.5,0)[red,rotate=30]{b};
        \node at (1,0)[rotate=0]{$+$};
        \node at (1.5,0)[blue,rotate=-30]{$9$};
        \node at (2,0)[green,rotate=45]{$3$};
    \end{tikzpicture}
    \end{document}

enter image description here

1
  • Thanks for your answer. Unfortunately, I would have preferred a solution in which I don't have to worry about the number of elements in the list. It make me realize that my question was unclear, so I made some edit (see EDIT 1 & 2) and I made a first attempt to better show my need (see EDIT 3). Thanks again anyway.
    – zetyty
    Mar 18, 2022 at 20:20

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .