2

I'm trying to automate the vertical alignment of these shapes so I can use a foreach loop to put them in a repeating pattern. (At the moment the triangle is a bit high and the circle is a bit low) Any ideas? Thanks heaps!

\documentclass{beamer}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric, positioning}


\tikzset{
    circle/.style={
        draw,
        regular polygon,
        regular polygon sides=100,
        fill=white,
        node distance=2cm,
         line width=1mm,
        minimum height=1cm
    }
}


\tikzset{
    triangle/.style={
        draw,
        regular polygon,
        regular polygon sides=3,
        fill=white,
        node distance=2cm,
         line width=1mm,
        minimum height=1.2cm
    }
}


\begin{document}

\begin{frame}
\begin{tikzpicture}
    
        \foreach \i in {0, 1, 2, 3} {
                    \ifodd\i
                        \node[triangle] at (\i * 1.5cm, 0) {};
                    \else
                        \node[circle] at (\i * 1.5cm, 0) {};
                    \fi
        }
    \end{tikzpicture}

\end{frame}
\end{document}

1 Answer 1

4

You can specify the anchor for the nodes to align them. Usually, center works well (which is default), but, in this case, you probably want south.

\documentclass{beamer}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric, positioning}


\tikzset{
  circle/.style={
    draw,
    regular polygon,
    regular polygon sides=100,
    fill=white,
    node distance=2cm,
    line width=1mm,
    minimum height=1cm
  }
}


\tikzset{
  triangle/.style={
    draw,
    regular polygon,
    regular polygon sides=3,
    fill=white,
    node distance=2cm,
    line width=1mm,
    minimum height=1.2cm
  }
}


\begin{document}
  
  \begin{frame}
    \begin{tikzpicture}
      
      \foreach \i in {0, 1, 2, 3} {
        \ifodd\i
        \node[triangle,anchor=south] at (\i * 1.5cm, 0) {};
        \else
        \node[circle,anchor=south] at (\i * 1.5cm, 0) {};
        \fi
      }
    \end{tikzpicture}
    
  \end{frame}
\end{document}

aligned at south

1
  • That is perfect! Thanks so much for your quick and super helpful response :) Commented Jun 18 at 6:33

You must log in to answer this question.

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