假设我有:
%defines a vertical bridge hand with seat name
\newcommand{\hand}[5]{
\begin{minipage}[t]{1.0cm}
\begin{tabbing}
\textsc{#1} \= \\
\s\Hair\=#2 \\
\h \> #3 \\
\d \> #4 \\
\c \> #5
\end{tabbing}
\end{minipage} }%
如何自定义字母间距(字母/数字之间后西装符号)在自定义环境?是否还可以在某些字母/数字之间添加自定义字距?(比如说,除了自定义字母间距之外,我还想调整 K 和 J 之间的字距。
梅威瑟:
\documentclass[10pt,a5paper,english]{article}
\usepackage{mathptmx}
\usepackage[T1]{fontenc}
\usepackage[latin9]{inputenc}
\pagestyle{empty}
\usepackage{amsmath}
%********************************************************************************
%Use MnSymbol suit symbols
\DeclareFontFamily{U}{MnSymbolCards}{}
\DeclareFontShape{U}{MnSymbolCards}{m}{n}{
<-6> s*[1.2] MnSymbolC5
<6-7> s*[1.2] MnSymbolC6
<7-8> s*[1.2] MnSymbolC7
<8-9> s*[1.2] MnSymbolC8
<9-10> s*[1.2] MnSymbolC9
<10-12> s*[1.2] MnSymbolC10
<12-> s*[1.2] 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}}}
\renewcommand{\c}{\mnclub}
\renewcommand{\d}{\mndiamond}
\newcommand{\h}{\mnheart}
\newcommand{\s}{\mnspade}
%********************************************************************************
%Defines "hair space" to be used after suit symbols
\newcommand{\Hair}{\ifmmode\mskip1mu\else\kern0.08em\fi}
%defines a vertical bridge hand with seat name
\newcommand{\hand}[5]{
\begin{minipage}[t]{1.0cm}
\begin{tabbing}
\textsc{#1} \= \\
\s\Hair\=#2 \\
\h \> #3 \\
\d \> #4 \\
\c \> #5
\end{tabbing}
\end{minipage} }%
\usepackage{babel}
\begin{document}
\noindent \hand{North}{KJ2}{AQ742}{K9}{K87}
\end{document}
答案1
我建议改变语法,这样可以使重新格式化变得更加容易。
\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{tgtermes}
\usepackage{xparse}
%***
%Use MnSymbol suit symbols
\DeclareFontFamily{U}{MnSymbolCards}{}
\DeclareFontShape{U}{MnSymbolCards}{m}{n}{
<-6> s*[1.2] MnSymbolC5
<6-7> s*[1.2] MnSymbolC6
<7-8> s*[1.2] MnSymbolC7
<8-9> s*[1.2] MnSymbolC8
<9-10> s*[1.2] MnSymbolC9
<10-12> s*[1.2] MnSymbolC10
<12-> s*[1.2] 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}}}
%***
% Defines the separation between cards
\newcommand{\cardsep}{\hspace*{0.3em}}
%defines a vertical bridge hand with seat name
\ExplSyntaxOn
\NewDocumentCommand{\hand}{mm}
{
\blackened_hand:nn { #1 } { #2 }
}
\seq_new:N \l_blackened_hand_seq
\clist_new:N \l_blackened_suit_clist
\cs_new_protected:Nn \blackened_hand:nn
{
\seq_set_split:Nnn \l_blackened_hand_seq { ; } { #2 }
\begin{minipage}[t]{\textwidth}
\begin{tabbing}
\textsc{#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}
}
\cs_new_protected:Nn \blackened_set_suit:n
{
\clist_set:Nx \l_blackened_suit_clist { \seq_item:Nn \l_blackened_hand_seq { #1 } }
\clist_use:Nn \l_blackened_suit_clist { \cardsep }
}
\ExplSyntaxOff
\begin{document}
\hand{North}{K,J,2; A,Q,10,4,2; K,9; K,8,7}
\end{document}
手形用分号分隔成各个部分;然后每个部分用逗号分隔,这样我们就可以插入任何我们想要的内容。的第二个参数中的空格\hand
完全无关紧要(当然,除了您不应该在中间放空格10
),因此输入可以更好地布局。
一种允许“水平”设置手的变体,只需\hand*
。我会保留座位名称以实现最大的可移植性:这样您只需复制和粘贴手,添加或删除*
。逗号后可以换行。
\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{tgtermes}
\usepackage{xparse}
%********************************************************************************
%Use MnSymbol suit symbols
\DeclareFontFamily{U}{MnSymbolCards}{}
\DeclareFontShape{U}{MnSymbolCards}{m}{n}{
<-6> s*[1.2] MnSymbolC5
<6-7> s*[1.2] MnSymbolC6
<7-8> s*[1.2] MnSymbolC7
<8-9> s*[1.2] MnSymbolC8
<9-10> s*[1.2] MnSymbolC9
<10-12> s*[1.2] MnSymbolC10
<12-> s*[1.2] 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}}}
%********************************************************************************
%Defines "hair space" to be used after suit symbols
\newcommand{\cardsep}{\hspace*{0.3em}}
%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 } },~
\mbox{\mnheart \ \blackened_set_suit:n { 2 } },~
\mbox{\mndiamond \ \blackened_set_suit:n { 3 } },~
\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}
\textsc{#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}
}
\cs_new_protected:Nn \blackened_set_suit:n
{
\clist_set:Nx \l_blackened_suit_clist { \seq_item:Nn \l_blackened_hand_seq { #1 } }
\clist_use:Nn \l_blackened_suit_clist { \cardsep }
}
\ExplSyntaxOff
\begin{document}
\hand*{North}{K,J,2; A,Q,10,4,2; K,9; ---}
\bigskip
\hand{North}{K,J,2; A,Q,10,4,2; K,9; K,8,7}
\end{document}
\blackened_set_suit:n
如果你改变的定义
\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 }
}
}
那么你必须从上面的输入中删除逗号;空格同样是不相关的,因此从诸如
\hand*{North}{KJ2; AQ1042; ; K 8 7 }
\bigskip
\hand{North}{KJ2; AQ1042; ; K 8 7}
你得到
我不确定有任何好处。
答案2
您\newcommand{\hand}...
可以使用:
\def\hand#1#2#3#4#5{\vtop{
\hbox{\textsc{#1}}
\handA \s{#2}
\handA \h{#3}
\handA \d{#4}
\handA \c{#5}
}}
\def\handA#1#2{\hbox{\hbox to1em{\hss#1\hss}\handB#2\relax}}
\def\handB#1{\ifx#1\relax\else #1\if1#1\else\kern2pt \fi\expandafter\handB\fi}
字母之间的字距设置为 2pt,请参阅定义\handB
。您可以更改此设置。
编辑:我添加了一个例外:1 之后不是\kern
,所以十设置正确(并且单个 1 表示没有卡)。
編輯2如果您需要 egreg 建议的语法,即:
\hand{North}{K,J,2; A,Q,10,4,2; K,9; K,8,7}
然后我的宏可以通过以下方式修改:
\def\hand#1#2{\handX{#1}#2;}
\def\handX#1#2;#3;#4;#5;{\vtop{
\hbox{\textsc{#1}}
\handA \s{#2}
\handA \h{#3}
\handA \d{#4}
\handA \c{#5}
}}
\def\handA#1#2{\hbox{\hbox to1em{\hss#1\hss}\handB#2,,}}
\def\handB#1,{\ifx,#1,\else \ignorespaces#1\kern2pt \expandafter\handB\fi}
请注意,我的宏不需要任何附加包\ExplSynaxOn
等等。让我感到敬畏的是:为什么这里不首选最简单和 TeX 原始的解决方案。