Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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.

share|improve this question
    
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
1  
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
show 1 more comment

3 Answers

up vote 3 down vote accepted
\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

enter image description here

share|improve this answer
    
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
add comment

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>};

share|improve this answer
    
\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
add comment

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]

\textbf{Answer}

\textcolor{white}{
  \lipsum[1]}

\textbf{Question}

\end{document}
share|improve this answer
    
That would require writing up all the solutions beforehand, though. –  Henry Sep 28 '11 at 14:51
1  
@Henry You need to know either the solution which I assume is known to you or alternative you need to know the amount of space you want to allow. If none available then the problem is unsolvable! Writing the solutions beforehand is good practice for anyone writing exams:) –  Yiannis Lazarides Sep 28 '11 at 15:25
    
There's a difference between knowing the solution and writing it up. (Particularly if I want to add comments to the solution based on particular answers or common mistakes.) –  Henry Sep 28 '11 at 15:58
    
@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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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