checkbox macro 

Newsgroups: comp.text.tex
Date: 2001-05-02 23:01:00 PST

I need a cross-out checkbox in my document (which is supposed to be printed). An example might be

[ ]  Male   [ ] Female

I think the box should have the height of X and be aligned with the baseline. I did the following:

\newlength{\Xheight}
\settoheight{\Xheight}{X}
\newcommand{\checkbox}{%
\setlength{\fboxsep}{0pt}%
\framebox[\height]{\rule{0pt}{\Xheight}}%
}

It works, but

1) I would like to put the definition of \Xheight inside \checkbox so that \checkbox is stand-alone. How do I do that ? Or in other words - how can I do this smarter? 2) Is there already such a macro somewhere?

Hans

PS! I'm aware of ex and \Xheight in CM is approx 1.5ex but that might be different in another font.

checkbox macro 

> what's this \height?

\height, \width, \depth, \totalheight are (latex) length parameter which is defined for framebox/makebox. They specify the natural size of the text to be boxed. I used it to get a square box …. (which was what I wanted, but forgot to say).

> what's wrong with
> \newcommand\checkbox{{% note double braces to isolate \setlength
>   \setlength\fboxsep{0pt}%
>   \fbox{\phantom{X}}%
> }}

It isn't square, else it is fine. I had forgotten about \phantom - and thx for warning me about the needed double braces - why?

Using \phantom my macro is now:

\newcommand\checkbox{{%
\setlength\fboxsep{0pt}%
\framebox[\height]{\phantom{X}}%
}

Hans Nordhaug,

checkbox macro 

>thx for warning me about the needed double braces - why?

in general, macros shouldn't set global parameters as side-effects of their behaviour. imho, anyway. the extra braces cause the assignment to be local only.

>Using \phantom my macro is now:
>
>\newcommand\checkbox{{%
>\setlength\fboxsep{0pt}%
>\framebox[\height]{\phantom{X}}%
>}

if my brain hadn't faded i would have realised you wanted a square box. that lot looks good.

Robin Fairbairns

checkbox macro 

Another way, that automatically gives squares, is to set fboxsep to half the size.

\newcommand\checkbox{\mbox{%
  \settoheight\fboxsep{X}\setlength\fboxsep{.5\fboxsep}%
  \raisebox\depth{\fbox{}}%
}}

Donald Arseneau

checkbox macro 

The following should work:

\newcommand{\checkbox}[1]{%
\settoheight{\Xheight}{#1}%
\setlength{\fboxsep}{0pt}%
\framebox[\height]{\rule{0pt}{\Xheight}}%

Dr. D. P. Story

checkbox macro 

As an alternative to drawing these manually, note that a number of fonts contain square boxes, which you can scale as necessary.

wasysym even provides a \Square, \CheckedBox, and \XBox macro, to represent an unchecked box, a checked box, and an xed box, respectively.

Check out the Comprehensive LaTeX Symbol List on CTAN for font samples.

Scott

mathabx 

\boxvoid
\boxtimes

or,

\bigboxtimes
\bigboxvoid