4

I'd like to typeset a problem solution highlighting dimensional analysis in LaTeX. What is the best way to format the following in LaTeX?

  1.345 g | 0.5 L | 1000 cm^3
 ---------|-------|----------- =  0.6725 g
   cm^3   |       |   1 L

I could use a table I guess but that seems wrong. A set of \frac commands would also work but not give exactly the same visual affect. (It would be really nice to cancel the units in the expression as well). Aside from digging into pstricks is there a better way to do this?

lockstep
  • 250,273

1 Answers1

7

You could definitely use \frac to write the LHS components, and the cancel package provides a diagonal strike-through of elements. Here's a minimal example:

enter image description here

\documentclass{article}
\usepackage{cancel}% http://ctan.org/pkg/cancel
\begin{document}
\[
  \frac{1.345\,\textrm{g}}{1\,\cancel{\textrm{cm}^3}}\,
    \frac{0.5\,\cancel{\textrm{L}}}{1}\,
    \frac{1000\,\cancel{\textrm{cm}^3}}{1\,\cancel{\textrm{L}}}=0.6725\,\textrm{g}
\]
​\end{document}​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​

If the SW-NE diagonal crossing through L is visually unappealing, cancel also provides \bcancel, as well as xcancel (a combination of \cancel and \bcancel). The siunitx package can also be used to write numerals with units in a standard way.

Werner
  • 603,163
  • 2
    Seems like you hit 80 [tag:mathmode] answers. ;-) – lockstep Dec 28 '11 at 17:28
  • Keeping track, are we? :) – Werner Dec 28 '11 at 17:29
  • Is \ell a legal symbol for "liter"? It's used, but not endorsed by the BIPM. The correct spacing for units is \,, not \;, but perhaps here it can stand. – egreg Dec 28 '11 at 17:30
  • See also http://tex.stackexchange.com/questions/15916/cancel-draws-under-thing-being-canceled and http://tex.stackexchange.com/questions/20643/diagonal-strikeout-starting-too-low-and-ending-too-high for an alternative to cancel. – N.N. Dec 28 '11 at 17:32
  • @egreg: I'll update my answer to reflect the notation choice. Thanks for the note on spacing; looking back at it, I should actually remove the \, from 1000 as well, since it is perhaps more common to not have that for 4-digit numerals, leading to the initial choice of \;. – Werner Dec 28 '11 at 17:35
  • @egreg No, \ell is not valid here: the only symbols allowed are l and L. – Joseph Wright Dec 28 '11 at 17:36
  • You can use the siunitx package for the units to make the formatting less annoying. It also integrates with the cancel package. – krzysz00 May 12 '12 at 21:19