Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I want to create boxes (\Box) and diamonds (\Diamond) with letter and other symbols insider them. I've achieved something, but the result is ok-ish:

$\Box \!\!\! _ {^{_ {^{_{^a}}}}}$
$\Diamond \!\!\! _ {^{_ {^{_{^a}}}}}$
$\Box\!\!\! _{^{ _{^\heartsuit}}}$

Does anyone have a good tip to make it looks better?

share|improve this question

2 Answers 2

A simple solution for single characters in the box and diamond. Play around with the setting \setlength\fboxsep{2pt} inside macros

\documentclass[a5paper,12pt]{article}
\usepackage{amssymb,graphicx}
\def\CBox#1{\fbox{$\scriptstyle#1$}}
\def\DBox#1{\rotatebox[origin=c]{45}{\fbox{\rotatebox[origin=c]{-45}{$#1$}}}}
\begin{document}

$\CBox{a}$
$\DBox{a}$

\end{document} 

enter image description here

share|improve this answer

I can't make the code shorter, but it might be more readable and reliable.

\documentclass{article}
\usepackage{amssymb}
\newcommand\merge[2]{%
  \ooalign{\hfil$\vcenter{\hbox{$#1$}}$\hfil\cr
    \hfil$\vcenter{\hbox{$\scriptstyle #2$}}$\hfil}}
\newcommand\inBox[1]{\merge\Box{#1}}
\newcommand\inDiamond[1]{\merge\Diamond{#1}}
\newcommand\inheartsuit[1]{\merge\heartsuit{#1}}
\begin{document}
$\inBox{a}, \inDiamond{a}, \inBox\heartsuit$
\end{document}

enter image description here

\ooalign is used by LaTeX kernel to merge symbols. Commands like \textcircled are defined with it.

share|improve this answer
    
nice solution!! –  Herbert May 5 '11 at 12:27

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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