I am authoring a poker-related document and am using the following commands to allow me to display cards:

% Suit image adjustments:
\newcommand{\suit}[1]{\includegraphics[width=8pt, height=8pt]{#1}}

% Commands to display suit only.

% 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}

This works as intended and I am pleased with the results -- however, when cards get wrapped onto a new line I sometimes find that ranks get separated from their suits.

Is there any way to "group" items so that they get wrapped onto new lines together?

  • Welcome to TeX.SE. Not sure I understand but perhaps using an \mbox{} to keep things together: \newcommand{\ofheart}[1]{\mbox{\textcolor{red}{#1} \heart}}? – Peter Grill Apr 8 '13 at 22:42
  • While code snippets are useful in explanations, it is always best to compose a fully compilable MWE that illustrates the problem including the \documentclass and the appropriate packages so that those trying to help don't have to recreate it. – Peter Grill Apr 8 '13 at 22:45
  • 1
    \newcommand{\ofheart}[1]{\textcolor{red}{#1}~\heart} should do. – egreg Apr 8 '13 at 22:51
  • @PeterGrill Thanks for the kind welcome. I will endeavor to provide a complete code snippet in the future. Your suggestion works; now I the ranks and suits of the same cards stay together (see i.imgur.com/D4oOnO5.png). – JimmidyJoo Apr 8 '13 at 22:52
  • 1
    A suggestion: Use a small space (e.g. \, which never breaks); yes, the spacing will be different (intentionally) but in your example it is already hard to notice whether the symbol comes before or after the digit/letter. By the way, there are fonts that include ♣, ♠, ♥ and ♦ already (libertine does). – Qrrbrbirlbel Apr 8 '13 at 23:14

I suggest using existing symbols rather than images for the suits. Then you can simply use a non-breaking space ~ (EDIT: or, even better, a thinspace \, which is non-breaking as well, as suggested by @Qrrbrbirlbel) to avoid line breaking between rank and suit.

enter image description here






\ofclub{3} \qquad \ofspade{K} \qquad \ofheart{Q} \qquad \ofdiamond{4}


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.