在 LaTeX Tikz 中绘制一面旗帜

在 LaTeX Tikz 中绘制一面旗帜

这是我的代码:

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

我不知道为什么它没有按照我的要求运行。希望有人能帮忙?

雷根博根旗帜

亲切的问候!

答案1

一些评论:

  1. xcolor已加载tikz,因此无需再次重新加载,
  2. 在颜色数字中使用大写字母,
  3. 最后一个矩形与前一个矩形重叠,
  4. 您可以使用使其更短foreach

以下是代码:

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

在此处输入图片描述

答案2

先前的颜色被下一个更大的矩形覆盖,也许你想要类似这样的颜色:

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

结果

xcolor2007/02/21 v2.11备注

此版本有一个错误,导致小写字母f在颜色模型的值中不起作用HTML

解决方法:

  • 使用大写字母。例如:\definecolor{gelb}{HTML}{FFEE00}
  • 包加载后,需要修补xcolor宏,将小写的十六进制数字转换为大写的十六进制数字,以满足 TeX 带双引号的十六进制语法的要求:\@hex@@Hex

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

答案3

如果你想让国旗飘扬……

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

飞翔的骄傲

或者,更简洁地使用\foreach循环:

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

稍微调整高度:

fflag 骄傲 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}

相关内容