4

For alignment reasons (for boxes that align themselves on the text they contain), I currently use this command :

\newcommand{\uplowtext}[1]{
    \transparent{0.}TJPtjp
    \transparent{1.}#1
    \transparent{0.}TJPtjp
}

to make all boxes with the same height by adding an invisible "TJPtjp" before and after the text. But the problem is when someone copy/paste the text from the pdf: he can see the "TJPtjp".

Instead of text, how to put one invisible "box" of the height of "TJPtjp" before and after the text, aligned as a text, so that it will act as a vertical spacer.

2
  • 1
    \leavevmode\phantom{0.}? – egreg Sep 15 '15 at 7:50
  • Can you explain a little more, what would be the whole replacement of my \newcommand? – Vincent Sep 15 '15 at 7:56
8

LaTeX has an undocumented but very useful feature:

\phantom{text}
\hphantom{text}
\vphantom{text}

will create “phantoms”; they occupy the same space of text, but \hphantom just for the width (no height and depth) and \vphantom just for the height and depth (no width). In any case no character will appear, just the space they would occupy.

For TeXnical reasons, you should add \leavevmode before any of these commands (unless you are sure they will be used in LR-mode or math mode).

So what you want seems to be

\newcommand{\fake}[1]{\leavevmode\hphantom{#1}}

and \fake{0.} instead of \transparent{0.). Your code would become

\newcommand{\fake}[1]{\leavevmode\hphantom{#1}}
\newcommand{\uplowtext}[1]{%
  \fake{0.}TJPtjp
  \fake{1.}#1
  \fake{0.}TJPtjp
}
1
  • Just curious, were you joking when you said that the phantom commands are undocumented? In what sense are they undocumented? For example, they are mentioned in "The LaTeX Companion". – James Sep 15 '15 at 11:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.