[Tex/LaTex] Draw a coat of arms in LaTeX

diagramsfun

Over at academia.sx we are trying to create a community ad to try and get us promoted out of beta. We are looking to create a university type coat of arms/seal. I have seen some really great artwork on tex.sx, so I thought I would ask …

Best Answer

Disclaimer

This should be considered as a start of an answer.


Actually this could be seen an answer to the title of the question, Draw a coat of arms in LaTeX, rather than an answer to what is really asked in the question: university type coat of arms/seal. Indeed, when I saw the title I thought that with TikZ should be possible to provide a way to draw heraldic shields; perhaps not those ones very complicated, but at least the simpler ones.

The reference took is: http://simple.wikipedia.org/wiki/Heraldry; notice that in heraldry colors should be respect rules (and execptions) as per http://en.wikipedia.org/wiki/Rule_of_tincture, but for the moment I did not considered them.

Technically speaking, this is the first time I created a custom pgf shape, thus the reference shape could (I'd say must) be improved. Another thing to be improved is how the cross lines join the border of the shield.

The code:

% version 1/12/2012 with clipping

\documentclass[svgnames]{article}
\usepackage{tikz}
\usetikzlibrary{calc, backgrounds}

\makeatletter    

\pgfkeys{/tikz/.cd,
  corner radius/.initial=1.5075cm,
  height shield/.initial=2.25cm,
  minimum width=3cm,
  minimum height=1.5cm,
}


\pgfdeclareshape{heraldic shield}{% taken and modified from page 631 of the manual
  \inheritsavedanchors[from=rectangle] %  this is nearly a rectangle
  \inheritanchorborder[from=rectangle]
  \inheritanchor[from=rectangle]{center}
  \inheritanchor[from=rectangle]{north}
  \inheritanchor[from=rectangle]{north west}
  \inheritanchor[from=rectangle]{north east}
  \inheritanchor[from=rectangle]{south}
  \inheritanchor[from=rectangle]{south west}
  \inheritanchor[from=rectangle]{south east}
  \inheritanchor[from=rectangle]{west}
  \inheritanchor[from=rectangle]{east}

   \savedmacro\cornerradius{%
    \edef\cornerradius{\pgfkeysvalueof{/tikz/corner radius}}%
  }

   \savedmacro\heightshield{%
    \edef\heightshield{\pgfkeysvalueof{/tikz/height shield}}%
  }

  \savedmacro\posarc{%
    \edef\posarc{1.75cm*\heightshield}%
  }

  \backgroundpath{%  this is new
    %  store lower right in xa/ya and upper right in xb/yb
    \southwest \pgf@xa=\pgf@x \pgf@ya=\pgf@y
    \northeast \pgf@xb=\pgf@x \pgf@yb=\pgf@y
    %  construct main path
    \pgfpathmoveto{\pgfpoint{\pgf@xa}{\pgf@ya}}
    \pgfpathlineto{\pgfpoint{\pgf@xa}{\pgf@yb}}
    \pgfpathlineto{\pgfpoint{\pgf@xb}{\pgf@yb}}
    \pgfpathlineto{\pgfpoint{\pgf@xb}{\pgf@ya}}
     \pgfpatharc{360}{270}{\cornerradius}%
     \pgfpatharc{270}{180}{\cornerradius}%
     \pgfpathlineto{\pgfpoint{\pgf@xa}{\pgf@ya}}
    \pgfpathclose
 }

  \savedanchor{\bottom}{
    \pgf@y=-\heightshield%
    \pgf@x=0cm %
    }

    \savedanchor{\arcleft}{
    \pgf@y=-\posarc%
    \pgf@x=0.9cm %
    }
    \savedanchor{\arcright}{
    \pgf@y=-\posarc%
    \pgf@x=-0.9cm %
    }
 \anchor{bottom}{\bottom}
 \anchor{arc left}{\arcleft}
 \anchor{arc right}{\arcright}
}
\makeatother


\tikzset{pale/.style={
        heraldic shield,    
        draw=black,
        line width=0.4pt,
        append after command={
            \pgfextra{
                \begin{pgfinterruptpath}
                \begin{scope}
                    [local bounding box=bb] \node [heraldic shield]{};
                \end{scope}
                \begin{pgfonlayer}{background}
                \pgfnode{heraldic shield}{center}{}{nodename}{\pgfusepath{stroke,clip}}
                \draw[#1, line width=15pt,line cap=rect](\tikzlastnode.north)--(\tikzlastnode.bottom);
                \end{pgfonlayer}
                \pgfresetboundingbox
                \useasboundingbox (bb.south west) rectangle  (bb.north east);
                \end{pgfinterruptpath}
             }
        }    
    },
    fess/.style={
        heraldic shield,
        draw=black,
        line width=0.4pt,
        append after command={
            \pgfextra{
                \begin{pgfinterruptpath}
                \begin{scope}
                    [local bounding box=bb] \node [heraldic shield]{};
                \end{scope}
                \begin{pgfonlayer}{background}
                \pgfnode{heraldic shield}{center}{}{nodename}{\pgfusepath{stroke,clip}}
                \draw[#1, line width=15pt](\tikzlastnode.south west)--(\tikzlastnode.south east);
                \end{pgfonlayer}
                \pgfresetboundingbox
                \useasboundingbox (bb.south west) rectangle  (bb.north east);
                \end{pgfinterruptpath}
             }
        }
    }   
}

\tikzset{bend/.style={
        heraldic shield,        
        draw=black,
        line width=0.4pt,
        append after command={
            \pgfextra{
                \begin{pgfinterruptpath}
                \begin{scope}
                    [local bounding box=bb]  \node  [heraldic shield]{};
                \end{scope}
                \begin{pgfonlayer}{background}
                \pgfnode{heraldic shield}{center}{}{nodename}{\pgfusepath{stroke,clip}}
                \draw[#1, line width=10pt,line cap=rect](\tikzlastnode.north west)--(\tikzlastnode.arc left);
                \end{pgfonlayer}
                \pgfresetboundingbox
                \useasboundingbox (bb.south west) rectangle  (bb.north east);
                \end{pgfinterruptpath}              
             }
        }    
    },
    bend right/.style={
        heraldic shield,        
        draw=black,
        line width=0.4pt,
        append after command={
            \pgfextra{
                \begin{pgfinterruptpath}
                \begin{scope}
                    [local bounding box=bb]  \node  [heraldic shield]{}; 
                \end{scope}
                \begin{pgfonlayer}{background}
                \pgfnode{heraldic shield}{center}{}{nodename}{\pgfusepath{stroke,clip}}
                \draw[#1, line width=10pt,line cap=rect](\tikzlastnode.north east)--(\tikzlastnode.arc right);
                \end{pgfonlayer}
                \pgfresetboundingbox
                \useasboundingbox (bb.south west) rectangle  (bb.north east);
                \end{pgfinterruptpath}
             }
        }    
    },
}
\tikzset{chief/.style={
        heraldic shield,        
        draw=black,
        line width=0.4pt,
        append after command={
            \pgfextra{
                \begin{pgfinterruptpath}
                \begin{scope}
                    [local bounding box=bb]  \node  [heraldic shield]{}; 
                \end{scope}
                \begin{pgfonlayer}{background}
                \pgfnode{heraldic shield}{center}{}{nodename}{\pgfusepath{stroke,clip}}
                \fill[#1](\tikzlastnode.west)--(\tikzlastnode.north west)--(\tikzlastnode.north east)--(\tikzlastnode.east)--cycle;
                \end{pgfonlayer}
                \pgfresetboundingbox
                \useasboundingbox (bb.south west) rectangle  (bb.north east);
                \end{pgfinterruptpath}
             }
        }    
    },
    cross/.style={
        heraldic shield,        
        draw=black,
        line width=0.4pt,
        append after command={
            \pgfextra{
                \begin{pgfinterruptpath}
                \begin{scope}
                    [local bounding box=bb]  \node  [heraldic shield]{}; 
                \end{scope}
                \begin{pgfonlayer}{background}
                \pgfnode{heraldic shield}{center}{}{nodename}{\pgfusepath{stroke,clip}}             
                \draw[#1, line width=15pt,line cap=rect](\tikzlastnode.north)--(\tikzlastnode.bottom);
                \draw[#1, line width=15pt,line cap=rect](\tikzlastnode.south west)--(\tikzlastnode.south east);
                \end{pgfonlayer}
                \pgfresetboundingbox
                \useasboundingbox (bb.south west) rectangle  (bb.north east);
                \end{pgfinterruptpath}
             }
        }    
    },
    pile/.style={
        heraldic shield,        
        draw=black,
        line width=0.4pt,
        append after command={
            \pgfextra{
                \begin{pgfinterruptpath}
                \begin{scope}
                    [local bounding box=bb]  \node  [heraldic shield]{}; 
                \end{scope}
                \begin{pgfonlayer}{background}
                \pgfnode{heraldic shield}{center}{}{nodename}{\pgfusepath{stroke,clip}}
                \filldraw[#1,line cap=rect]($(\tikzlastnode.north west)!0.5!(\tikzlastnode.north)$)--($(\tikzlastnode.north east)!0.5!(\tikzlastnode.north)$)--(\tikzlastnode.bottom)--cycle;
                \end{pgfonlayer}
                \pgfresetboundingbox
                \useasboundingbox (bb.south west) rectangle  (bb.north east);
                \end{pgfinterruptpath}
             }
        }    
    },
}
\tikzset{party per fess/.style args={superior color #1 and inferior color #2}{
        heraldic shield,        
        draw=black,
        line width=0.4pt,
        append after command={
            \pgfextra{
                \begin{pgfinterruptpath}
                \begin{scope}
                    [local bounding box=bb]  \node  [heraldic shield]{}; 
                \end{scope}
                \begin{pgfonlayer}{background}
                \pgfnode{heraldic shield}{center}{}{nodename}{\pgfusepath{stroke,clip}}
                \fill[#1](\tikzlastnode.west)--(\tikzlastnode.north west)--(\tikzlastnode.north east)--(\tikzlastnode.east)--cycle;
                \fill[#2]($(\tikzlastnode.south west)!0.5!(\tikzlastnode.west)$)-- (\tikzlastnode.south west)arc(180:270:\pgfkeysvalueof{/tikz/corner radius}) arc(270:360:\pgfkeysvalueof{/tikz/corner radius})--(\tikzlastnode.south east) --($(\tikzlastnode.south east)!0.5!(\tikzlastnode.east)$) --cycle;
                \end{pgfonlayer}
                \pgfresetboundingbox
                \useasboundingbox (bb.south west) rectangle  (bb.north east);
                \end{pgfinterruptpath}
             }
        }    
    },
    party per pale/.style args={left color #1 and right color #2}{
        heraldic shield,        
        draw=black,
        line width=0.4pt,
        append after command={
            \pgfextra{
                \begin{pgfinterruptpath}
                \begin{scope}
                    [local bounding box=bb]  \node  [heraldic shield]{}; 
                \end{scope}
                \begin{pgfonlayer}{background}
                \pgfnode{heraldic shield}{center}{}{nodename}{\pgfusepath{stroke,clip}}
                \fill[#1] (\tikzlastnode.north)--(\tikzlastnode.north west)--(\tikzlastnode.south west)arc(180:270:\pgfkeysvalueof{/tikz/corner radius})--cycle;
                \fill[#2] (\tikzlastnode.north)--(\tikzlastnode.north east)--(\tikzlastnode.south east)arc(360:270:\pgfkeysvalueof{/tikz/corner radius})--cycle;
                \end{pgfonlayer}
                \pgfresetboundingbox
                \useasboundingbox (bb.south west) rectangle  (bb.north east);
                \end{pgfinterruptpath}
             }
        }    
    },
}   

\newcommand{\army}[2]{
\tikz[baseline=-0.5ex,remember picture]\node[#1=#2] (x) {};
\tikz[baseline=-0.5ex,remember picture,overlay]\node[font=\Large,yshift=0.5cm] at (x.north){#1};
\hspace{1cm}
}

\begin{document}
\noindent
\army{fess}{red}
\army{pale}{blue}
\army{bend}{Purple}\\[7ex]
\army{bend right}{red}
\army{chief}{Green}
\army{cross}{Gold}\\[7ex]
\army{pile}{Silver}
\army{party per fess}{superior color white and inferior color blue}
\army{party per pale}{left color Silver and right color Green}
\end{document}

The result:

enter image description here


An example with the famous duck by Paulo:

\documentclass[svgnames]{article}
\usepackage{tikz}
\usetikzlibrary{calc, backgrounds}
\input{pc-duck} 
% tikz and colors of the duck from
% http://tex.stackexchange.com/questions/63732/cute-document-in-latex/63759#63759
\makeatletter    

\pgfkeys{/tikz/.cd,
  corner radius/.initial=1.5075cm,
  height shield/.initial=2.25cm,
  minimum width=3cm,
  minimum height=1.5cm,
}


\pgfdeclareshape{heraldic shield}{% taken and modified from page 631 of the manual
  \inheritsavedanchors[from=rectangle] %  this is nearly a rectangle
  \inheritanchorborder[from=rectangle]
  \inheritanchor[from=rectangle]{center}
  \inheritanchor[from=rectangle]{north}
  \inheritanchor[from=rectangle]{north west}
  \inheritanchor[from=rectangle]{north east}
  \inheritanchor[from=rectangle]{south}
  \inheritanchor[from=rectangle]{south west}
  \inheritanchor[from=rectangle]{south east}
  \inheritanchor[from=rectangle]{west}
  \inheritanchor[from=rectangle]{east}

   \savedmacro\cornerradius{%
    \edef\cornerradius{\pgfkeysvalueof{/tikz/corner radius}}%
  }

   \savedmacro\heightshield{%
    \edef\heightshield{\pgfkeysvalueof{/tikz/height shield}}%
  }

  \savedmacro\posarc{%
    \edef\posarc{1.75cm*\heightshield}%
  }


  %  ... and possibly more
  \backgroundpath{%  this is new
    %  store lower right in xa/ya and upper right in xb/yb
    \southwest \pgf@xa=\pgf@x \pgf@ya=\pgf@y
    \northeast \pgf@xb=\pgf@x \pgf@yb=\pgf@y
    %  construct main path
    \pgfpathmoveto{\pgfpoint{\pgf@xa}{\pgf@ya}}
    \pgfpathlineto{\pgfpoint{\pgf@xa}{\pgf@yb}}
    \pgfpathlineto{\pgfpoint{\pgf@xb}{\pgf@yb}}
    \pgfpathlineto{\pgfpoint{\pgf@xb}{\pgf@ya}}
     \pgfpatharc{360}{270}{\cornerradius}%
     \pgfpatharc{270}{180}{\cornerradius}%
     \pgfpathlineto{\pgfpoint{\pgf@xa}{\pgf@ya}}
    \pgfpathclose
 }

  \savedanchor{\bottom}{
    \pgf@y=-\heightshield%
    \pgf@x=0cm %
    }

    \savedanchor{\arcleft}{
    \pgf@y=-\posarc%
    \pgf@x=0.9cm %
    }
    \savedanchor{\arcright}{
    \pgf@y=-\posarc%
    \pgf@x=-0.9cm %
    }
 \anchor{bottom}{\bottom}
 \anchor{arc left}{\arcleft}
 \anchor{arc right}{\arcright}
}
\makeatother
\def\duckinarm{\resizebox{5.5em}{!}{\drawduck}}

\tikzset{party per fess with traversing duck/.style args={superior color #1 and inferior color #2}{
        heraldic shield,        
        draw=black,
        line width=0.4pt,
        append after command={
            \pgfextra{
                \begin{pgfinterruptpath}
                \node[above=5ex] at ([xshift=0.25em]\tikzlastnode.bottom) {\duckinarm};
                \begin{pgfonlayer}{background}
                \fill[#1](\tikzlastnode.west)--(\tikzlastnode.north west)--(\tikzlastnode.north east)--(\tikzlastnode.east)--cycle;
                \fill[#2]($(\tikzlastnode.south west)!0.5!(\tikzlastnode.west)$)-- (\tikzlastnode.south west)arc(180:270:\pgfkeysvalueof{/tikz/corner radius}) arc(270:360:\pgfkeysvalueof{/tikz/corner radius})--(\tikzlastnode.south east) --($(\tikzlastnode.south east)!0.5!(\tikzlastnode.east)$) --cycle;
                \end{pgfonlayer}
                \end{pgfinterruptpath}
             }
        }    
    }
}   

\newcommand{\army}[2]{
\tikz[baseline=-0.5ex]\node[#1=#2, label={[label distance=0.1cm,font=\Large]90:#1}] {};
}
\begin{document}
\army{party per fess with traversing duck}{superior color white and inferior color blue}
\end{document}

Result:

enter image description here