10

Here is my code:

\documentclass[tikz]{standalone}
\usetikzlibrary{shapes,snakes}
\usepackage[html]{xcolor} 

\definecolor{rot}{HTML}{e40303}
\definecolor{xorange}{HTML}{ff8c00}
\definecolor{gelb}{HTML}{ffed00}
\definecolor{gruen}{HTML}{008026}
\definecolor{blau}{HTML}{004dff}
\definecolor{lilla}{HTML}{750787}


\begin{document}


\begin{tikzpicture}[x=0.026458cm,y=0.026458cm]
\fill[fill=rot](0,0)rectangle(750,70);
\fill[fill=xorange](0,0)rectangle(750,140);
\fill[fill=gelb](0,0)rectangle(750,210);
\fill[fill=gruen](0,0)rectangle(750,280);
\fill[fill=blau](0,0)rectangle(750,350);
\fill[fill=lilla](0,0)rectangle(750,420);
\end{tikzpicture}

\end{document}

I don't know why it doesn't do what I wanted it to do. Hopefully some of you can help?

Regenbogenflagge

Kind regards!

5
  • 4
    Could you please detail more what you wanted to do? At least to me, it is not clear at all. Jun 28, 2015 at 19:11
  • 3
    I think we should properly ask this question as Drawing the gay pride flag. By the way it is also already in the TikZ manual. Search for pride
    – percusse
    Jun 28, 2015 at 20:03
  • @percusse to clarify, a gradient version is included in the current manual. this is stepwise. Jun 28, 2015 at 20:06
  • If you want to preserve the original golden ratio of the rainbow flag, you should use 77 in place of 70 as rectangle height.
    – Kpym
    Jun 28, 2015 at 20:13
  • @SeanAllred It is not a country flag. You can spot rainbow everywhere.
    – percusse
    Jun 28, 2015 at 20:48

3 Answers 3

10

Some comments :

  1. xcolor is loaded by tikz, so don't reload it again,
  2. use capitals in color numbers,
  3. your last rectangle overlap the previous ones,
  4. you can make it shorter using foreach.

Here is the code :

\documentclass[tikz]{standalone}

\definecolor{rot}{HTML}{E40303}
\definecolor{xorange}{HTML}{FF8C00}
\definecolor{gelb}{HTML}{FFED00}
\definecolor{gruen}{HTML}{008026}
\definecolor{blau}{HTML}{004DFF}
\definecolor{lilla}{HTML}{750787}

\begin{document}
  \begin{tikzpicture}[x=0.026458cm,y=0.026458cm]
    \foreach[count=\i] \col in {lilla,blau,gruen,gelb,xorange,rot}
      \fill[\col] (0,70*\i) rectangle +(750,70);
  \end{tikzpicture}
\end{document}

enter image description here

7
  • 2
    Let's go :) \tikz\foreach[count=\i]~in{E40303,FF8C00,FFED00,008026,004DFF,750787}\definecolor{temp}{HTML}{~}\fill[temp](0,70*\i pt)rectangle+(750 pt,70 pt);
    – percusse
    Jun 28, 2015 at 20:00
  • 1
    @percusse \tikz\foreach[count=\i]~in{E40303,FF8C00,FFED00,008026,004DFF,750787}\definecolor{t}{HTML}{~}\fill[t]rectangle(750pt,70*(7-\i pt);, your turn ;)
    – Kpym
    Jun 28, 2015 at 20:10
  • @Kpym what does the "(0,70*\i) " make? Jun 28, 2015 at 21:50
  • @Dr.HenrietteB.Fröhlich The (0,70*\i) sets the starting coordinate for each bar of the flag starting at the bottom: (0,70) then (0,140), then (0,210) etc.
    – Alan Munn
    Jun 28, 2015 at 23:25
  • 1
    OK I give you golden ratio then :P \tikz\foreach[count=\i]~in{E40303,FF8C00,FFED00,008026,004DFF,750787}\definecolor t{HTML}~\fill[t](0,\i)|-(15,\i+1.545)|-(0,\i); ... Aargh I gave away the trophy haha I should have thought about it anyway let's see if you can find it :)
    – percusse
    Jul 12, 2015 at 14:33
9

The previous color is overwritten by the next larger rectangle, probably you want something like:

\documentclass[tikz]{standalone}

\definecolor{lila}{HTML}{8800bb}
\definecolor{blau}{HTML}{0000FF}
\definecolor{hellblau}{HTML}{88bbdd}
\definecolor{gruen}{HTML}{66bb44}   
\definecolor{gelb}{HTML}{FFee00} 
\definecolor{orange}{HTML}{FF4411}
\definecolor{rot}{HTML}{FF1100}   

\begin{document}

\begin{tikzpicture}[x=0.026458cm,y=0.026458cm]
\fill[fill=lila](0,0)rectangle(750,70);
\fill[fill=blau](0,70)rectangle(750,140);
\fill[fill=hellblau](0,140)rectangle(750,210);
\fill[fill=gruen](0,210)rectangle(750,280);   
\fill[fill=gelb](0,280)rectangle(750,350);    
\fill[fill=orange](0,350)rectangle(750,420);
\fill[fill=rot](0,420)rectangle(750,490);   
\end{tikzpicture}

\end{document}

Result

Remark for xcolor 2007/02/21 v2.11

This version has a bug with the effect that the lowercase f does not work inside the values for the color model HTML.

Workarounds:

  • Using uppercase letters. Example: \definecolor{gelb}{HTML}{FFEE00}
  • After package xcolor is loaded, the macro \@hex@@Hex needs to be patched, which converts lowercase hex digits to uppercase hex digits, needed for TeX's hex syntax with the double quote:

    \usepackage{etoolbox}
    \makeatletter
    \patchcmd\@hex@@Hex{f\else}{F\else}{}{}
    \makeatother
    
0
6

In case you would like the flag to fly...

\documentclass[tikz, border=5pt]{standalone}
\usetikzlibrary{shapes.symbols,positioning}

\definecolor{rot}{HTML}{e40303}
\definecolor{xorange}{HTML}{FF8c00}
\definecolor{gelb}{HTML}{FFed00}
\definecolor{gruen}{HTML}{008026}
\definecolor{blau}{HTML}{004dFF}
\definecolor{lilla}{HTML}{750787}

\begin{document}

\begin{tikzpicture}[x=0.026458cm, y=0.026458cm, tape bend height=20, shape=tape, text width=750, minimum height=70, inner sep=0pt, node distance=-1pt]
  \node (rot) [fill=rot] {};
  \node (oren) [fill=xorange, below=of rot] {};
  \node (melyn) [fill=gelb, below=of oren] {};
  \node (gwyrdd) [fill=gruen, below=of melyn] {};
  \node (glas) [fill=blau, below=of gwyrdd] {};
  \node [fill=lilla, below=of glas] {};
\end{tikzpicture}

\end{document}

flying pride

Or, more concisely using a \foreach loop:

\documentclass[tikz, border=5pt]{standalone}
\usetikzlibrary{shapes.symbols,positioning}

\definecolor{rot}{HTML}{e40303}
\definecolor{xorange}{HTML}{FF8c00}
\definecolor{gelb}{HTML}{FFed00}
\definecolor{gruen}{HTML}{008026}
\definecolor{blau}{HTML}{004dFF}
\definecolor{lilla}{HTML}{750787}

\begin{document}

\begin{tikzpicture}[x=0.026458cm, y=0.026458cm, tape bend height=20, shape=tape, text width=750, minimum height=70, inner sep=0pt, node distance=-1pt]
  \node (rot) [fill=rot] {};
  \foreach \i [remember=\i as \j (initially rot)] in {xorange,gelb,gruen,blau,lilla}
  \node (\i) [fill=\i, below=of \j] {};
\end{tikzpicture}

\end{document}

Adjusting the height a little:

fflag pride 2

\documentclass[tikz, border=5pt]{standalone}
\usetikzlibrary{shapes.symbols,positioning}

\definecolor{rot}{HTML}{e40303}
\definecolor{xorange}{HTML}{FF8c00}
\definecolor{gelb}{HTML}{FFed00}
\definecolor{gruen}{HTML}{008026}
\definecolor{blau}{HTML}{004dFF}
\definecolor{lilla}{HTML}{750787}

\begin{document}

\begin{tikzpicture}[x=0.026458cm, y=0.026458cm, tape bend height=20, shape=tape, minimum width=750, minimum height=100, inner sep=0pt, node distance=-1pt]
  \node (rot) [fill=rot] {};
  \node (oren) [fill=xorange, below=of rot] {};
  \node (melyn) [fill=gelb, below=of oren] {};
  \node (gwyrdd) [fill=gruen, below=of melyn] {};
  \node (glas) [fill=blau, below=of gwyrdd] {};
  \node [fill=lilla, below=of glas] {};
\end{tikzpicture}

\end{document}
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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