Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I am trying to create a flag in TikZ but aesthetically it's not the best. Here is my 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}

enter image description here

The second is drawn with TpX. The display are not the best. Maybe a flag like the one shown here in tex.stackexchange.com would suffice.

enter image description here

I am really just looking for a neat representation of a flag which I can scale. This flag will be displayed like an icon on my Lecture Notes for important milestones in certain topics.

share|improve this question
1  
The TikZ/PSTricks based bclogo package has a lot of cliparts for this kind of purposes. You might modify any flags if the country is not available or you have your own country in mind :) Your French might be better than my TikZsh (?!). –  percusse May 28 '12 at 20:43
1  
Any reason it has to be in TikZ? You can find lots of flags on openclipart.org, download SVG, open in inkscape, edit, save as PDF. –  Matthew Leingang May 29 '12 at 16:12
    
There's also \Flag and \VarFlag from the ifsym package. Yet another source of flag icons is The Noun Project, which has seven different flags. –  doncherry May 29 '12 at 20:51
    
@MatthewLeingang I just love TikZ, :-). It can be in Pstricks too. –  azetina May 29 '12 at 21:46
    
@doncherry Can use freely and edit the documents at the site you shared? The ideas are great. –  azetina May 29 '12 at 22:06

2 Answers 2

A black flag but it's easy to change the form or the colors

\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}    

enter image description here

share|improve this answer
    
Very pretty and sober drawing. –  projetmbc May 28 '12 at 21:15
1  
@azetina I added a flag with color because its not very easy to add color with this kind of flag –  Alain Matthes May 29 '12 at 17:10
    
Very much appreciated. I will study what you have and learn a bit more on the curved paths. –  azetina May 30 '12 at 14:49

How about this:

\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}

Firt I made a general command \tikzflag that can be altered in several ways, then I made some specialized commands from it. Like that you can easily 'flag' questions, problems, hints etc. Here's the result:

enter image description here


Edit 1: Here is a more usable implementation. The \marker command is from some question around here, I don't recall were it originated from. It is used to define the positions the flags should go to. The names of the flags should be unique, otherwise a flag might end up at a previous position. As this uses the overlay, remember picture option, it will take two runs to work properly.

\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}

enter image description here

share|improve this answer
    
Nice....Outstanding results. I just didn't get the understanding of the curved paths. Am getting their though. –  azetina May 30 '12 at 14:48
    
The to operation will draw a possibly curved line between two points. If you specify a plain to it will draw a sraight line (like --). If you specify in=degrees or out=degrees the line will enter or leave the points at that angle. Via looseness you can specify how 'narrow' the curve will be, which is illustrated here –  Tom Bombadil May 30 '12 at 15:18
    
The official name is \tikzmark for that ;) –  percusse Jun 24 '12 at 10:49

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.