Text Formatting ⇒ Faking Height of one Expression with another
-
- Posts: 402
- Joined: Fri May 20, 2011 9:41 am
Faking Height of one Expression with another
I know there is a command to fake the width of one expression with another expression using the \makebox* command from "makebox" package. But is there also another command to fake the height of one expression with another expression ?
Last edited by ghostanime2001 on Wed Dec 21, 2011 1:15 am, edited 2 times in total.
NEW: TikZ book now 40% off at Amazon.com for a short time.

-
- Posts: 126
- Joined: Sun Feb 13, 2011 8:36 pm
Faking Height of one Expression with another
You may use the plain TeX macros \smash and \vphantom to achieve this. In the following example, in the first paragraph, the height of the huge word ``line'' is smashed to zero. In the second paragraph, the second line consumes the same height as if the word ``line'' would be there in \huge font.
Equipped with this, you can define the macro \fakeheight that typesets its first argument as if it had the height from the second.
The whole story is very nicely described in a TGUBoat article by Alexander R. Perlis.
Code: Select all
\documentclass{article}
\begin{document}
\noindent%
This is a line of text.\\
This is a \smash{\huge line} of text.\\
This is a line of text.
\vspace{5ex}
\noindent%
This is a line of text.\\
This is a\vphantom{\huge line} of text.\\
This is a line of text.
\end{document}
Code: Select all
\newcommand{\fakeheight}[2]{\mbox{\smash{#1}\vphantom{#2}}}
I'm using pdfTeX, Version 3.1415926-1.40.10 (TeX Live 2009/Debian).
-
- Posts: 402
- Joined: Fri May 20, 2011 9:41 am
Faking Height of one Expression with another
When I try to use the \fakeheight command on chemical formula's the positioning of the superscript (+) charge moves upwards from the original positioning in the original table. How can I prevent this from happening ?
Code: Select all
\documentclass{article}
\usepackage[version=3]{mhchem}
\usepackage{tikz}
\usepackage{makebox}
\usepackage{nccboxes}
\usetikzlibrary{matrix,calc}
\newcommand{\fk}[2]{\mbox{\smash[t]{#1}\vphantom{#2}}}
\begin{document}
Original: \begin{tikzpicture}
\matrix (m) [matrix of math nodes,ampersand replacement=\&,nodes=draw]
{
\vphantom{\ce{H2S <=>}} \& \node (a) {\ce{H2S <=>}}; \& \node (b) {\ce{H+ +}}; \& \node (c) {\ce{HS-}}; \\ \hline
a \& \node {b}; \& \node {c}; \& \node {d}; \\
a \& \node {b}; \& \node {c}; \& \node {d}; \\
a \& \node {b}; \& \node {c}; \& \node {d}; \\
};
\end{tikzpicture} \\ \\
Now look at the negative charge on \ce{H+} and \ce{HS-} \\
\begin{tikzpicture}
\matrix (m) [matrix of math nodes,ampersand replacement=\&,nodes=draw]
{
\& \node (a) {\fk{\ce{H2S <=>}}{\ce{HS-}}}; \& \node (b) {\fk{\ce{H+ +}}{\ce{HS-}}}; \& \node (c) {\fk{\ce{HS-}}{\ce{HS-}}}; \\ \hline
a \& \node {b}; \& \node {c}; \& \node {d}; \\
a \& \node {b}; \& \node {c}; \& \node {d}; \\
a \& \node {b}; \& \node {c}; \& \node {d}; \\
};
\end{tikzpicture}
\end{document}
-
- Posts: 126
- Joined: Sun Feb 13, 2011 8:36 pm
Faking Height of one Expression with another
Don't fake a different height but let TeX' positioning algorithms know the actual dimensions of the objects to arrange.ghostanime2001 wrote:How can I prevent this from happening ?
I'm using pdfTeX, Version 3.1415926-1.40.10 (TeX Live 2009/Debian).
-
- Posts: 402
- Joined: Fri May 20, 2011 9:41 am
Re: Faking Height of one Expression with another
There's nothing I can do ???