使用 TikZ 绘制旗帜

使用 TikZ 绘制旗帜

我正在尝试在 TikZ 中创建一个标志,但从美学角度来看,它并不是最好的。这是我的 MWE:

\documentclass[letterpaper]{article}
\usepackage{fullpage}
%\usepackage{amsmath,amssymb,amsthm}
\usepackage[dvipsnames]{xcolor}
\usepackage{tikz}
\begin{document}
\usetikzlibrary{shapes.symbols,shapes.misc}
\begin{tikzpicture}[scale=0.25,transform shape]
\draw[rounded corners=0.1pt] (0,2) rectangle (0.2,4);
\node[tape, draw,right] at (0.32,3.55) {\vphantom{\large i}\hphantom{TEST}};
%\draw[xshift=0.25cm](0,4) -- (1,4) -- (2,3) -- (3,2) -- (2,2) -- (1,2) -- (0,2) -- (0,4)--cycle;
\end{tikzpicture}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% or%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{tikzpicture}[x=1.00mm, y=1.00mm, inner xsep=0pt, inner ysep=0pt, outer xsep=0pt, outer ysep=0pt]
\path[line width=0mm] (138.71,542.78) rectangle +(14.34,14.44);
\definecolor{L}{rgb}{0,0,0}
\path[line width=0.30mm, draw=L] (140.71,555.13) [rotate around={270:(140.71,555.13)}] rectangle +(10.35,1.73);
\path[line width=0.30mm, draw=L] (142.93,554.82);
\path[line width=0.30mm, draw=L] (142.98,549.72) .. controls (142.98,549.72) and (142.98,549.72) .. (142.98,549.72) .. controls (142.99,551.40) and (143.07,553.03) .. (143.01,554.75) .. controls (143.00,554.94) and (142.98,555.18) .. (143.11,555.20) .. controls (144.51,555.37) and (146.55,554.72) .. (147.61,553.60) .. controls (148.77,552.38) and (150.28,551.53) .. (150.87,552.64) .. controls (151.02,552.93) and (151.94,548.83) .. (147.57,549.33) .. controls (146.00,549.51) and (144.56,549.84) .. (142.98,549.72) -- cycle;
\path[line width=0.30mm, draw=L] (147.56,553.67) -- (147.53,549.33);
\end{tikzpicture}
\end{document}

在此处输入图片描述

第二个是用 TpX 绘制的。显示效果不是很好。也许像这里显示的标志一样tex.stackexchange.com就足够了。

在此处输入图片描述

我实际上只是在寻找一个可以缩放的旗帜的简洁表示。这面旗帜将像图标一样显示在我的讲义上,用于表示某些主题中的重要里程碑。

答案1

一面黑旗,但很容易改变形状或颜色

\documentclass[11pt]{scrartcl}
\usepackage{tikz}

\begin{document}
\begin{tikzpicture}

\begin{scope}[rotate=10]
    \begin{scope}[every path/.style={fill=black}]
        \draw (-.2,0) to [bend right] (.2,0) -- (.2,8) to [bend left] (-.2,8) -- cycle;
        \draw (0,8) circle (.4) ;
    \draw [rounded corners] (.2,7.6) to [out=60 ,in=180] (3,8) to [out=0, in = 200] (8,9) to [out=-85 ,in=85] (7.5,4) to [out=220,in=0](5,3) to [out=180,in=10] (.2,3) to [out =85,in=-80]  (.2,7.6) ; 
\end{scope}
\end{scope}  
\end{tikzpicture} 
\begin{tikzpicture}

\begin{scope}[rotate=10,scale=.5]
    \begin{scope}[every path/.style={shade, top color=black,bottom color=darkgray}]
        \draw (-.2,0) to [bend right] (.2,0) -- (.2,8) to [bend left] (-.2,8) -- cycle;
        \draw (0,8) circle (.4) ;
    \draw [rounded corners] (.2,7.6) to [out=60 ,in=180] (3,8) to [out=0, in = 200] (8,9) to [out=-85 ,in=85] (7.5,4) to [out=220,in=0](5,3) to [out=180,in=10] (.2,3) to [out =85,in=-80]  (.2,7.6) ; 
\end{scope}
\end{scope}  
\end{tikzpicture} 

\begin{tikzpicture}[scale=.5]

\begin{scope}[rotate=10]
    \begin{scope}[every path/.style={fill=black}]
        \draw (-.2,0) to [bend right] (.2,0) -- (.2,8) to [bend left] (-.2,8) -- cycle;
        \draw (0,8) circle (.4) ;
\end{scope}
\begin{scope}
\clip [rounded corners] (.2,7.6) to [out=60 ,in=180] coordinate[pos=.95] (h1) (3,8) to [out=0, in = 200]  coordinate[pos=.5] (h2) (8,9) coordinate(h3) to [out=-85 ,in=85] (7.5,4) coordinate(b3) to [out=220,in=0] coordinate[pos=.85] (b2)(5,3)  to [out=180,in=10]  coordinate[pos=.5] (b1)(.2,3) to [out =85,in=-80]  (.2,7.6) ;
\fill[blue] (-1,9) -- (h1) to[out=-85,in=80] (b1) -- (0,0) --cycle;     
\fill[red] (h2) to[out=-85,in=80] (b2) -- ++(0,-0.75) -- ([yshift=-1.25]b3) --(b3) to  [out=85 ,in=-85]  (h3) -- cycle  ; 
\end{scope} 
\draw[thick] [rounded corners] (.2,7.6) to [out=60 ,in=180] coordinate[pos=.95] (h1) (3,8) to [out=0, in = 200]  coordinate[pos=.5] (h2) (8,9) coordinate(h3) to [out=-85 ,in=85] (7.5,4) coordinate(b3) to [out=220,in=0] coordinate[pos=.85] (b2)(5,3)  to [out=180,in=10]  coordinate[pos=.5] (b1)(.2,3) to [out =85,in=-80]  (.2,7.6) ;      
\draw[thick]  (h1) to[out=-85,in=80] (b1); 
\draw[thick]  (h2) to[out=-85,in=80] (b2);  
\end{scope} 
\end{tikzpicture} 

\end{document}    

在此处输入图片描述

答案2

这个怎么样:

\documentclass[parskip]{scrartcl}
\usepackage[margin=15mm]{geometry}
\usepackage{tikz}

\pgfmathsetmacro{\flagscalefactor}{0.2}
\pgfmathsetmacro{\flagrotationdegree}{45}
\newcommand{\flagpolecolor}{brown!60!black}
\newcommand{\flagcolor}{yellow!67!red}
\newcommand{\flagsymbol}{:)}
\newcommand{\flagsymbolcolor}{black}

\newcommand{\tikzflag}{%
    \begin{scope}[scale=\flagscalefactor,rotate=\flagrotationdegree]
        \draw[fill=\flagpolecolor,thick] (0,0) -- ++ (0,8) arc (180:0:0.4 and 0.1) -- ++ (0,-8) arc (360:180:0.4 and 0.1);
        \draw[thick] (0,8) arc (180:360:0.4 and 0.1);
        \draw[fill=\flagcolor,thick] (0.8,7.5) to[out=-30,in=210] ++(3,0) to[out=30,in=150] ++ (3,0) -- ++ (0,-3) to [out=150,in=30] ++(-3,0) to[out=210,in=-30] ++(-3,0) -- cycle;
        \node[\flagsymbolcolor] at (3.8,6) {\textbf{\flagsymbol}};
    \end{scope}
}

\newcommand{\questionflag}{%
    \pgfmathsetmacro{\flagscalefactor}{0.2}
    \pgfmathsetmacro{\flagrotationdegree}{22.5}
    \renewcommand{\flagpolecolor}{brown!60!black}
    \renewcommand{\flagcolor}{yellow}
    \renewcommand{\flagsymbol}{?}
    \renewcommand{\flagsymbolcolor}{red}
    \tikzflag
}

\newcommand{\importantflag}{%
    \pgfmathsetmacro{\flagscalefactor}{0.2}
    \pgfmathsetmacro{\flagrotationdegree}{-22.5}
    \renewcommand{\flagpolecolor}{brown!60!black}
    \renewcommand{\flagcolor}{green!50!blue}
    \renewcommand{\flagsymbol}{!}
    \renewcommand{\flagsymbolcolor}{white}
    \tikzflag
}

\begin{document}

\begin{tikzpicture}
\tikzflag
\end{tikzpicture}

\begin{tikzpicture}
\questionflag
\end{tikzpicture}

\begin{tikzpicture}
\importantflag
\end{tikzpicture}

\end{document}

首先我创建了一个可以以多种方式更改的通用命令\tikzflag,然后我从中创建了一些专用命令。这样你就可以轻松地“标记”问题、难题、提示等。结果如下:

在此处输入图片描述


编辑1:这是一个更实用的实现。该\marker命令来自这里的一些问题,我不记得它起源于哪里。它用于定义标志应该去的位置。标志的名称应该是唯一的,否则标志可能会出现在之前的位置。由于这使用了选项overlay, remember picture,因此需要运行两次才能正常工作。

\documentclass[parskip]{scrartcl}
\usepackage[margin=20mm]{geometry}
\usepackage{tikz}
\usepackage{lipsum}
\usepackage{amsmath}
\usepackage{amssymb}

\newcommand{\marker}[2]{% name, shift
    \tikz[overlay,remember picture] 
        {\node (m-#1) at (#2) {};}%
}        

\pgfmathsetmacro{\flagscalefactor}{0.3}
\pgfmathsetmacro{\flagrotationdegree}{45}
\newcommand{\flagpolecolor}{brown!60!black}
\newcommand{\flagcolor}{yellow!67!red}
\newcommand{\flagsymbol}{:)}
\newcommand{\flagsymbolcolor}{black}
\newcommand{\flagadditionalcommands}{}

\newcommand{\tikzflag}[1][0,0]{% shift
    \begin{tikzpicture}[scale=\flagscalefactor,rotate=\flagrotationdegree,shift={(#1)},overlay,remember picture]
        \draw[fill=\flagpolecolor,thick] (0,0) -- ++ (0,8) arc (180:0:0.4 and 0.1) -- ++ (0,-8) arc (360:180:0.4 and 0.1);
        \draw[thick] (0,8) arc (180:360:0.4 and 0.1);
        \draw[fill=\flagcolor,thick] (0.8,7.5) to[out=-30,in=210] ++(3,0) to[out=30,in=150] ++ (3,0) -- ++ (0,-4.5) to [out=150,in=30] ++(-3,0) to[out=210,in=-30] ++(-3,0) -- cycle;
        \node[\flagsymbolcolor,fill=white,circle,thick,inner sep=1pt,draw,thin] (a) at (3.8,5.25) {\textbf{\flagsymbol}};
        \flagadditionalcommands
    \end{tikzpicture}
}

\newcommand{\questionflag}[1]{% name
    \pgfmathsetmacro{\flagscalefactor}{0.1}
    \pgfmathsetmacro{\flagrotationdegree}{22.5}
    \renewcommand{\flagpolecolor}{brown!60!black}
    \renewcommand{\flagcolor}{yellow}
    \renewcommand{\flagsymbol}{\tiny ?}
    \renewcommand{\flagsymbolcolor}{black}
    \marker{#1}{-0.8,-0.8}
    \tikzflag[m-#1]
}

\newcommand{\importantflag}[1]{% name
    \pgfmathsetmacro{\flagscalefactor}{0.1}
    \pgfmathsetmacro{\flagrotationdegree}{-22.5}
    \renewcommand{\flagpolecolor}{brown!60!black}
    \renewcommand{\flagcolor}{red!50!orange}
    \renewcommand{\flagsymbol}{\tiny !}
    \renewcommand{\flagsymbolcolor}{black}
    \marker{#1}{-1.1,-0.6}
    \tikzflag[m-#1]
}

\newcommand{\hintflag}[1]{% name
    \pgfmathsetmacro{\flagscalefactor}{0.1}
    \pgfmathsetmacro{\flagrotationdegree}{0}
    \renewcommand{\flagpolecolor}{brown!60!black}
    \renewcommand{\flagcolor}{blue!50!cyan}
    \renewcommand{\flagsymbol}{\tiny $\blacktriangledown$}
    \renewcommand{\flagsymbolcolor}{black}
    \marker{#1}{-0.9,-0.6}
    \tikzflag[m-#1]
}

\begin{document}

\questionflag{first}\lipsum[1]

\hintflag{firstmath}\[ \int\limits_0^11dx=1 \]

\importantflag{second}\lipsum[2]

\importantflag{secondmath}
\begin{align*}
    0 &= x^2 +px +q\\
    x_{_{1/2}}   &= -\frac{p}{2} \pm \sqrt{\left(\frac{p}{2}\right)^2-q}
\end{align*}

\hintflag{third}\lipsum[43]

\questionflag{firstpicture} \\ \includegraphics[scale=7]{avatar}

\end{document}

在此处输入图片描述

相关内容