# minipage environment keep parskip

I've tried to create a new environment using minipage, which has the same vertical space between paragraphs as would be there when not using the minipage. What I have so far is:

\usepackage{boxedminipage} % had to use this to get minipage

\newlength{\currentparskip}
\newenvironment{minipageparskip}
{%
\setlength{\currentparskip}{\parskip}% save the value
\begin{minipage}{1.0\textwidth}% open the minipage
\setlength{\parskip}{\currentparskip}% restore the value
}%
{\end{minipage}}

\newenvironment{songverse}
{%
\begin{minipageparskip}{1.0\textwidth}%
\begin{center}%
}
{%
\end{center}%
\end{minipageparskip}%
\leavevmode \\%
}


However, in the line, where I first use this new environment, like this:

\begin{songverse}
...
Text
...
\end{songverse}


I get the following error:

! Missing number, treated as zero.
}
\songverse ...in {minipageparskip}{1.0\textwidth }
\begin {center}
l.118 \begin{songverse}


At first I thought it was talking about the 1.0\textwidth, but then I saw, that I have written that everywhere, where I used minipage, so now I think it might not be that. I don't understand where else a number could be missing, leading to this error.

The minipageparskip environment is actually copied from another SE post.

Ultimately, I want to have an environment, in which no pagebreak occurs and which contains a verse of a song.

How can I fix the error?

Example (samepage not preventing the pagebreak within songverse)

Note: using xelatex to compile.

    \documentclass[12pt, a5paper]{extarticle}
\usepackage[
top=20mm,
bottom=20mm,
left=24mm,
right=24mm
]{geometry}

\usepackage{fontspec}
\usepackage{xunicode}
\usepackage[UTF8]{ctex}

% AUTOMATICAL PINYIN PHONETIC SCRIPT
\newfontfamily{\DVS}{DejaVu Sans}
\usepackage{xpinyin}
\xpinyinsetup{ratio={.6}, hsep={.5em plus .1em}, vsep={1.1em}, multiple={\color{red}}, pysep={.2em}, footnote=false, font=\DVS}

\newenvironment{songverse}
{%
\begin{samepage}%
\begin{center}%
}{%
\end{center}%
\end{samepage}%
}

\begin{document}

\begin{pinyinscope}

\begin{songverse}

\end{songverse}
\begin{songverse}

\end{songverse}
\begin{songverse}

\end{songverse}
\begin{songverse}

\end{songverse}
\begin{songverse}

\end{songverse}
\begin{songverse}

\end{songverse}
\begin{songverse}

\end{songverse}
\begin{songverse}

\end{songverse}
\end{pinyinscope}

\end{document}

• you could just redefine \@parboxrestore not to reset pasrskip see tex.stackexchange.com/questions/279856/… but why not just samepage environment? – David Carlisle Feb 23 '16 at 19:50
• @DavidCarlisle Thanks for the suggestion of using samepage, I didn't know it. Unfortunately, in the resulting PDF the content within the samepage environment does still get split. Maybe it's my definition, which is wrong though: \newenvironment{songverse}{\begin{samepage} \begin{center}}{\end{center}\end{samepage}\leavevmode \\\\} – Zelphir Kaltstahl Feb 23 '16 at 20:28
• \leavevmode\\\\  is wrong in any case (don't you get underfull hbox badness 10000 warnings for each of those?) although that doesn't affect the splitting of the content. samepage tells all "normal" latex constructs not to break, but as you have provided no example document it is not possible to test any answer. (It's always best to include an example document in a question) – David Carlisle Feb 23 '16 at 20:33
• @DavidCarlisle I'll add one : ) – Zelphir Kaltstahl Feb 23 '16 at 20:35

Your minipageparskip environment does not expect an argument. I adjusted your definition, that the argument is passed through.

\newenvironment{minipageparskip}[1]
{%
\setlength{\currentparskip}{\parskip}% save the value
\begin{minipage}{#1}% open the minipage
\setlength{\parskip}{\currentparskip}% restore the value
}%
{\end{minipage}}


Edit:

But why do you even nest these two environments? I think it would be much easier to just use one environment.

\documentclass{article}
\newlength{\currentparskip}
\newenvironment{songverse}
{%
\setlength{\currentparskip}{\parskip}% save the value
\begin{minipage}{1.0\textwidth}%
\setlength{\parskip}{\currentparskip}% restore the value
\begin{center}%
}{%
\end{center}%
\end{minipage}%
\leavevmode \\%
}
\begin{document}
\begin{songverse}
...
Text
...
\end{songverse}
\end{document}

• I think this answer is closer to the original idea and it explains why my code is wrong, so I'll accept this answer. – Zelphir Kaltstahl Feb 23 '16 at 20:11

You can also use a tabular to provide an unbreakable block. It doesn't suffer from the same \baseline issues that \parbox and minipage have.

\documentclass{article}

\usepackage[nopar]{lipsum}% Just for this example

\newlength{\currentparskip}

\newenvironment{songverse}
{%
\setlength{\currentparskip}{\parskip}% Save current \parskip
\noindent\begin{tabular}[t]{@{} p{\textwidth} @{}}%
\centering
\setlength{\parskip}{\currentparskip}% Restore current \parskip
}
{%
\end{tabular}%
}

\begin{document}

\setlength{\parskip}{10pt}

\lipsum[1]

\lipsum[2]

\newpage

\begin{songverse}
\lipsum[1]

\lipsum[2]
\end{songverse}

\end{document}

• Thank you for pointing out the tabular environment idea, I am still a bit new to all of this and now I am thinking about what would be the cleaner approach, the tabular (which I didn't even know before you mentioned it) or the modified version with the minipage. – Zelphir Kaltstahl Feb 23 '16 at 20:13