2

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.
<to be read again> 
                   }
\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}

唯有 心无挂碍 成就大愿

唯有 心无故 妙不可言

算天算\xpinyin{地}{di4} 算尽\xpinyin{了}{liao3} 从前

算不出 生死 会在哪一天

\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
2

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}
| improve this answer | |
  • 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
1

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.

enter image description here

\documentclass{article}

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

\newlength{\currentparskip}

\newenvironment{songverse}
{%
  \setlength{\currentparskip}{\parskip}% Save current \parskip
  \par%\vspace{\baselineskip}% Add possible separation
  \noindent\begin{tabular}[t]{@{} p{\textwidth} @{}}%
    \centering
    \setlength{\parskip}{\currentparskip}% Restore current \parskip
}
{%
  \end{tabular}%
  \par%\vspace{\baselineskip}% Add possible vertical separation
}

\begin{document}

\setlength{\parskip}{10pt}

\lipsum[1]

\lipsum[2]

\newpage

\begin{songverse}
\lipsum[1]

\lipsum[2]
\end{songverse}

\end{document}
| improve this answer | |
  • 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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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