1

enter image description here

I didn't find square-type in tikz manual.

These two shapes should be centered at the same original point.

    \draw[dashed, red, ultra thick](0, 0) circle [radius=10mm];
    \draw[blue, thick](-1, 0)--(0, 1)--(1, 0)--(0, -1)--circle;

Why my code doesn't work?

Any help would be appreciated.

How to use relative coordinates (syntax ++(a, b)) to get the shape?

3
  • 5
    Typo? The second \draw should end with --cycle;, not --circle;.
    – campa
    Commented Feb 18, 2021 at 14:08
  • Thanks, bro. I missed it.
    – WYW
    Commented Feb 18, 2021 at 14:24
  • 1
    There is a rectangle type that can be easily made to be a square by supplying equal side lengths.
    – Raven
    Commented Feb 18, 2021 at 14:41

3 Answers 3

2

One more for fun: with using backgrounds and fit library.

\documentclass[border=3.141592mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{backgrounds,
                fit}

\begin{document}
    \begin{tikzpicture}[
base/.style args = {#1/#2}{draw=#1, very thick, fill=#2}
                       ]
\node [base=blue/white, minimum size=2cm, rotate=45] (t) {};
\scoped[on background layer]
    \node[base=yellow/yellow, circle, inner sep=0.5\pgflinewidth,
          fit=(t.north west) (t.south east)] {};
\end{tikzpicture}
\end{document}

enter image description here

1
  • Brilliant, thanks.
    – WYW
    Commented Feb 20, 2021 at 9:59
2

Just for fun:

\documentclass[tikz,border=2mm]{standalone}

\begin{document}
\begin{tikzpicture}
\draw[dashed, red, ultra thick] node[draw, circle, minimum width=2cm, rotate=30] (A){};
\draw (A.north east) -- (A.south east) -- (A.south west) -- (A.north west) -- cycle;
\end{tikzpicture}
\end{document}
1
  • Awesome! Thanks, bro.
    – WYW
    Commented Feb 20, 2021 at 9:58
1
\documentclass[tikz,border=2mm]{standalone}
\usetikzlibrary{shapes.geometric}

\begin{document}
\begin{tikzpicture}
\draw[dashed, red, ultra thick] (0,0) circle (1cm);
\node[regular polygon, regular polygon sides=4, minimum size=2cm, draw, rotate=30] at (0,0) {};
\end{tikzpicture}
\end{document}

enter image description here

1
  • Awesome! Thanks, bro.
    – WYW
    Commented Feb 20, 2021 at 9:59

You must log in to answer this question.

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