扑克牌的典型尺寸是6 x 9 = width x height
,所以我选择值
\pgfmathsetlengthmacro\w{<card width>}% card width
\pgfmathsetlengthmacro\h{9*\w/6}% card height
为一个“cardground”矩形节点。
但是,如何确保文本(例如A
)$\heartsuit$
能够很好地适合卡片节点?
也许有规模?
在下面的 MWE 中,我设置了命令\cardsymbol
,\cardcolor
允许语法
\crd{A}{h}
或共同\crd{<card value A,1-10,J,Q,K>}{<card color s,h,d,c>}
\documentclass[]{article}
\usepackage{tikz}
\begin{document}
% Card-Style =============================
\definecolor{spadecolor}{HTML}{020202}% myblack % spade - Pik
\definecolor{heartcolor}{HTML}{C70002}% myred % heart - Herz
\definecolor{diamondcolor}{HTML}{687CF5}% myblue % diamond - Karo
\definecolor{clubcolor}{HTML}{3B7801}% mygreen % club - Kreuz
\colorlet{cardbackcolor}{purple}% card back
\colorlet{cardplaincolor}{black}% empty card
\colorlet{jokercolor}{violet}% joker
%
\newcommand\cardsymbol[1]{%
\ifnum\pdfstrcmp{#1}{s}=0 $\spadesuit$%
\else \ifnum\pdfstrcmp{#1}{h}=0 $\heartsuit$%
\else \ifnum\pdfstrcmp{#1}{d}=0 $\diamondsuit$%
\else \ifnum\pdfstrcmp{#1}{c}=0 $\clubsuit$%
\fi\fi\fi\fi}
%
\newcommand\cardcolor[1]{%
\ifnum\pdfstrcmp{#1}{s}=0 spadecolor%
\else \ifnum\pdfstrcmp{#1}{h}=0 heartcolor%
\else \ifnum\pdfstrcmp{#1}{d}=0 diamondcolor%
\else \ifnum\pdfstrcmp{#1}{c}=0 clubcolor%
\fi\fi\fi\fi}
% ================================
% Card-Sizes (default)=======================
\pgfmathsetlengthmacro\w{1.2em}% card width
\pgfmathsetlengthmacro\h{9*\w/6}% card height
% ================================
% \crd[<TikZ adds>]{<card value A,1-10,J,Q,K>}{<card color s,h,d,c>}
\newcommand\crd[3][]{%
\begin{tikzpicture}[font=\sffamily,
cardtext/.style={inner sep=0pt, inner ysep=0.045*\h},
cardground/.style={minimum width=\w, minimum height=\h,
draw, rounded corners=0.075*\w},
]
\node(temp)[cardground,
label={[cardtext, anchor=north, text=\cardcolor{#3}]north:#2},
label={[cardtext, anchor=south, text=\cardcolor{#3}]south:\cardsymbol{#3}},
#1]{};
\end{tikzpicture}}
\section{Let's try the default}
I choose the cards \crd{K}{c}, \crd{A}{h}, \crd{Q}{d}, \crd{7}{s}.
(Dimensions could be better...)
\section{Now a huge card}
% Card-Sizes =============================
\pgfmathsetlengthmacro\w{3.1em}% card width
\pgfmathsetlengthmacro\h{9*\w/6}% card height
% ================================
\crd{A}{h} has very much white space :(
\end{document}
答案1
我让字体大小取决于卡片高度,并稍微增加了内部 y 间隔。
\RequirePackage{fix-cm}% only needed if you are using cm fonts
\documentclass[]{article}
\usepackage{tikz}
\begin{document}
% Card-Style =============================
\definecolor{spadecolor}{HTML}{020202}% myblack % spade - Pik
\definecolor{heartcolor}{HTML}{C70002}% myred % heart - Herz
\definecolor{diamondcolor}{HTML}{687CF5}% myblue % diamond - Karo
\definecolor{clubcolor}{HTML}{3B7801}% mygreen % club - Kreuz
\colorlet{cardbackcolor}{purple}% card back
\colorlet{cardplaincolor}{black}% empty card
\colorlet{jokercolor}{violet}% joker
%
\newcommand\cardsymbol[1]{%
\ifnum\pdfstrcmp{#1}{s}=0 $\spadesuit$%
\else \ifnum\pdfstrcmp{#1}{h}=0 $\heartsuit$%
\else \ifnum\pdfstrcmp{#1}{d}=0 $\diamondsuit$%
\else \ifnum\pdfstrcmp{#1}{c}=0 $\clubsuit$%
\fi\fi\fi\fi}
%
\newcommand\cardcolor[1]{%
\ifnum\pdfstrcmp{#1}{s}=0 spadecolor%
\else \ifnum\pdfstrcmp{#1}{h}=0 heartcolor%
\else \ifnum\pdfstrcmp{#1}{d}=0 diamondcolor%
\else \ifnum\pdfstrcmp{#1}{c}=0 clubcolor%
\fi\fi\fi\fi}
% ================================
% Card-Sizes (default)=======================
\pgfmathsetlengthmacro\w{1.2em}% card width
\pgfmathsetlengthmacro\h{9*\w/6}% card height
% ================================
% \crd[<TikZ adds>]{<card value A,1-10,J,Q,K>}{<card color s,h,d,c>}
\newcommand\crd[3][]{%
\begin{tikzpicture}[font=\fontsize{.45\dimexpr\h\relax}{.45\dimexpr\h\relax}\sffamily,
cardtext/.style={inner sep=0pt, inner ysep=0.075*\h},
cardground/.style={minimum width=\w, minimum height=\h,
draw, rounded corners=0.075*\w},
]
\node(temp)[cardground,
label={[cardtext, anchor=north, text=\cardcolor{#3}]north:#2},
label={[cardtext, anchor=south, text=\cardcolor{#3}]south:\cardsymbol{#3}},
#1]{};
\end{tikzpicture}}
\section{Let's try the default}
I choose the cards \crd{K}{c}, \crd{A}{h}, \crd{Q}{d}, \crd{7}{s}.
(Dimensions could be better...)
\section{Now a huge card}
% Card-Sizes =============================
\pgfmathsetlengthmacro\w{3.1em}% card width
\pgfmathsetlengthmacro\h{9*\w/6}% card height
% ================================
\crd{A}{h} has very much white space :(
\end{document}