# Text that doesn't affect the placement of other text

I would like to be able to put blocks of text in a document that don't affect the layout of the main part of it. (Specifically, I'm writing the solutions to a previously written exam; I'd like to be able to add the solutions in without causing the text from the original exam to move around.)

For what it's worth, the original spacing was largely handled via "\vfill", and I'd like those to still take up the same amount of space. (In principle, this means that if a solution were too long, it would run over and end up on top of the next problem, and I expected to have to manually check that this doesn't happen.)

Update: Here's an example, except that it isn't doing the spacing quite right. (The stuff in typewriter font is the solutions.) The point is that I want to leave the spacing of the original exam content alone, while inserting the solutions---complete with formatting---in the gaps left behind. In the unlikely event that there isn't enough space, I expect that any solution might cause crazy things to happen, but I'd like the typical case, that my solution fits in the space allotted, to be relatively seamless.

-
If the solution is too long, it would spill over the next page anyhow with or without \vfill. In those cases, do you want to scale the text to fit? You can simply start a new page for the next question with \newpage so the change would be limited to that question. –  percusse Sep 28 '11 at 14:18
I assume that you do not have the original LaTeX source code of the examination? –  Werner Sep 28 '11 at 14:20
I was planning to not have any solutions run over on the next page. (To clarify, the issue is that there are multiple questions on the same page, so I want to fit the solution to one question between that and the next question, without shifting around the next question.) I do have the original LaTex source code. –  Henry Sep 28 '11 at 14:21
If you do not have the code, and want to fit the solutions in "after the fact", consider reading Overlay LaTeX/TeX coding easily on PDF with 300 pages. –  Werner Sep 28 '11 at 14:26
@Henry Sorry for my speed of understanding, I have to ask one detail. What to do when you have more content then the space available even when you are arranging everything manually? Do you shift one of the questions or you simply shorten the solution? –  percusse Sep 28 '11 at 14:34

\newsavebox{\zerobox}
\newenvironment{nospace}
{\par\edef\theprevdepth{\the\prevdepth}\nointerlineskip
\setbox\zerobox=\vtop to 0pt\bgroup
\hrule height0pt\kern\dimexpr\baselineskip-\topskip\relax
}
{\par\vss\egroup\ht\zerobox=0pt \wd\zerobox=0pt \dp\zerobox=0pt
\box\zerobox}

Here ends the text of the question

\begin{nospace}
Here is the solution
\end{nospace}

\vfill


Here is a sample document:

\documentclass[a4paper]{article}
\usepackage{multicol}
\newsavebox{\zerobox}
\newenvironment{nospace}
{\par\edef\theprevdepth{\the\prevdepth}\nointerlineskip
\setbox\zerobox=\vtop to 0pt\bgroup
\hrule height0pt\kern\dimexpr\baselineskip-\topskip\relax
}
{\par\vss\egroup\ht\zerobox=0pt \wd\zerobox=0pt \dp\zerobox=0pt
\box\zerobox}

\begin{document}
Some text that may have descenders

\begin{nospace}
Here is some text
Here is some text
Here is some text
Here is some text
Here is some text
Here is some text
Here is some text
Here is some text
Here is some text
Here is some text
Here is some text
Here is some text
Here is some text
\end{nospace}

\vspace{10cm}

\textbf{And here is something else}

\newpage
Some text that may have descenders

\vspace{10cm}

\textbf{And here is something else}

\end{document}


Here is the result, that shows that the insertion takes up no space

-
This isn't working for me; it's pushing the start of the next question along as I make the solution longer. –  Henry Sep 28 '11 at 15:57
Aha, that is working now! Thanks. –  Henry Sep 28 '11 at 18:05

There are multiple possibilities for this, dependent what you exactly need.

You can use \llap{<text>} and \rlap{<text>} to add text which doesn't take any horizontal space and laps to the left or right, respectively.

With \raisebox{<raise amount>}[<set height>][<set depth>]{<text>}, i.e. \raisebox{0pt}[0pt][0pt]{<text>} you can set the height and depth of the text to zero (without actually raising it). This is also done with the \smash{<text>} macro.

For example you could use \llap{\smash{<text>}} to place some text to the left of the current position without taking any vertical or horizontal space. However, this will enter horizontal mode, e.g. start a new paragraph if you are just between paragraphs.

Then there is my adjustbox package provides the keys set height, set depth and lap, e.g. \adjustbox{set height=0pt,set depth=0pt,lap=-\width}{<text>} would be the same as the above mentioned \llap{\smash{<text>}}. In this specific case there is no real benefit to use that package, but you can easily add more, e.g. the minipage or fbox key if you need line breaking or a frame, respectively. See my answer to Positioning of text (box) relative to other text for an example.

Finally you can place text to absolute positions of the current page using TikZ if you use the remember picture,overlay options. With overlay the whole picture doesn't take any space as well. The text would then be part of a \node {<text>};

-
\llap doesn't start horizontal mode. –  egreg Sep 28 '11 at 14:28
Unless I'm doing something wrong, all of these seems to be having trouble with the internal formatting of the new text. (\llap and \smash both gave errors about the paragraph break in some of my text, while \raisebox seems to just ignore it and run the text off the side of the page.) –  Henry Sep 28 '11 at 14:29
@Henry: You can't have line breaking directly in them. You need to use either a \parbox{<length>}{..} or {minipage}{<length} environment around your text inside the \llap etc. macros. –  Martin Scharrer Sep 28 '11 at 14:31
@MartinScharrer I think what the OP wants is similar to your answer such that he fills up the available space with solution precisely. –  percusse Sep 28 '11 at 14:40
@Martin maybe I am missing something, but why not just a simple \vspace{} or hspace{}? –  Yiannis Lazarides Sep 28 '11 at 17:48

Cheat a bit! Print the answer in white! Later on you can just change the color to a normal color. (You can write a macro for this).

\documentclass{article}
\usepackage{xcolor}
\usepackage{lipsum}
\parindent0pt
\begin{document}

\textbf{Question}

\lipsum[1]


@Henry As you noted in your answer to percusse in the comments you might need to shorten the solution or as you suggest here lengthen it. I am suggesting rather write the answer and hide it to have a good estimate. Alternatively all you need is just a \vspace{}. –  Yiannis Lazarides Sep 28 '11 at 17:43