Text Formattingheight of text using \makebox

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
Post Reply
ghostanime2001
Posts: 402
Joined: Fri May 20, 2011 9:41 am

height of text using \makebox

Post by ghostanime2001 »

How can I set the height of C with the height of H+ ?

I have already defined a new lenght \co as the height of H+ but it doesn't work with \makebox even though \makebox can take \height or \totalheight as an optional argument.

Code: Select all

\documentclass{article}
\usepackage[version=3]{mhchem}
\newlength{\co}
\settoheight{\co}{\ce{H+}}
\begin{document}
\fbox{\makebox[\co]{C}} \fbox{\ce{H+}}
\end{document} 

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

ghostanime2001
Posts: 402
Joined: Fri May 20, 2011 9:41 am

Re: height of text using \makebox

Post by ghostanime2001 »

Any suggestions ?
User avatar
NoIdeaNickanme
Posts: 13
Joined: Wed Nov 09, 2011 5:41 pm

height of text using \makebox

Post by NoIdeaNickanme »

Hi!
This may not be a conventional solution, however using tabular environment and \hhline within a \makebox does the trick.

Code: Select all

\documentclass{article}
\usepackage[version=3]{mhchem}
\usepackage{hhline}
\begin{document}

\makebox{
     \begin{tabular}{|c|}
     \hhline{-}
     C\\
     \hhline{-}
     \end{tabular}
}
\makebox{
     \begin{tabular}{|c|}
     \hhline{-}
     \ce{H+}\\
     \hhline{-}
\end{tabular}
}

\end{document}
If you still have problems with height, use tabulary environment instead.
Post Reply