9

In math mode, I'm trying to make a square with a diamond in it. My failed attempt has been to put the following in the preamble:

\newcommand{\sqdiamond}{\mathbin{\rlap{$\mspace{2mu}\diamond$}\hbox{$\square$}}}

However, the diamond symbol is not scaled properly relative to the square. I'd like the corners of the diamond to touch the midpoints of the sides of the square, and I can't figure out how to "scale" the diamond appropriately. Is there another way to do this?

10

It is quit difficult to get the two symbols scaled and align correctly in all four math modes. Better draw it using TikZ. One difficulty is to properly scale the size and line width. This can be best done using amsmath \text macro. I made two versions which are slightly different.

\documentclass{article}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{tikz}

\newcommand{\sqdiamond}{\mathbin{\text{\tikz [x=1ex,y=1ex,line width=.1ex,line join=round] \draw (0,0) rectangle (1,1) (0,.5) -- (.5,1) -- (1,.5) -- (.5,0) -- (0,.5) -- cycle;}}}

\newcommand{\varsqdiamond}{\mathbin{\text{\tikz [x=1ex,y=1ex,line width=.1ex,line join=round] \draw (0,0) rectangle (1,1) (.5\pgflinewidth,.5) -- (.5,1ex-.5\pgflinewidth) -- (1ex-.5\pgflinewidth,.5) -- (.5,.5\pgflinewidth) -- (.5\pgflinewidth,.5) -- cycle;}}}

\begin{document}
% Test code:

.. $a \sqdiamond b$ ..

\[a \sqdiamond b \]

.. $X_{a \sqdiamond b}$ ..

.. $X_{X_{a \sqdiamond b}}$ ..


.. $a \varsqdiamond b$ ..

\[a \varsqdiamond b \]

.. $X_{a \varsqdiamond b}$ ..

.. $X_{X_{a \varsqdiamond b}}$ ..


\end{document}

Result 1

Zoomed:

Variant 1: sqdiamond

Variant 2: varsqdiamond

2

This seems to work with the Computer Modern fonts, but it's font dependent:

\newcommand{\sqdiamond}{\mathbin{\ooalign{%
  $\scriptstyle\square$\cr\hfil\raisebox{.15pt}{$\diamond$}\hfil\cr}}}
1

Here's one possibility, using TikZ:

\usepackage{tikz}

\newcommand{\sqdiamond}{%
  \tikz{\draw (0,0) rectangle (6pt,6pt); 
  \draw (3pt,0) -- (6pt,3pt) -- (3pt,6pt) -- (0,3pt) -- (3pt,0);}
}
  • The problem here is that it doesn't scale correctly in subscripts etc. Also the spacing around is wrong if \mathbin isn't used. – Martin Scharrer Apr 1 '11 at 20:32
  • @Martin Scharrer: yes, I know that, but it wasn't completely clear (at least for me) if the symbol should be used as a binary symbol, or as a relation symbol, or if it was just meant to be used as, for example, an endmark. – Gonzalo Medina Apr 1 '11 at 20:44
0

Using the xy package (in particular, \usepackage[all]{xy}), we can surround the diamond by a square as follows:

$\xymatrix{*[F]{\diamondsuit}}$

This appears to scale correctly to all font sizes, display math, footnotes, etc. The only question is whether a subscript placed afterwards will be spaced correctly. For this, the following tweak seems to work, though not guaranteed to be font-size-independent:

\documentclass{amsart}
\usepackage[all]{xy}
\newcommand\sd{\xymatrix{*[F]{\diamondsuit}}\hspace{0.5mm}}
\begin{document}
Jensen invented $\diamondsuit_\lambda$ and $\square_\lambda$.
We want to combine them.

Like this:
$\sd_\lambda$

\end{document}

Your Answer

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