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 have the following definition (MWE below) of a lrbox. If I use the normal setting parskip=off the interaction \mdf@restoreparams works as expected. Inside the lrbox I can use parskip and parindent. But if I use the option parskip=half I get an extra skip at the beginning of the save box. How can I avoid this.

Picture

enter image description here

MWE:

\documentclass[parskip=half]{scrreprt}
\usepackage{kantlipsum}

\catcode`\@11\relax

\def\mdf@lrbox#1{%
 \edef\mdf@restoreparams{%
   \parindent=\the\parindent \parskip=\the\parskip}%
 \setbox#1\vbox\bgroup%
   \color@begingroup%
%     \mdf@horizontalmargin@equation%
     \columnwidth=\hsize%
     \textwidth=\hsize%
     \let\if@nobreak\iffalse%
     \let\if@noskipsec\iffalse%
     \let\par\@@par%
     \let\-\@dischyph%
     \let\'\@acci\let\`\@accii\let\=\@acciii%
     \parindent\z@ \parskip\z@skip%
     \linewidth\hsize%
     \@totalleftmargin\z@%
     \leftskip\z@skip \rightskip\z@skip \@rightskip\z@skip%
     \parfillskip\@flushglue \lineskip\normallineskip%
     \baselineskip\normalbaselineskip%
%%  \sloppy%
     \let\\\@normalcr%
     \hrule \@height\z@ \@width\hsize\relax
     \mdf@restoreparams\relax
     \@afterindentfalse%
     \@afterheading%
}

\def\endmdf@lrbox{\color@endgroup\egroup}


\newbox\MyTestBox

\begin{document}


\mdf@lrbox\MyTestBox
\kant[1]

\kant[1]
\endmdf@lrbox

\fbox{\box\MyTestBox}
\end{document}

I didn't tag this question with KOMA because the same result is reached by the header with a standard class

\documentclass[]{report}
\usepackage{parskip}

or with memoir

\documentclass[]{memoir}
\setlength{\parindent}{0pt}
\nonzeroparskip
share|improve this question
    
If you have any improvements I won't be disappointed ;-) –  Marco Daniel May 18 '12 at 10:13

2 Answers 2

up vote 7 down vote accepted

Well....

If you don't do

     \hrule \@height\z@ \@width\hsize\relax

Then you don't get the parskip at the top.

Then in your end code, if the width of the box is not what you expect (because no paragraph material has been added) do

\vbox{
hrule \@height\z@ \@width\hsize\relax
\unvbox the box you had
}

\documentclass[parskip=half]{scrreprt}
\usepackage{kantlipsum}

\catcode`\@11\relax

\def\mdf@lrbox#1{%
 \edef\mdf@restoreparams{%
   \parindent=\the\parindent \parskip=\the\parskip}%
 \def\tmp{#1}%
 \setbox#1\vbox\bgroup%
   \color@begingroup%
%     \mdf@horizontalmargin@equation%
     \columnwidth=\hsize%
     \textwidth=\hsize%
     \let\if@nobreak\iffalse%
     \let\if@noskipsec\iffalse%
     \let\par\@@par%
     \let\-\@dischyph%
     \let\'\@acci\let\`\@accii\let\=\@acciii%
     \parindent\z@ \parskip\z@skip%
     \linewidth\hsize%
     \@totalleftmargin\z@%
     \leftskip\z@skip \rightskip\z@skip \@rightskip\z@skip%
     \parfillskip\@flushglue \lineskip\normallineskip%
     \baselineskip\normalbaselineskip%
%%  \sloppy%
     \let\\\@normalcr%
%     \hrule \@height\z@ \@width\hsize\relax
     \mdf@restoreparams\relax
     \@afterindentfalse%
     \@afterheading%

}

\def\endmdf@lrbox{\color@endgroup\egroup
\ifdim\wd\tmp<\hsize
\typeout{making box fill width}
\setbox\tmp\vbox{%
\hrule \@height\z@ \@width\hsize\relax
\unvbox\tmp}%
\fi
}


\newbox\MyTestBox

\begin{document}

\mdf@lrbox\MyTestBox
\kant[1]

\kant[1]
\endmdf@lrbox




\fbox{\box\MyTestBox}



\mdf@lrbox\MyTestBox
\begin{tabbing}aaa\end{tabbing}
\endmdf@lrbox


\fbox{\box\MyTestBox}

\end{document}
share|improve this answer
    
The aim of the rule is to get the correct with of the vbox ;-) -- I tried \setbox\MyTestBox=\vbox{\unvbox\MyTestBox} but it didn't remains the first skip. –  Marco Daniel May 18 '12 at 10:46
    
If a paragraph is started (ie you get the parskip) the box will have the correct width without that rule (as the paragraph lines will be hboxes of that width) you only need the rule when there is no paragraph, I'll fill out a patched MWE. –  David Carlisle May 18 '12 at 10:50
    
Exactly what I searched –  Marco Daniel May 18 '12 at 11:02

You can add \vskip-\parskip just at the end of the definition of \mdf@lrbox, that is between \@afterheading and the closing brace.

This will cancel out the \parskip glue automatically inserted when the first paragraph is about to be started.

share|improve this answer
    
So long as the paragraph does get started. the reason why the rule is there in Marco's code is to catch the cases where no paragraph is started, to ensure the final box has full width. –  David Carlisle May 18 '12 at 10:48

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.