2

I am trying to draw this picture in latex, I have collected few bits and pieces from this forum, however I am unable to find a way to put geometrical elements over each other to get desired shape.

Setup

\documentclass[10pt]{beamer}
\input{headerBeamer}
\setbeamertemplate{caption}[numbered]
\graphicspath{{./drawings/}}
\title[short title]{XYZ}
\author{Abc}

\begin{document}
\begin{frame}
\begin{figure}
  \centering
  \includetikz{drawings/checkerboard.tikz}
\end{figure}
\end{frame}

\end{document}

checkerboard.tikz

\begin{tikzpicture}[scale=0.2]
\foreach \x in {0,...,8} \foreach \y in {0,...,5}
{
    \pgfmathparse{mod(\x+\y,2) ? "black" : "white"}
    \edef\colour{\pgfmathresult}
    \path[fill=\colour] (\x,\y) rectangle ++ (1,1);
}
\draw (0,0)--(0,6)--(9,6)--(9,0)--cycle;

\tikz \fill [black] (0.2,0.2) rectangle (1.8,0.8);
\tikz \fill [black,rotate around={-35:(-1,0.5)}] (0.2,0.2) rectangle (0.8,1.8);
\tikz \fill [black]   (0,0)     circle (2.5ex);
\tikz \fill [black]   (0,0)     circle (1.2ex);

\end{tikzpicture}
2

(I of course don't know what's in headerBeamer.tex, nor how \includetikz is defined, and your example would have been better without either of them. An example relying on files we don't have is not ideal.)

Your main problem is I think that you're nesting tikzpictures, and that is in general a bad idea. \tikz ... is a short form for \begin{tikzpicture} ...\end{tikzpicture}.

If you remove all the \tikz macros, then all the coordinates will belong to the same coordinate system, and then moving things around is just a matter of changing the numbers in the coordinates. I.e. instead of \tikz \fill (0,0) circle (1.2ex);, use \fill (x,y) circle (1.2ex);, where you change x and y.

There are other ways of doing similar things though, one possible approach is shown below. The shapes are drawn using \nodes, and they are positioned relative to each other. This might be simpler in that there is less guessing of coordinates.

enter image description here

\documentclass[10pt]{beamer}
\usepackage{tikz}
\usetikzlibrary{positioning}
\tikzset{
  blackrec/.style 2 args={fill=black,rectangle,minimum width=#1,minimum height=#2,inner sep=0pt},
  blackcirc/.style={fill=black,circle,inner sep=0pt,minimum size=#1}
}
\begin{document}
\begin{frame}
\centering
\begin{tikzpicture}
\begin{scope}[scale=0.2]
\foreach \x in {0,...,8} \foreach \y in {0,...,5}
{
    \pgfmathparse{mod(\x+\y,2) ? "black" : "white"}
    \edef\colour{\pgfmathresult}
    \path[fill=\colour] (\x,\y) rectangle ++ (1,1);
}
\draw (0,0)--coordinate (checkerleftside)(0,6)--(9,6)--(9,0)--cycle;
\end{scope}
\node [blackrec={3mm}{4mm},fill=blue,left] (bluerec) at (checkerleftside) {};
\node [blackrec={4mm}{9mm},anchor=north east] (rec1) at (bluerec.north west) {};
\node [blackcirc=5mm,anchor=north] (circ1) at (rec1.south) {};
\node [blackrec={4mm}{9mm},anchor=north,rotate=-75] (rec2) at (circ1.185) {};
\node [blackcirc=5mm,anchor=15] (circ2) at (rec2.south) {};
\node [blackrec={4mm}{8mm},anchor=north] (rec3) at (circ2.south) {};
\node [blackrec={10mm}{5mm},anchor=north] (rec4) at (rec3.south) {};

\end{tikzpicture}
\end{frame}

\end{document}
3

Time for a robot arm decoration:

\documentclass[tikz,border=5]{standalone}
\usetikzlibrary{decorations}
\pgfdeclaredecoration{robot arm}{draw first}{
\state{draw first}[width=\pgfdecoratedinputsegmentlength, next state=draw,
  persistent precomputation={%
    \def\x{\pgfdecoratedinputsegmentlength}
    \let\s=\pgfdecorationsegmentlength
    \let\a=\pgfdecorationsegmentamplitude}]{
  \fill [black] (0,-\s) rectangle (\s/2, \s);
  \fill [black] (\s/2,-\a/2) rectangle (\x-\s/2, \a/2);
}
\state{draw}[width=\x, switch if less than=\x+1 to final]{
  \fill [black] circle [radius=\s/2];
  \fill [black] (\s/2,-\a/2) rectangle (\x-\s/2, \a/2);
}
\state{final}{
  \fill [black] circle [radius=\s/2];
  \fill [black] (\s/2,-\a/2) rectangle (\x, \a/2);
  \fill [blue] (\x-\s, -\a/2) rectangle (\x, -3 * \a/2);
  \tikzset{shift={(\x-3*\s/2, -3 * \a/2)}, x=\s/2, y=\s/2}
  \foreach \i in {0,...,3}
    \foreach \j [evaluate={\o=mod(\i+\j,2)*100;}] in {0,...,3}{
      \draw [fill=black!\o!white] (\i,-\j) rectangle ++(1, -1);
}}}
\begin{document}
\begin{tikzpicture}
\path [decoration={robot arm, segment length=20pt, amplitude=10pt}, decorate] 
  (0,0) -- (0,3) -- ++(20:2) -- ++(80:1) -- ++(45:2);
\end{tikzpicture}
\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.