我正在編寫一個與撲克相關的文檔,並使用以下命令來顯示紙牌:
% Suit image adjustments:
\newcommand{\suit}[1]{\includegraphics[width=8pt, height=8pt]{#1}}
% Commands to display suit only.
\newcommand{\heart}{\suit{../res/heart_26x26.png}}
\newcommand{\club}{\suit{../res/club_26x26.png}}
\newcommand{\spade}{\suit{../res/spade_26x26.png}}
\newcommand{\daimond}{\suit{../res/daimond_26x26.png}}
% Commands to display both rank and suit.
\newcommand{\ofheart}[1]{\textcolor{red}{#1} \heart}
\newcommand{\ofclub}[1]{\textcolor{black}{#1} \club}
\newcommand{\ofspade}[1]{\textcolor{black}{#1} \spade}
\newcommand{\ofdaimond}[1]{\textcolor{red}{#1} \daimond}
這按預期工作,我對結果很滿意——但是,當卡片被包裝到新線上時,我有時會發現等級與花色分開。
有什麼方法可以對項目進行“分組”,以便將它們包裝到新的行中嗎?
答案1
我建議使用現有的符號而不是圖像來製作套裝。然後你可以簡單地使用一個不間斷的空格~
(編輯:或者更好的是,一個\,
不間斷的細空格,正如@Qrrbrbirlbel建議的那樣)來避免等級和花色之間的換行。
\documentclass{article}
\usepackage{xcolor}
\usepackage{arev}
\DeclareSymbolFont{extraup}{U}{zavm}{m}{n}
\DeclareMathSymbol{\varheart}{\mathalpha}{extraup}{86}
\DeclareMathSymbol{\vardiamond}{\mathalpha}{extraup}{87}
\newcommand\ofheart[1]{\textcolor{red}{#1\,$\varheart$}}
\newcommand\ofclub[1]{\textcolor{black}{#1\,$\clubsuit$}}
\newcommand\ofspade[1]{\textcolor{black}{#1\,$\spadesuit$}}
\newcommand\ofdiamond[1]{\textcolor{red}{#1\,$\vardiamond$}}
\begin{document}
\ofclub{3} \qquad \ofspade{K} \qquad \ofheart{Q} \qquad \ofdiamond{4}
\end{document}