2

Is it possible in tikz to generate a list using length registers?

for exemple:

\foreach \x in {0,1,...,6}

with produce the following list: "0,1,2,3,4,5,6"

but now I want to produce a list using registers \pas and \largeur, i.e.

\foreach \x in {0,\pas,...,\largeur}

but this does not work.

MWE

\documentclass{beamer}
\newlength{\slw}\setlength{\slw}{160mm}
\newlength{\slh}\setlength{\slh}{90mm}
\geometry{verbose,papersize={\slw,\slh}}

\mode<presentation>
\usetheme{metropolis}
\usepackage{tikz,pgffor}
\usetikzlibrary{calc}

\newlength\pas
\setlength\pas{10mm}

\begin{document}
\begin{frame}
  \begin{tikzpicture}
    \foreach \x in {0,\pas,...,\slw}
    {
      \node at (\x,0) {\x};
    }
\end{tikzpicture}
  \end{frame}
\end{document}
2
  • Please don't edit solutions into your question. That's very confusing. You can post a self-answer if you'd like. Apr 22 at 12:06
  • it's ok I removed it Apr 22 at 12:22

1 Answer 1

3

You can use e.g. https://tex.stackexchange.com/a/541869/36296 to convert to cm

\documentclass[aspectratio=169]{beamer}

\mode<presentation>
\usetheme{moloch}% modern fork of the metropolis theme
\usepackage{tikz}
\usetikzlibrary{calc}

\newlength\pas
\setlength\pas{10mm}

% from https://tex.stackexchange.com/a/541869/36296
\NewExpandableDocumentCommand{\getlengthnumber}{O{pt}m}{%
  % #1 (optional, default pt), #2 = length
  \fpeval{(#2)/(1#1)}%
}

\begin{document}
\begin{frame}
  \begin{tikzpicture}
    \foreach \x in {0,\getlengthnumber[cm]{\pas},...,\getlengthnumber[cm]{\paperwidth}}
    {
      \node at (\x,0) {\x};
    }
\end{tikzpicture}
  \end{frame}
\end{document}

enter image description here

You must log in to answer this question.

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