3

I need to put together my bridge-related macros to produce complete bridge diagrams. A MWE and an example output is shown below:

%********************************************************************************
\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}
\usepackage{array}
%********************************************************************************


%********************************************************************************
% 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
%********************************************************************************
\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
%********************************************************************************

% Above macros are not directly related to this question,
% they are needed to to produce the diagrams


%********************************************************************************
% BRIDGE DIAGRAM
%********************************************************************************
\newlength{\myminipageparskip}
\newenvironment{bdminipage}
  {\setlength{\myminipageparskip}{1ex}% save the value
   \begin{minipage}[t]{3in}% open the minipage
   \setlength{\parskip}{\myminipageparskip}% restore the value
  }
  {\end{minipage}}

% bidding
\newenvironment{bidding}{%
\begin{minipage}[t]{3in}
\setlength{\topsep}{0pt}%
\setlength{\partopsep}{0pt}%
\begin{tabbing}
\hspace*{0.75in}\= \hspace*{0.75in}\= \hspace*{0.75in}\= \hspace*{0.75in} \kill
\textbf{South} \> \textbf{West} \> \textbf{North} \> \textbf{East}\\
}%
{\end{tabbing}\end{minipage}}%


\newcommand{\bdcomplete}[7]{%
\begin{tabular}[t]{ m{1in} m{1in} m{1in}}
\multicolumn{3}{m{3in}}{
\begin{bdminipage}
#1
\end{bdminipage}}\vspace{2ex}\\
   & #2 &\\
#3 & {\begin{tikzpicture} \draw (0,0) rectangle (1.3,1.3); \end{tikzpicture}} & #4\\
   & #5 &\\
\multicolumn{3}{m{3in}}{#6}\\
\multicolumn{3}{m{3in}}{
\begin{bdminipage}
#7
\end{bdminipage}}
\end{tabular}
}
%********************************************************************************




\begin{document}

The following deal was reported in the \emph{The Bridge World} magazine:

\begin{center}
\bdcomplete
{
East dealer,\\
North-South vulnerable
}
{\hand{North}{J432; 65; A53; QJ109}}%
{\hand{West}{K5; AK9732; 84; 876}}%
{\hand{East}{109876; J84; J; K532}}%
{\hand{South}{AQ; Q10; KQ109762; A4}}%
{
\begin{bidding}
2\mnheart \> Pass\> 3\mnheart \> Double \\
Pass\> 3\mnspade \> Pass \> 4\mndiamond \\
Pass\> 5\mndiamond\> Pass\> Pass\\
Pass
\end{bidding}
}
{
Contract: Five-clubs doubled by South.

Opening lead: Heart ace.

Closed Room Result: Five clubs doubled by the Brazilian South, down 1, +100 for Norway.
}
\end{center}
Some text following the diagram above.

\end{document}

enter image description here

When some of the options are blank, they still occupy a certain amount of vertical space, as in below:

\begin{document}

The following deal was reported in the \emph{The Bridge World} magazine:

\begin{center}
\bdcomplete
{}
{\hand{North}{J432; 65; A53; QJ109}}%
{\hand{West}{K5; AK9732; 84; 876}}%
{\hand{East}{109876; J84; J; K532}}%
{\hand{South}{AQ; Q10; KQ109762; A4}}%
{}{}
\end{center}
Some text following the diagram above.

enter image description here

How can I avoid such behavior.

(When I “feel” that the macros are mature, I plan to present them to bridge authors, players, etc. So any comment to make the Bridge Diagrams macros above more robust, more LaTeX way, more flexible in any way is appreciated. For example, there isn't enough vertical space between the bidding and the explanatory text below; I like to be able to control such details as much as possible.)

(I am aware that I can write separate macros for separate diagrams and needs.)

2
  • You may test if the argument is null and if so, do nothing. In xparse package you have the \IfNoValueTF{}{}{} that can help you on that. – cacamailg Oct 22 '15 at 18:28
  • @cacamailg: \IfNoValueTF{} operates only on optional argument, but [] would be regarded as non-null, i.e. it has a value then! – user31729 Oct 22 '15 at 20:58
4

It is possible to use \notblank{#1}{true}{false} from etoolbox package to query whether an argument is empty or not and react correspondingly. However, it should not be used inside \multicolumn since those tabular cells would be typeset any way, regardless whether #1 is empty or not.

Using

\noalign{\gdef\temp@x{\notblank{#1}{\multicolumn{3}{m{3in}}{%... }}{\@empty}}}\temp@x

this will mask the query first (\noalign) and stores the execution to \temp@x which is then called afterwards. If \temp@x is empty, nothing is done.

Additional vertical space comes in when #6 is empty --> a \tabularnewline is used anyway. I removed this with \showonlyifnotempty{#6}

The code for #1 and #7 with bdminipage is almost identical, so I defined \showwithminipage{som}, the starred version is used to suppress the \tabularnewline at the end of the \multicolumn. If the optional argument is not given, no \vspace{...} will be inserted.

Another possibility to cope with {} is to use optional arguments and \NewDocumentCommand instead, querying with \IfValueT but this does not prevent the \noalign approach.

%********************************************************************************
\documentclass[10pt]{article}
\usepackage[paperwidth=6in,paperheight=9in, margin=1in]{geometry}
\usepackage{MnSymbol}
\usepackage[T1]{fontenc}
\usepackage[latin9]{inputenc}
\usepackage{etoolbox}
\usepackage{xparse}
\usepackage{tikz}
\usepackage{libertine}
\usepackage{array}
%********************************************************************************


%********************************************************************************
% 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
%********************************************************************************
\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
%********************************************************************************

% Above macros are not directly related to this question,
% they are needed to to produce the diagrams


%********************************************************************************
% BRIDGE DIAGRAM
%********************************************************************************
\newlength{\myminipageparskip}
\newenvironment{bdminipage}
{\setlength{\myminipageparskip}{1ex}% save the value
  \begin{minipage}[t]{3in}% open the minipage
    \setlength{\parskip}{\myminipageparskip}% restore the value
  }
  {\end{minipage}}

% bidding
\newenvironment{bidding}{%
\begin{minipage}[t]{3in}
\setlength{\topsep}{0pt}%
\setlength{\partopsep}{0pt}%
\begin{tabbing}
\hspace*{0.75in}\= \hspace*{0.75in}\= \hspace*{0.75in}\= \hspace*{0.75in} \kill
\textbf{South} \> \textbf{West} \> \textbf{North} \> \textbf{East}\\
}%
{\end{tabbing}\end{minipage}}%

\makeatletter
\newcommand{\showonlyifnotempty}[1]{%
  \noalign{%
    \gdef\temp@x{\notblank{#1}{%
        \multicolumn{3}{m{3in}}{#1}
        \tabularnewline
      }{% false branch
        \@empty
      }%
    }%
  }%
  \temp@x
}

\DeclareExpandableDocumentCommand{\showwithminipage}{som}{%
  \noalign{%
    \gdef\temp@x{\notblank{#3}{%
        \multicolumn{3}{m{3in}}{%
          \begin{bdminipage}
            #3
          \end{bdminipage}
          \IfValueT{#2}{%
          \vspace{#2}%
          }
        }
        \IfBooleanF{#1}{%
        \tabularnewline % Only \tabularnewline if there is no star
        }%
      }{% false branch
        \@empty
      }%
    }%
  }%
  \temp@x
}




\NewDocumentCommand{\bdcomplete}{mmmmmmm}{%
\begin{tabular}[t]{ m{1in} m{1in} m{1in}}
  \showwithminipage[2ex]{#1}
  & #2 & \\
  #3 & {\begin{tikzpicture} \draw (0,0) rectangle (1.3,1.3); \end{tikzpicture}} & #4\\
  & #5 & \tabularnewline
  \showonlyifnotempty{#6}%
  \showwithminipage*{#7} 
 \end{tabular}%
}
\makeatother
%********************************************************************************





\begin{document}

The following deal was reported in the \emph{The Bridge World} magazine:
\hrule
\begin{center}
\bdcomplete
{Hello}
{\hand{North}{J432; 65; A53; QJ109}}%
{\hand{West}{K5; AK9732; 84; 876}}%
{\hand{East}{109876; J84; J; K532}}%
{\hand{South}{AQ; Q10; KQ109762; A4}}%
{More Text}{Even more text}
\end{center}
\hrule
\begin{center}
\bdcomplete
{}
{\hand{North}{J432; 65; A53; QJ109}}%
{\hand{West}{K5; AK9732; 84; 876}}%
{\hand{East}{109876; J84; J; K532}}%
{\hand{South}{AQ; Q10; KQ109762; A4}}%
{}{}
\end{center}
\hrule
Some text following the diagram above.

\end{document}

enter image description here

Edit Version with long arguments which allow par breaks:

%********************************************************************************
\documentclass[10pt]{article}
\usepackage[paperwidth=6in,paperheight=9in, margin=1in]{geometry}
\usepackage{MnSymbol}
\usepackage[T1]{fontenc}
\usepackage[latin9]{inputenc}
\usepackage{etoolbox}
\usepackage{xparse}
\usepackage{tikz}
\usepackage{libertine}
\usepackage{array}
%********************************************************************************


%********************************************************************************
% 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
%********************************************************************************
\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
%********************************************************************************

% Above macros are not directly related to this question,
% they are needed to to produce the diagrams


%********************************************************************************
% BRIDGE DIAGRAM
%********************************************************************************
\newlength{\myminipageparskip}
\newenvironment{bdminipage}
{\setlength{\myminipageparskip}{1ex}% save the value
  \begin{minipage}[t]{3in}% open the minipage
    \setlength{\parskip}{\myminipageparskip}% restore the value
  }
  {\end{minipage}}

% bidding
\newenvironment{bidding}{%
\begin{minipage}[t]{3in}
\setlength{\topsep}{0pt}%
\setlength{\partopsep}{0pt}%
\begin{tabbing}
\hspace*{0.75in}\= \hspace*{0.75in}\= \hspace*{0.75in}\= \hspace*{0.75in} \kill
\textbf{South} \> \textbf{West} \> \textbf{North} \> \textbf{East}\\
}%
{\end{tabbing}\end{minipage}}%

\makeatletter
\newcommand{\showonlyifnotempty}[1]{%
  \noalign{%
    \gdef\temp@x{\notblank{#1}{%
        \multicolumn{3}{m{3in}}{#1}
        \tabularnewline
      }{% false branch
        \@empty
      }%
    }%
  }%
  \temp@x
}

\DeclareExpandableDocumentCommand{\showwithminipage}{+s+o+m}{%
  \noalign{%
    \gdef\temp@x{\notblank{#3}{%
        \multicolumn{3}{m{3in}}{%
          \begin{bdminipage}
            #3
          \end{bdminipage}
          \IfValueT{#2}{%
          \vspace{#2}%
          }
        }
        \IfBooleanF{#1}{%
        \tabularnewline % Only \tabularnewline if there is no star
        }%
      }{% false branch
        \@empty
      }%
    }%
  }%
  \temp@x
}




\NewDocumentCommand{\bdcomplete}{+m+m+m+m+m+m+m}{%
\begin{tabular}[t]{ m{1in} m{1in} m{1in}}
  \showwithminipage[2ex]{#1}
  & #2 & \\
  #3 & {\begin{tikzpicture} \draw (0,0) rectangle (1.3,1.3); \end{tikzpicture}} & #4\\
  & #5 & \tabularnewline
  \showonlyifnotempty{#6}%
  \showwithminipage*{#7} 
 \end{tabular}%
}
\makeatother
%********************************************************************************






\begin{document}

The following deal was reported in the \emph{The Bridge World} magazine:

\begin{center}
\bdcomplete
{
East dealer,\\
North-South vulnerable
}
{\hand{North}{J432; 65; A53; QJ109}}%
{\hand{West}{K5; AK9732; 84; 876}}%
{\hand{East}{109876; J84; J; K532}}%
{\hand{South}{AQ; Q10; KQ109762; A4}}%
{
\begin{bidding}
2\mnheart \> Pass\> 3\mnheart \> Double \\
Pass\> 3\mnspade \> Pass \> 4\mndiamond \\
Pass\> 5\mndiamond\> Pass\> Pass\\
Pass
\end{bidding}
}
{
Contract: Five-clubs doubled by South.

Opening lead: Heart ace.

Closed Room Result: Five clubs doubled by the Brazilian South, down 1, +100 for Norway.
}
\end{center}
Some text following the diagram above.

\end{document}


\begin{document}
The following deal was reported in the \emph{The Bridge World} magazine:
\hrule
\begin{center}
\bdcomplete
{Hello}
{\hand{North}{J432; 65; A53; QJ109}}%
{\hand{West}{K5; AK9732; 84; 876}}%
{\hand{East}{109876; J84; J; K532}}%
{\hand{South}{AQ; Q10; KQ109762; A4}}%
{More Text}{Even more text}
\end{center}
\hrule
\begin{center}
\bdcomplete
{}
{\hand{North}{J432; 65; A53; QJ109}}%
{\hand{West}{K5; AK9732; 84; 876}}%
{\hand{East}{109876; J84; J; K532}}%
{\hand{South}{AQ; Q10; KQ109762; A4}}%
{}{}
\end{center}
\hrule
Some text following the diagram above.



\end{document}

enter image description here

Request for optional arguments

\NewDocumentCommand{\bdcompleteopt}{+m+m+m+m+m+O{2ex}+m+O{1ex}+m}{%
\begin{tabular}[t]{ m{1in} m{1in} m{1in}}
  \showwithminipage[2ex]{#1}
  & #2 & \\
  #3 & {\begin{tikzpicture} \draw (0,0) rectangle (1.3,1.3); \end{tikzpicture}} & #4\\
  & #5 & \tabularnewline[#6] % Optional space between #5 and #7
  \showonlyifnotempty{#7}%
  \showwithminipage*[#8]{#9} % Optional space between next to last and last line
 \end{tabular}%
}
11
  • Very good answer! – cacamailg Oct 22 '15 at 22:07
  • @cacamailg: Oh, thank you very much. Querying inside tables is a constant source of joy ;-) – user31729 Oct 22 '15 at 22:09
  • @Christian Thanks for giving your time. Am I doing something wrong? When I substitute the portion between \begin{document} and \end{document, in my original MWE, I get an error. – blackened Oct 22 '15 at 22:26
  • @blackened: You mean the one with the longer example? -- Ah yes, the long arguments ... Hm, I've to change something then – user31729 Oct 22 '15 at 22:27
  • @blackened: See the update, please! – user31729 Oct 22 '15 at 22:33

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.