14

Is there any way to 'phantom' text within the align environment?

I have the following code:

\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{align*}
\phantom
{
a & = b \\
& = c
}
\end{align*}
\end{document}

Apparently, if there a tab alignment character in the argument of the phantom command, compilation will stop. I was trying to make the text within the align environment appear as blank text. Curiously, if I have a cases environment with the tab alignment character inside it, phantom will work when it surrounds the cases environment.

Thanks.

2
  • you could \phantom each individual 'cell'
    – cmhughes
    Commented Aug 27, 2012 at 1:20
  • you could pack the alignment in a minipage with the \phantom wrapped around that, but unfortunately it would foul up the vertical spacing. Commented Aug 27, 2012 at 12:57

3 Answers 3

18

If you "hide" the tab alignment & from align, it will fail to work as expected. This is only because & is read as part of the argument to \phantom, which knowns nothing about & and its use. As such, you either have to spread the \phantom across the aligned components, or use an altogether different approach:

enter image description here

\documentclass{article}
\usepackage{amsmath}% http://ctan.org/pkg/amsmath
\begin{document}
\begin{align*}
  a & = b + c \\
  \phantom{a} & \phantom{{} = b} + c \\ % Hides some components of above line
   & = d + e \\
   & \phantom{{}= d} + e % Hides some components of above line
\end{align*}
\end{document}

In the above example, some components were left untouched to indicate how some spacing correction is sometimes required when using \phantom (for example, when hiding the relation =).

The reason why \phantom around an entire cases structure works is because the tab alignment character is buried within the environment where it makes sense.

4

This is an old question, but I thought that future searchers might appreciate this alternative, which in complex situation is much easier than splitting out the phantoms over the tab stops. It uses pgf, which has \pgfsys@begininvisible and \pgfsys@endinvisible for this purpose.

\documentclass{article}

\usepackage{pgf}
\usepackage{amsmath}

\makeatletter
\newcommand\pgfinvisible{\pgfsys@begininvisible}
\newcommand\pgfshown{\pgfsys@endinvisible}
\makeatother

\begin{document}

\begin{align*}
  a & = b + c \\
  \pgfinvisible a & = b\pgfshown + c \\ % Hides some components of above line
   & = d + e \\
  \pgfinvisible  & = d\pgfshown + e % Hides some components of above line
\end{align*}

\end{document}

The output: align with phantoms crossing tab boundaries

This is the mechanism that beamer's overlay system uses.

In fact, you can put this around the entire align* environment, which doesn't work with \phantom and is what the question asker originally wanted. Then one must be careful about introducing extra vertical space.

I should add here that, apparently, this does not remove the text from the PDF (it gets offset somewhere where it won't appear on the page, as far as I understand) so this is not a suitable approach for redaction.

3

It's probably easier to use textcolor with white:

\textcolor{white}{sometext}

You need the color package.

2
  • 9
    Unusual approach, however I don't consider it good in this case. There are two reasons: (1) unnecessary usage of colours, (2) the hidden text is still copy-pastable, which might be an issue, especially if it's hidden to achieve correct spacing, because then the text does not belong to the output but still would get copied.
    – yo'
    Commented Aug 27, 2012 at 6:18
  • Also, this text is still read by automated resume reading programs, careful what you write! Commented Aug 15, 2018 at 1:45

You must log in to answer this question.

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