1

enter image description here

Hello,

I'm trying to number the elements in the grid as follows. I'm wondering if I can get some help. Thank you. I'm confused to write the logic.

\documentclass{beamer}
\usepackage[english]{babel}
\usepackage[document]{ragged2e}
\usepackage{utopia} %font utopia imported
\usepackage{graphicx} %package to manage images
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{blkarray, bigstrut}
\usepackage[utf8]{inputenc}%codification of the document
\usepackage{tikz}
\usetheme{Warsaw}
\usecolortheme{beaver}
\usetikzlibrary{decorations.markings}

\title[Module 8]{MODULE 8 \\ Data Matrix : Generation }
\author[aa]{by\\aa
}
% START add slide number
\newcommand*\oldmacro{}%
\let\oldmacro\insertshorttitle%
\renewcommand*\insertshorttitle{%
  \oldmacro\hfill%
  \insertframenumber\,/\,\inserttotalframenumber}
% END add slide number


\date

\begin{document}


%1
%Here begins the body of the document
\begin{frame}
\titlepage
\end{frame}
%13
\begin{frame}
\frametitle{Re-numbered 2-D grid}
\begin{center}
\begin{tikzpicture}[thick,scale=0.4, every node/.style={scale=0.6}]

\draw (0,0) grid[step=2cm] (6,8);
\foreach \X [count=\x] in {0,...,3} 
{\foreach \Y [count=\y] in {0,...,4}
 {
 \ifnum\Y=0
  \node[anchor=north west] at (2*\X,2*\Y) {\x};
 \else
  \ifnum\Y=1
    {
   \node[anchor=south east] at (2*\X,2*\Y) {\number\numexpr\x+4};
    }
 \else
  \ifnum\Y=2
    {
   \node[anchor=south east] at (2*\X,2*\Y) {\number\numexpr\x+8};
    }
 \else
  \ifnum\Y=3
   {
   \node[anchor=south east] at (2*\X,2*\Y) {\number\numexpr\x+12};
    }
  \else
  {
   \node[anchor=south east] at (2*\X,2*\Y) {\number\numexpr\x+16};
  }
  \fi
 \fi
 \fi
 \fi
 }
}
\end{tikzpicture}
\end{center}
\end{frame}
2

To divide the slide in two halves, simply place the two tikzpictures next to each other.

Some other comments regarding your code:

  • \usepackage{utopia} this package is obsolete

  • You don't need \usepackage{graphicx} with beamer

  • Please do not load the same package multiple time, e.g. \usepackage[utf8]{inputenc}

  • Instead of this complicate construct

    % START add slide number
    \newcommand*\oldmacro{}%
    \let\oldmacro\insertshorttitle%
    \renewcommand*\insertshorttitle{%
     \oldmacro\hfill%
     \insertframenumber\,/\,\inserttotalframenumber}
    % END add slide number
    

    you can simply use \setbeamertemplate{page number in head/foot}[totalframenumber]

  • in your tikz code, you could save a lot of if-else conditions by using \x+\Y*4


\documentclass{beamer}
\usepackage[english]{babel}
\usepackage{ragged2e}
%\usepackage{utopia} %font utopia imported
%\usepackage{graphicx} %package to manage images
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{blkarray, bigstrut}
%\usepackage[utf8]{inputenc}%codification of the document
\usepackage{tikz}
\usetheme{Warsaw}
\usecolortheme{beaver}
\usetikzlibrary{decorations.markings}

\title[Module 8]{MODULE 8 \\ Data Matrix : Generation }
\author[aa]{by\texorpdfstring{\\}{}aa}
\setbeamertemplate{page number in head/foot}[totalframenumber]


\begin{document}

\begin{frame}
\frametitle{Re-numbered 2-D grid}
\begin{center}
\begin{tikzpicture}[thick,scale=0.4, every node/.style={scale=0.6}]

\draw (0,0) grid[step=2cm] (6,8);
\foreach \X [count=\x] in {0,...,3} 
{\foreach \Y [count=\y] in {0,...,4}
 {
 \ifnum\Y=0
  \node[anchor=north west] at (2*\X,2*\Y) {\x};
 \else
   \node[anchor=south east] at (2*\X,2*\Y) {\number\numexpr\x+\Y*4};
 \fi
 }
}
\end{tikzpicture}
\hspace{3cm}
\begin{tikzpicture}[thick,scale=0.4, every node/.style={scale=0.6}]

\draw (0,0) grid[step=2cm] (6,8);
\foreach \X [count=\x] in {0,...,3} 
{\foreach \Y [count=\y] in {0,...,4}
 {
 \ifnum\Y=0
  \node[anchor=north west] at (2*\X,2*\Y) {\number\numexpr(\x-1)*5+1};
 \else
  \node[anchor=south east] at (2*\X,2*\Y) {\number\numexpr(\x-1)*5+\Y+1};
 \fi
 }
}
\end{tikzpicture}
\end{center}
\end{frame}
\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.