在 TikZ 中绘制 16 边形的问题

在 TikZ 中绘制 16 边形的问题

有没有公​​式或函数可以直接绘制 16 边形?我编写了一个 16 边形的代码,但它不能让我满意。我想将页码放在 16 边形内。我该怎么做?

\documentclass[10pt]{article}
\usepackage{pgf,tikz,pgfplots}
\pgfplotsset{compat=1.15}
\usepackage{mathrsfs}
\usetikzlibrary{arrows}
\pagestyle{empty}
\begin{document}
\begin{tikzpicture}[line cap=round,line join=round,>=triangle 45,x=1cm,y=1cm]
\clip(-10.13291673529722,-9.435386632879322) rectangle (9.695190117199873,4.648701636574812);
\draw [line width=2pt] (-3,-3)-- (-3,-4);
\draw [line width=2pt] (-3,-4)-- (-2,-5);
\draw [line width=2pt] (-2,-5)-- (-3,-6);
\draw [line width=2pt] (-3,-6)-- (-3,-7);
\draw [line width=2pt] (-3,-7)-- (-4,-7);
\draw [line width=2pt] (-4,-7)-- (-5,-8);
\draw [line width=2pt] (-5,-8)-- (-6,-7);
\draw [line width=2pt] (-6,-7)-- (-7,-7);
\draw [line width=2pt] (-7,-7)-- (-7,-6);
\draw [line width=2pt] (-7,-6)-- (-8,-5);
\draw [line width=2pt] (-8,-5)-- (-7,-4);
\draw [line width=2pt] (-7,-4)-- (-7,-3);
\draw [line width=2pt] (-7,-3)-- (-6,-3);
\draw [line width=2pt] (-6,-3)-- (-5,-2);
\draw [line width=2pt] (-5,-2)-- (-4,-3);
\draw [line width=2pt] (-4,-3)-- (-3,-3);
\end{tikzpicture}
\end{document}

而且我这个功能跟画钻石是一样的啊!

\tikzset{%
  pics/diamond/.style args={name=#1}{%
    code={%
      \begin{scope}[local bounding box=#1,scale=0.25]
        \draw (0,0)--++(0:1)--++(-45:1.2)--++(45:1.2)--++(0:1)--++(90:1)--++(45:1.2)--++(135:1.2)--++(90:1)--++(180:1)--++(135:1.2)--++(225:1.2)--++(180:1)--++(-90:1)--++(-135:1.2)--++(-45:1.2)--cycle;
      \end{scope}
    }
  }
}
%سربرگ ها 
\fancypagestyle{mainstyle}{%
\fancyhf{}
\fancyhead[LO,RE]{\myfancynum}

\fancyhead[LE]{%
  \begin{tikzpicture}[overlay,remember picture]
    \node[anchor=west] at ([xshift=12ex,yshift=-14ex]current page.north west) {\textcolor{cyan}{\rl{ test}}};
  \end{tikzpicture}%
}
\fancyhead[RO]{%
  \begin{tikzpicture}[overlay,remember picture]
%    \node[anchor=east] at ([xshift=-12ex,yshift=-14ex]current page.north east){\textcolor{cyan}{\large\rl{\leftmark}}};
  \end{tikzpicture}%
%\textcolor{cyan}{\leftmark}
}
\renewcommand{\headrulewidth}{0pt}
\pagestyle{fancy}
\linespread{1}
\newcommand{\myfancynum}{%
  \begin{tikzpicture}[remember picture,overlay,yshift=2cm]
%      \path (0,0) [use as bounding box]
%        node[diamond, draw=cyan, inner sep=0pt, minimum size=32pt] (pageno) {\thepage} ;
\pic at (0,0) {diamond={name=a}};
\node at (a.center){\thepage};
\pic at (0,0) {diamond={name=a}};
\node at (a.center){\thepage};
    \checkoddpage\ifoddpage
    % 36pt = 32pt + 4pt +4pt; 
    \path (pageno.west) node[fill=cyan, fill opacity=0.4, diamond, inner sep=0pt, minimum size=16pt] {};
   \draw[cyan] (pageno.north) ++(0, +4pt) -- ++(55pt, -55pt) -- ++(2\linewidth,0);

    \draw[cyan] (pageno.east) ++(4pt, 0) -- ++(-60pt, -60pt) -- ++(0, -4cm);


    \else
    \path (pageno.east) node[fill=cyan, fill opacity=0.4, diamond, inner sep=0pt, minimum size=16pt] {};
    \draw[cyan] (pageno.north) ++(0, +4pt) -- ++(-55pt, -55pt) -- ++(-2\linewidth,0);%-40,-40
    \draw[cyan] (pageno.west) ++(-4pt,0) -- ++(60pt, -60pt) -- ++(0, -4cm);

    \fi
    \end{tikzpicture}%
}
\fancyfoot[OL]{%
  \begin{tikzpicture}[overlay,remember picture]
\foreach \x in {1,...,250}
\draw[color=cyan,xshift=2cm,yshift=-0.5cm] node  {\color{cyan}\rule{\paperwidth}{.1pt}};
\node[fill=cyan, fill opacity=1, diamond, inner sep=0pt, minimum size=16pt,xshift=12.4cm,yshift=-0.5cm] {};
  \end{tikzpicture}%
}

\fancyfoot[ER]{%
  \begin{tikzpicture}[overlay,remember picture]
\foreach \x in {1,...,250}
%\draw[color=cyan,xshift=-2cm,yshift=-1.5cm] node  {\color{cyan}\rule{\paperwidth}{.1pt}};
%\node[fill=cyan, fill opacity=1, diamond, inner sep=0pt, minimum size=16pt,xshift=-12.4cm,yshift=-1.5cm] {};%cric fot
%
\draw[color=cyan,xshift=-2cm,yshift=-0.5cm] node  {\color{cyan}\rule{\paperwidth}{.1pt}};
\node[fill=cyan, fill opacity=1, diamond, inner sep=0pt, minimum size=16pt,xshift=-12.4cm,yshift=-0.5cm] {};%cric fot
  \end{tikzpicture}%
}
}
\renewcommand{\headrulewidth}{0pt}
%\fancypagestyle{tocstyle}{%
%\fancyhf{} 
%\fancyhead[C]{%
%\begin{tikzpicture}[overlay,remember picture]
%j
%\end{tikzpicture}
%}
% }

在此处输入图片描述

它是一个 16 边的形状。 在此处输入图片描述

答案1

这些形状被称为星形。你可以玩star point ratio

\documentclass[tikz,border=3.14mm]{standalone}
\usetikzlibrary{shapes.geometric}
\begin{document}
\begin{tikzpicture}
 \node[draw,star,star points=8]{hello}; 
 \node[draw,star,star points=8,star point ratio=1.25] at (3,0) {hello};
 \node[draw,star,star points=8,star point ratio=0.8] at (6,0) {hello};
\end{tikzpicture}
\end{document}

在此处输入图片描述

答案2

像这样?

\documentclass[]{article}
\usepackage{tikz}
\tikzset{
  pics/diamond/.style args={name=#1}{
    code={
      \begin{scope}[local bounding box=#1,scale=0.5]
        \draw (0,0)--++(0:1)--++(-45:1.2)--++(45:1.2)--++(0:1)--++(90:1)--++(45:1.2)--++(135:1.2)--++(90:1)--++(180:1)--++(135:1.2)--++(225:1.2)--++(180:1)--++(-90:1)--++(-135:1.2)--++(-45:1.2)--cycle;
      \end{scope}
    }
  }
}

\begin{document}
\begin{tikzpicture}
\pic at (0,0) {diamond={name=a}};
\node at (a.center){\thepage};
\end{tikzpicture}

\end{document}

在此处输入图片描述

答案3

\documentclass[tikz, margin=3mm]{standalone}
\setcounter{page}{111}
\newcommand\PAGE%
{
\begin{tikzpicture}[
  box/.style args = {##1/##2}{draw, minimum size=\dimexpr9mm-##1\pgflinewidth, 
                            rotate=##2, fill=white},
                    ]
\node [box=0/0] {};
\node [box=0/45] {};
\node [box=1/0, draw=none] {\thepage};
\end{tikzpicture}
}

\begin{document}
\PAGE
\end{document}

在此处输入图片描述

相关内容