How to Draw the Cards of a Deck?

tikz-pgf

How to draw the cards from a deck using a Latex package, as TikZ?enter image description here

Best Answer

Here is a solution using SVG-Cards, inkscape and PDFLaTEX/graphicx/TikZ.

I provide a Makefile :

  • to download and to extract the SVG-Cards archive (via wget and tar),

  • to extract each SVG card from svg-cards.svg (via inkscape)

  • to convert each SVG card into a PDF card (via inkscape)

  • to compile cards.tex (via pdflatex)

Steps:

  1. Copy the Makefile (note: the white spaces at beginning of lines are tabulations) and the cards.tex below.

  2. Run make to get cards.pdf

Note: if you can't use this Makefile, I provide cards.tgz. This archive contains all extracted PDF cards (needed to compile cards.tex).

enter image description here

The Makefile:

JOKERS = black_joker red_joker
LEVELS = 1 2 3 4 5 6 7 8 9 10 jack queen king
CLUBS = ${LEVELS:%=%_club}
DIAMONDS = ${LEVELS:%=%_diamond}
HEARTS = ${LEVELS:%=%_heart}
SPADES = ${LEVELS:%=%_spade}
CARDS = ${CLUBS} ${DIAMONDS} ${HEARTS} ${SPADES} ${JOKERS}
CARDS_PDF = ${CARDS:%=card-%.pdf}

all: cards.pdf

cards.pdf: cards.tex $(CARDS_PDF)
    latexmk -pdf cards.tex

card-%.pdf: card-%.svg
    inkscape --export-pdf=$@ $<

card-%.svg: SVG-cards-2.0.1/svg-cards.svg
    inkscape --export-plain-svg=$@ --export-id=${@:card-%.svg=%} --export-id-only $<

SVG-cards-2.0.1/svg-cards.svg:
    wget http://sourceforge.net/projects/svg-cards/files/SVG-cards-2.0.1.tar.gz
    tar zxvf SVG-cards-2.0.1.tar.gz

The cards.tex file:

\documentclass[tikz]{standalone}
\begin{document}
\begin{tikzpicture}
  \foreach \col[count=\c] in {spade,heart,diamond,club}{
    \begin{scope}[shift={(\c*90:1.5cm)}]
      \foreach \level[count=\val] in {1,...,10,jack,queen,king}{
        \node[inner sep=0,anchor=south,rotate={40-(\val*6)}]
        at ({140-(\val*6)}:1cm)
        {\includegraphics[height=1cm]{card-\level_\col}};
      }    
    \end{scope}
  }
  \node at (-2,0) {\includegraphics[height=1cm]{card-red_joker}};
  \node at (2,0)  {\includegraphics[height=1cm]{card-black_joker}};
\end{tikzpicture}
\end{document}
Related Question