8

Is there a way I can use \phantom to hide the contents of an environment, such as itemize?

This does not execute:

\phantom{\begin{itemize}
          \item Hi!
         \end{itemize}}

I'm specifically not looking to just change the text white, because I don't want the contents highlightable in the output.

2
  • 1
    Does tex.stackexchange.com/questions/135453/… help?
    – egreg
    Feb 21, 2015 at 17:56
  • @egreg Wow! Not only is that relevant because it's working to leave the space open, I also want this functionality for student versions of my lecture notes. Wild! Nice find!
    – Kyle
    Feb 21, 2015 at 21:48

1 Answer 1

10

No, you can't use \phantom like that. You can use a \parbox inside \phantom to hide the contents, but reserving the space it occupied, or you could use the comment environment from the comment package to hide the contents suppressing the space altogether:

\documentclass[draft]{article}
\usepackage{comment}

\begin{document}

a
\begin{comment}
\begin{itemize}
\item First.
\item Second.
\end{itemize}
\end{comment}
b

a\par
\noindent\phantom{\parbox{\linewidth}{%
\begin{itemize}
\item First.
\item Second.
\end{itemize}}}\par
b

\end{document}

enter image description here

1
  • This is perfect! I need to get more used to using parboxes to turn "block" elements into "inline" elements. (I'm guessing at terms here.) Thank you!
    – Kyle
    Feb 21, 2015 at 21:59

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