![与桥牌(游戏)相关的问题](https://linux22.com/image/321310/%E4%B8%8E%E6%A1%A5%E7%89%8C%EF%BC%88%E6%B8%B8%E6%88%8F%EF%BC%89%E7%9B%B8%E5%85%B3%E7%9A%84%E9%97%AE%E9%A2%98.png)
在 egreg 的帮助下,我的 bridge 相关宏有了很大的进步。以下是 MWE:
%********************************************************************************
\documentclass[10pt]{article}
\usepackage[paperwidth=6in,paperheight=9in, margin=1in]{geometry}
\usepackage{MnSymbol}
\usepackage[T1]{fontenc}
\usepackage[latin9]{inputenc}
\usepackage{xparse}
\usepackage{tikz}
\usepackage{libertine}
%********************************************************************************
%********************************************************************************
% Use MnSymbol suit symbols
\DeclareFontFamily{U}{MnSymbolCards}{}
\DeclareFontShape{U}{MnSymbolCards}{m}{n}{
<-6> s*[1.1] MnSymbolC5
<6-7> s*[1.1] MnSymbolC6
<7-8> s*[1.1] MnSymbolC7
<8-9> s*[1.1] MnSymbolC8
<9-10> s*[1.1] MnSymbolC9
<10-12> s*[1.1] MnSymbolC10
<12-> s*[1.1] MnSymbolC12}{}
\newcommand{\mndiamond}{{\usefont{U}{MnSymbolCards}{m}{n}\symbol{"A2}}}
\newcommand{\mnheart}{{\usefont{U}{MnSymbolCards}{m}{n}\symbol{"A3}}}
\newcommand{\mnspade}{{\usefont{U}{MnSymbolCards}{m}{n}\symbol{"A4}}}
\newcommand{\mnclub}{{\usefont{U}{MnSymbolCards}{m}{n}\symbol{"A5}}}
%********************************************************************************
%********************************************************************************
% BRIDGE HAND
% macros to produce horizontal and vertical bridge hand
%Defines "hair space" to be used after suit symbols
\newcommand{\cardsep}{\hspace*{0.2em}}
%defines a vertical bridge hand with seat name
\ExplSyntaxOn
\NewDocumentCommand{\hand}{smm}
{
\IfBooleanTF{#1}
{
\blackened_hand_horizontal:nn { #2 } { #3 }
}
{
\blackened_hand:nn { #2 } { #3 }
}
}
\seq_new:N \l_blackened_hand_seq
\clist_new:N \l_blackened_suit_clist
\cs_new_protected:Nn \blackened_hand_horizontal:nn
{
\seq_set_split:Nnn \l_blackened_hand_seq { ; } { #2 }
\mbox{\mnspade \ \blackened_set_suit:n { 1 } }\quad
\mbox{\mnheart \ \blackened_set_suit:n { 2 } }\quad
\mbox{\mndiamond \ \blackened_set_suit:n { 3 } }\quad
\mbox{\mnclub \ \blackened_set_suit:n { 4 } }
}
\cs_new_protected:Nn \blackened_hand:nn
{
\seq_set_split:Nnn \l_blackened_hand_seq { ; } { #2 }
\begin{minipage}[t]{\textwidth}
\begin{tabbing}
\tl_if_blank:nF { #1 } { \textbf{#1} \\ }
\mnspade \= \cardsep \= \blackened_set_suit:n { 1 } \\
\mnheart \> \> \blackened_set_suit:n { 2 } \\
\mndiamond \> \> \blackened_set_suit:n { 3 } \\
\mnclub \> \> \blackened_set_suit:n { 4 }
\end{tabbing}
\end{minipage}
}
\tl_const:Nn \c_blackened_ten_tl { 10 }
\tl_new:N \l_blackened_suit_tl
\seq_new:N \l_blackened_suit_seq
\cs_new_protected:Nn \blackened_set_suit:n
{
\tl_set:Nx \l_blackened_suit_tl { \seq_item:Nn \l_blackened_hand_seq { #1 } }
\tl_if_blank:VTF \l_blackened_suit_tl
{ --- } % no card in the suit
{
\tl_replace_once:Nnn \l_blackened_suit_tl { 10 } { \c_blackened_ten_tl }
\seq_set_split:NnV \l_blackened_suit_seq { } \l_blackened_suit_tl
\seq_use:Nn \l_blackened_suit_seq { \cardsep }
}
}
\ExplSyntaxOff
%********************************************************************************
%********************************************************************************
% BRIDGE DIAGRAM
\newcommand{\bd}[4]{%
\begin{tabular}[t]{ p{7em} p{7em} p{7em}}
& #1 & \\
#2 & {\vspace{4pt}\begin{tikzpicture} \draw (0,0) rectangle (1.3,1.3); \end{tikzpicture}} & #3\\
& #4 &
\end{tabular}
}
%********************************************************************************
%********************************************************************************
% custom minipage (needed for spacial cases)
\newlength{\myminipageparskip}
\newenvironment{bdminipage}
{\setlength{\myminipageparskip}{1ex}% save the value
\begin{minipage}{21em}% open the minipage
\setlength{\parskip}{\myminipageparskip}% restore the value
}
{\end{minipage}}
%********************************************************************************
\begin{document}
\begin{center}
\begin{bdminipage}
\bd
{\hand{North}{QJ42; 7; AJ763; 843}}%
{\hand{West}{K1085; AK543; Q4; AJ}}%
{\hand{East}{976; Q862; K10952; K}}%
{\hand{South}{A3; J109; 8; Q1097652}}%
\end{bdminipage}
\end{center}
\end{document}
生成:
如何修改宏以便我可以生成如下图表:
示例中只有两种花色,但实际上可能只有一种,花色符号可能不同,我可能不希望包含座位名称,在某些极端情况下,一个座位可能有两种花色,而其他座位只有一种花色,等等。因此,灵活性至关重要,值得无限赞赏。
答案1
添加一个可选参数来\hand
指定您想要显示的花色;顺序并不重要,花色按名称调用:S = 黑桃,H = 红心,D = 方块,C = 梅花。
为了实现正确的对齐,存在一些小麻烦,但我认为我已经解决了它们。
%********************************************************************************
\documentclass[10pt]{article}
\usepackage[paperwidth=6in,paperheight=9in, margin=1in]{geometry}
%\usepackage{MnSymbol} % not needed
\usepackage[T1]{fontenc}
\usepackage[latin9]{inputenc}
\usepackage{array}
\usepackage{xparse}
\usepackage{tikz}
\usepackage{libertine}
%********************************************************************************
%********************************************************************************
% Use MnSymbol suit symbols
\DeclareFontFamily{U}{MnSymbolCards}{}
\DeclareFontShape{U}{MnSymbolCards}{m}{n}{
<-6> s*[1.1] MnSymbolC5
<6-7> s*[1.1] MnSymbolC6
<7-8> s*[1.1] MnSymbolC7
<8-9> s*[1.1] MnSymbolC8
<9-10> s*[1.1] MnSymbolC9
<10-12> s*[1.1] MnSymbolC10
<12-> s*[1.1] MnSymbolC12}{}
\newcommand{\mndiamond}{{\usefont{U}{MnSymbolCards}{m}{n}\symbol{"A2}}}
\newcommand{\mnheart}{{\usefont{U}{MnSymbolCards}{m}{n}\symbol{"A3}}}
\newcommand{\mnspade}{{\usefont{U}{MnSymbolCards}{m}{n}\symbol{"A4}}}
\newcommand{\mnclub}{{\usefont{U}{MnSymbolCards}{m}{n}\symbol{"A5}}}
%********************************************************************************
%********************************************************************************
% BRIDGE HAND
% macros to produce horizontal and vertical bridge hand
%Defines "hair space" to be used after suit symbols
\newcommand{\cardsep}{\hspace*{0.2em}}
%defines a vertical bridge hand with seat name
\ExplSyntaxOn
\NewDocumentCommand{\hand}{sO{S,H,D,C}mm}
{
\IfBooleanTF{#1}
{
\blackened_hand_horizontal:nnn { #2 } { #3 } { #4 }
}
{
\blackened_hand:nnn { #2 } { #3 } { #4 }
}
}
\seq_new:N \l_blackened_hand_seq
\clist_new:N \l_blackened_suit_clist
\cs_new_protected:Nn \blackened_hand_horizontal:nnn
{
\seq_set_split:Nnn \l_blackened_hand_seq { ; } { #3 }
\hspace*{-1em}% remove the initial \quad
\clist_if_in:nnT { #1 } { S }
{ \quad \mbox{\mnspade \ \blackened_set_suit:n { 1 } } }
\clist_if_in:nnT { #1 } { H }
{ \quad \mbox{\mnheart \ \blackened_set_suit:n { 2 } } }
\clist_if_in:nnT { #1 } { D }
{ \quad \mbox{\mndiamond \ \blackened_set_suit:n { 3 } } }
\clist_if_in:nnT { #1 } { C }
{ \quad \mbox{\mnclub \ \blackened_set_suit:n { 4 } } }
}
\cs_new_protected:Nn \blackened_hand:nnn
{
\seq_set_split:Nnn \l_blackened_hand_seq { ; } { #3 }
\bool_gset_false:N \g_blackened_newline_bool
\begin{minipage}{\textwidth}
\begin{tabbing}
\tl_if_blank:nTF { #2 }
{ \bool_gset_false:N \g_blackened_newline_bool }
{ \bool_gset_true:N \g_blackened_newline_bool \textbf{#2} }
\clist_if_in:nnT { #1 } { S }
{ \blackened_newline: \mnspade \= \cardsep \= \blackened_set_suit:n { 1 } }
\clist_if_in:nnT { #1 } { H }
{ \blackened_newline: \mnheart \= \cardsep \= \blackened_set_suit:n { 2 } }
\clist_if_in:nnT { #1 } { D }
{ \blackened_newline: \mndiamond \= \cardsep \= \blackened_set_suit:n { 3 } }
\clist_if_in:nnT { #1 } { C }
{ \blackened_newline: \mnclub \= \cardsep \= \blackened_set_suit:n { 4 } }
\end{tabbing}
\end{minipage}
\bool_gset_false:N \g_blackened_newline_bool
}
\tl_const:Nn \c_blackened_ten_tl { 10 }
\tl_new:N \l_blackened_suit_tl
\seq_new:N \l_blackened_suit_seq
\bool_new:N \g_blackened_newline_bool
\cs_new_protected:Nn \blackened_newline:
{
\bool_if:NTF \g_blackened_newline_bool
{ \\ }
{ \bool_gset_true:N \g_blackened_newline_bool }
}
\cs_new_protected:Nn \blackened_set_suit:n
{
\tl_set:Nx \l_blackened_suit_tl { \seq_item:Nn \l_blackened_hand_seq { #1 } }
\tl_if_blank:VTF \l_blackened_suit_tl
{ --- } % no card in the suit
{
\tl_replace_once:Nnn \l_blackened_suit_tl { 10 } { \c_blackened_ten_tl }
\seq_set_split:NnV \l_blackened_suit_seq { } \l_blackened_suit_tl
\seq_use:Nn \l_blackened_suit_seq { \cardsep }
}
}
\ExplSyntaxOff
%********************************************************************************
%********************************************************************************
% BRIDGE DIAGRAM
\newcommand{\bd}[4]{%
\begin{tabular}{ m{7em} m{7em} m{7em}}
& #1 & \\
#2 & \parbox{7em}{
\vspace{1ex}
\begin{tikzpicture} \draw (0,0) rectangle (1.3,1.3); \end{tikzpicture}
\vspace{1ex}
} & #3\\
& #4 &
\end{tabular}
}
%********************************************************************************
%********************************************************************************
% custom minipage (needed for spacial cases)
\newlength{\myminipageparskip}
\newenvironment{bdminipage}
{\setlength{\myminipageparskip}{1ex}% save the value
\begin{minipage}{21em}% open the minipage
\setlength{\parskip}{\myminipageparskip}% restore the value
}
{\end{minipage}}
%********************************************************************************
\begin{document}
\begin{center}
\begin{bdminipage}
\bd
{\hand{North}{QJ42; 7; AJ763; 843}}%
{\hand{West}{K1085; AK543; Q4; AJ}}%
{\hand{East}{976; Q862; K10952; K}}%
{\hand{South}{A3; J109; 8; Q1097652}}%
\end{bdminipage}
\bigskip
\begin{bdminipage}
\bd
{\hand[S,H]{North}{QJ42; 7; AJ763; 843}}%
{\hand[S,H]{West}{K1085; AK543; Q4; AJ}}%
{\hand[S,H]{East}{976; Q862; K10952; K}}%
{\hand[S,H]{South}{A3; J109; 8; Q1097652}}%
\end{bdminipage}
\bigskip
\begin{bdminipage}
\bd
{\hand[S]{}{QJ42; 7; AJ763; 843}}%
{\hand[H]{}{K1085; AK543; Q4; AJ}}%
{\hand[D]{}{976; Q862; K10952; K}}%
{\hand[C]{}{A3; J109; 8; Q1097652}}%
\end{bdminipage}
\end{center}
\end{document}
带有彩色套装的版本。
\documentclass[10pt]{article}
\usepackage[paperwidth=6in,paperheight=9in, margin=1in]{geometry}
\usepackage[T1]{fontenc}
\usepackage{array}
\usepackage{tikz}
\usepackage{libertine}
\usepackage{xcolor}
% Use FdSymbol suit symbols
\DeclareFontFamily{U}{FdSymbolCards}{}
\DeclareFontShape{U}{FdSymbolCards}{m}{n}{
<-> s*[0.9] FdSymbolA-Book
}{}
\newcommand{\fddiamondsuit}{{\usefont{U}{FdSymbolCards}{m}{n}\symbol{"B5}}}
\newcommand{\fddiamondredsuit}{\textcolor{red!90!blue}{\usefont{U}{FdSymbolCards}{m}{n}\symbol{"B6}}}
\newcommand{\fdheartsuit}{{\usefont{U}{FdSymbolCards}{m}{n}\symbol{"B7}}}
\newcommand{\fdheartredsuit}{\textcolor{red!90!blue}{\usefont{U}{FdSymbolCards}{m}{n}\symbol{"B8}}}
\newcommand{\fdspadesuit}{{\usefont{U}{FdSymbolCards}{m}{n}\symbol{"B9}}}
\newcommand{\fdclubsuit}{{\usefont{U}{FdSymbolCards}{m}{n}\symbol{"BA}}}
\newif\ifcolorsuits
\newcommand{\fddiamond}{\fddiamondsuit}
\newcommand{\fdheart}{\fdheartsuit}
\newcommand{\fdspade}{\fdspadesuit}
\newcommand{\fdclub}{\fdclubsuit}
\AtBeginDocument{\ifcolorsuits\colorsuits\fi}
\newcommand{\colorsuits}{%
\renewcommand{\fddiamond}{\fddiamondredsuit}%
\renewcommand{\fdheart}{\fdheartredsuit}%
}
% BRIDGE HAND
% macros to produce horizontal and vertical bridge hand
%Defines "hair space" to be used after suit symbols
\newcommand{\cardsep}{\hspace*{0.2em}}
%defines a vertical bridge hand with seat name
\ExplSyntaxOn
\NewDocumentCommand{\hand}{sO{S,H,D,C}mm}
{
\IfBooleanTF{#1}
{
\blackened_hand_horizontal:nnn { #2 } { #3 } { #4 }
}
{
\blackened_hand:nnn { #2 } { #3 } { #4 }
}
}
\seq_new:N \l_blackened_hand_seq
\clist_new:N \l_blackened_suit_clist
\cs_new_protected:Nn \blackened_hand_horizontal:nnn
{
\seq_set_split:Nnn \l_blackened_hand_seq { ; } { #3 }
\hspace*{-1em}% remove the initial \quad
\clist_if_in:nnT { #1 } { S }
{ \quad \mbox{\fdspade \ \blackened_set_suit:n { 1 } } }
\clist_if_in:nnT { #1 } { H }
{ \quad \mbox{\fdheart \ \blackened_set_suit:n { 2 } } }
\clist_if_in:nnT { #1 } { D }
{ \quad \mbox{\fddiamond \ \blackened_set_suit:n { 3 } } }
\clist_if_in:nnT { #1 } { C }
{ \quad \mbox{\fdclub \ \blackened_set_suit:n { 4 } } }
}
\cs_new_protected:Nn \blackened_hand:nnn
{
\seq_set_split:Nnn \l_blackened_hand_seq { ; } { #3 }
\bool_gset_false:N \g_blackened_newline_bool
\begin{minipage}{\textwidth}
\begin{tabbing}
\tl_if_blank:nTF { #2 }
{ \bool_gset_false:N \g_blackened_newline_bool }
{ \bool_gset_true:N \g_blackened_newline_bool \textbf{#2} }
\clist_if_in:nnT { #1 } { S }
{ \blackened_newline: \fdspade \= \cardsep \= \blackened_set_suit:n { 1 } }
\clist_if_in:nnT { #1 } { H }
{ \blackened_newline: \fdheart \= \cardsep \= \blackened_set_suit:n { 2 } }
\clist_if_in:nnT { #1 } { D }
{ \blackened_newline: \fddiamond \= \cardsep \= \blackened_set_suit:n { 3 } }
\clist_if_in:nnT { #1 } { C }
{ \blackened_newline: \fdclub \= \cardsep \= \blackened_set_suit:n { 4 } }
\end{tabbing}
\end{minipage}
\bool_gset_false:N \g_blackened_newline_bool
}
\tl_const:Nn \c_blackened_ten_tl { 10 }
\tl_new:N \l_blackened_suit_tl
\seq_new:N \l_blackened_suit_seq
\bool_new:N \g_blackened_newline_bool
\cs_new_protected:Nn \blackened_newline:
{
\bool_if:NTF \g_blackened_newline_bool
{ \\ }
{ \bool_gset_true:N \g_blackened_newline_bool }
}
\cs_new_protected:Nn \blackened_set_suit:n
{
\tl_set:Nx \l_blackened_suit_tl { \seq_item:Nn \l_blackened_hand_seq { #1 } }
\tl_if_blank:VTF \l_blackened_suit_tl
{ --- } % no card in the suit
{
\tl_replace_once:Nnn \l_blackened_suit_tl { 10 } { \c_blackened_ten_tl }
\seq_set_split:NnV \l_blackened_suit_seq { } \l_blackened_suit_tl
\seq_use:Nn \l_blackened_suit_seq { \cardsep }
}
}
\ExplSyntaxOff
%********************************************************************************
%********************************************************************************
% BRIDGE DIAGRAM
\newcommand{\bd}[4]{%
\begin{tabular}{ m{7em} m{7em} m{7em}}
& #1 & \\
#2 & \parbox{7em}{
\vspace{1ex}
\begin{tikzpicture} \draw (0,0) rectangle (1.3,1.3); \end{tikzpicture}
\vspace{1ex}
} & #3\\
& #4 &
\end{tabular}
}
%********************************************************************************
%********************************************************************************
% custom minipage (needed for spacial cases)
\newlength{\myminipageparskip}
\newenvironment{bdminipage}
{\setlength{\myminipageparskip}{1ex}% save the value
\begin{minipage}{21em}% open the minipage
\setlength{\parskip}{\myminipageparskip}% restore the value
}
{\end{minipage}}
%********************************************************************************
\colorsuitstrue
\begin{document}
\begin{center}
\begin{bdminipage}
\bd
{\hand{North}{QJ42; 7; AJ763; 843}}%
{\hand{West}{K1085; AK543; Q4; AJ}}%
{\hand{East}{976; Q862; K10952; K}}%
{\hand{South}{A3; J109; 8; Q1097652}}%
\end{bdminipage}
\bigskip
\begin{bdminipage}
\bd
{\hand[S,H]{North}{QJ42; 7; AJ763; 843}}%
{\hand[S,H]{West}{K1085; AK543; Q4; AJ}}%
{\hand[S,H]{East}{976; Q862; K10952; K}}%
{\hand[S,H]{South}{A3; J109; 8; Q1097652}}%
\end{bdminipage}
\bigskip
\begin{bdminipage}
\bd
{\hand[S]{}{QJ42; 7; AJ763; 843}}%
{\hand[H]{}{K1085; AK543; Q4; AJ}}%
{\hand[D]{}{976; Q862; K10952; K}}%
{\hand[C]{}{A3; J109; 8; Q1097652}}%
\end{bdminipage}
\end{center}
\end{document}
默认情况下,红色套装是空心印刷的,但在文档的\colorsuitstrue
序言中或之后,它们显示为红色。\colorsuits