# Grouping items onto the same line to avoid wrapping

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.
\newcommand{\heart}{\suit{../res/heart_26x26.png}}
\newcommand{\club}{\suit{../res/club_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{\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
• \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
• 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.

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