7

If I add to a class test this code:

\hfill\fbox{T}\qquad\fbox{F}

at the end of a question, magnifying it you'll see that the "true" box is slightly larger than the "false" one.

Is it interesting to anyone?

0

4 Answers 4

12

Use a box that's as wide as the widest between T and F.

You don't even need to know which one (different fonts may do different choices), because it's decided at runtime.

\documentclass{article}

\newcommand{\True} {\fbox{\makebox[\MAXTF]{T}}}
\newcommand{\False}{\fbox{\makebox[\MAXTF]{F}}}
\newcommand{\MAXTF}{%
  \fontcharwd\font\ifdim\fontcharwd\font`T>\fontcharwd\font`F `T\else `F\fi
}

\begin{document}

\True\ \False

\False\ \True

\end{document}

If you're sure that T is wider than F (which is usually the case), you can simplify into

\newcommand{\True}{\fbox{T}}
\newcommand{\False}{\fbox{\makebox[\fontcharwd\font`T]{F}}}

enter image description here

10

As you can see, the T is wider than the F. The \fbox command adjusts to the size of its contents so different size boxes is the expected behavior. If you want the same size, use \framebox and specify the width.

enter image description here

\framebox[1.5em][c]{T}\quad\framebox[1.5em][c]{F}

Note that [c] is optional since centered text is the default. But you could change that to [l] or [r] if you wish.

enter image description here

5

If I add to a class test this code:

\hfill\fbox{T}\qquad\fbox{F}

at the end of a question,

This actually does not precisely describe the scenario performed by the questioner in a way reproducible by others.

magnifying it you'll see that the "true" box is slightly larger than the "false" one.

When TeX, at the time of reading and tokenizing the content of a .tex-file, encounters a character T while not gathering the name of a control sequence token, then that character usually is tokenized as an explicit character token whose category is 11(letter) and whose character code equals the number of the character T in TeX's internal character representation scheme which with XeTeX and LuaTeX is unicode, and with traditional TeX-engines like Knuth's TeX and Hàn Thế Thành's pdfTeX is a character-encoding-scheme where you can encode 256 characters, numbered from 0-255 and whereof characters 0-127 comply to the American Standard Code for Information Interchange.

Let's henceforth denote such an explicit character token via T11.

When TeX is typesetting contents of boxes, a character token T11 is taken for the instruction to typeset a glyph from the font currently in use which belongs to the class formed by the grapheme "T". Same with the character token F11 with respect to the grapheme "F".

In case the glyph in use for denoting the instance of the grapheme "T" is wider than the glyph in use for denoting the instance of the grapheme "F", with \fbox the frame around the "T"-glyph is wider than the frame around the "F"-glyph, too.

Thus boxes not being of same size is to be expected.

Is it interesting to anyone?

Whether something is interesting or not also is a matter of opinion.

The author of this answer doesn't know about the opinions of others in this matter, thus he doesn't know whether this is interesting to anyone.


Maybe the remarks above don't answer those questions which the questioner did not ask explicitly. So after guessing let's focus on the matter of getting boxes of same height, depth and width while having TeX typeset different glyphs:

  • To get measurements of boxes, e.g. widths for horizontally centering, you can play with \lastbox.
  • To ensure measurements of boxes (both vertically and horizontally), you can use \phantom.
  • To have \hboxes overprint one another so that their baselines vertically coincide into one, set \baselineskip to zero and \lineskiplimit to -\maxdimen; with ordinary character glyphs a value smaller than the negative of the sum of height and depth of a strut should do, but with -\maxdimen you might be on the safe side:
\documentclass{article}

\usepackage{color}

\newbox\scratchbox

\begin{document}

This seems wrong:
\fbox{%
  \hbox{%
    \vbox{%
      \baselineskip=0pt
      \lineskiplimit=-\maxdimen 
      \hbox{\hfill\color{red}T\hfill}%
      \hbox{\hfill F\hfill}%
    }%
  }%
}

\medskip

These seem right:
\fbox{%
  \hbox{%
    \vbox{\hbox{T}\hbox{F}}%
    \setbox\scratchbox=\lastbox
    \vbox{%
      \baselineskip=0pt
      \lineskiplimit=-\maxdimen 
      \hbox to\wd\scratchbox{\hfill\phantom{T}\hfill}%
      \hbox to\wd\scratchbox{\hfill\phantom{F}\hfill}%
      \hbox{\hfill\color{red}T\hfill}%
      \hbox to\wd\scratchbox{\hfill F\hfill}%
    }%
  }%
}

\fbox{%
  \hbox{%
    \vbox{\hbox{T}\hbox{F}}%
    \setbox\scratchbox=\lastbox
    \vbox{%
      \baselineskip=0pt
      \lineskiplimit=-\maxdimen 
      \hbox to\wd\scratchbox{\hfill\phantom{T}\hfill}%
      \hbox to\wd\scratchbox{\hfill\phantom{F}\hfill}%
      \hbox to\wd\scratchbox{\hfill F\hfill}%
    }%
  }%
}
%
\fbox{%
  \hbox{%
    \vbox{\hbox{T}\hbox{F}}%
    \setbox\scratchbox=\lastbox
    \vbox{%
      \baselineskip=0pt
      \lineskiplimit=-\maxdimen 
      \hbox to\wd\scratchbox{\hfill\phantom{T}\hfill}%
      \hbox to\wd\scratchbox{\hfill\phantom{F}\hfill}%
      \hbox to\wd\scratchbox{\hfill T\hfill}%
    }%
  }%
}

\fbox{%
  \hbox{%
    \vbox{\hbox{T}\hbox{F}}%
    \setbox\scratchbox=\lastbox
    \vbox{%
      \baselineskip=0pt
      \lineskiplimit=-\maxdimen 
      \hbox to\wd\scratchbox{\hfill\phantom{T}\hfill}%
      \hbox to\wd\scratchbox{\hfill\phantom{F}\hfill}%
      \hbox to\wd\scratchbox{\hfill T\hfill}%
    }%
  }%
}
%
\fbox{%
  \hbox{%
    \vbox{\hbox{T}\hbox{F}}%
    \setbox\scratchbox=\lastbox
    \vbox{%
      \baselineskip=0pt
      \lineskiplimit=-\maxdimen 
      \hbox to\wd\scratchbox{\hfill\phantom{T}\hfill}%
      \hbox to\wd\scratchbox{\hfill\phantom{F}\hfill}%
      \hbox to\wd\scratchbox{\hfill F\hfill}%
    }%
  }%
}

\end{document}

enter image description here

0

This actually does not precisely describe the scenario performed by the questioner in a way reproducible by others.

Here it is:

\documentclass{article}
\usepackage[utf8]{inputenc}

\newcommand{\truefalse}{\hfill\framebox[1.5em][c]{T}\quad\framebox[1.5em][c]{F}}

\begin{document}

    Determine wether these statements are True or False:

\begin{enumerate}
    \item God exists \truefalse
    \item Aliens exist \truefalse
    \item Tupac is still alive \truefalse
\end{enumerate}

\end{document}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .