3

This question is related to this question. Read that question, and read the first and the only answer, and its comments.

Answer I got was worked well. But there is a very little problem. Let's say that we have multi columned document:

\documentclass[twocolumn]{article}
\newenvironment{mybox}{\par\noindent%
   \begin{minipage}{\linewidth}}
   {\end{minipage}\par\vfill}
\begin{document}
        \begin{mybox}
            ++++++\\
            \vspace{3cm}\\
            **********
        \end{mybox}
        \begin{mybox}
            ++++++\\
            \vspace{3cm}\\
            **********
        \end{mybox}
        \begin{mybox}
            ++++++\\
            \vspace{3cm}\\
            **********
        \end{mybox}
        \begin{mybox}
            ++++++\\
            \vspace{3cm}\\
            **********
        \end{mybox} \begin{mybox}
        ++++++\\
        \vspace{3cm}\\
        **********
    \end{mybox}
    \begin{mybox}
        ++++++\\
        \vspace{3cm}\\
        **********
    \end{mybox}
    \begin{mybox}
        ++++++\\
        \vspace{3cm}\\
        **********
    \end{mybox}
    \begin{mybox}
        ++++++\\
        \vspace{3cm}\\
        **********
    \end{mybox}
\end{document}

The output is: output

As you may notice, the last asterisks do not share same horizontal level. The thing I expected was asterisks on the left column should be on more higher level. Because \vspace{\fill} should also work at the end of that column too. But somehow it doesn't. So could you explain why?

2 Answers2

3

You want the page break to happen after the \vfill otherwise it will happen before the \vfill on the first column (and so be discarded) but still be there on the last: so use \vspace*

enter image description here

\documentclass[twocolumn]{article}
\newcommand\myskip{}  % vertical spacing between mybox environments
\newenvironment{mybox}{\par\noindent%
   \begin{minipage}{\linewidth}}
   {\end{minipage}\par\vspace*{\fill}\pagebreak[0]}


\begin{document}
        \begin{mybox}
            ++++++\\
            \vspace{3cm}\\
            **********
        \end{mybox}
        \begin{mybox}
            ++++++\\
            \vspace{3cm}\\
            **********
        \end{mybox}
        \begin{mybox}
            ++++++\\
            \vspace{3cm}\\
            **********
        \end{mybox}
        \begin{mybox}
            ++++++\\
            \vspace{3cm}\\
            **********
        \end{mybox} \begin{mybox}
        ++++++\\
        \vspace{3cm}\\
        **********
    \end{mybox}
    \begin{mybox}
        ++++++\\
        \vspace{3cm}\\
        **********
    \end{mybox}
    \begin{mybox}
        ++++++\\
        \vspace{3cm}\\
        **********
    \end{mybox}
    \begin{mybox}
        ++++++\\
        \vspace{3cm}\\
        **********
    \end{mybox}

\end{document}
David Carlisle
  • 757,742
  • This is good answer. But if I use \vspace instead of \vspace*, nothing changes. After I defined the page break positions, why do I still need to use \vspace*? – jnbrq -Canberk Sönmez Jan 22 '15 at 15:08
  • @jnbrq You need to prevent the page break happening before the \vspace{\fill] which would cause it to be discarded. Alternatively and possibly better, go back to \vspace (or just \vfill but ensure that you do not add a space after the last one, only between your boxes. – David Carlisle Jan 22 '15 at 17:03
  • How can I use your solution with multicols? I use starred version of multicols environment, but it looks like pagebreak[0] doesn't work. – jnbrq -Canberk Sönmez Jan 23 '15 at 05:29
1

I don't know if this fix is universal, but it works for a number of different box sizes (\mysize). I apply an optional argument to your \mybox environment. If the optional 1-letter argument is F or is omitted, it applies a closing \vfill to the environment. For any other letter, it applies a \vspace{-.5\baselineskip} (and I am not sure why this works).

Typically, you would apply the optional argument to the last block on a filled page, though not if it was the last block on an unfilled page.

\documentclass[twocolumn]{article}
\newcommand\myskip{}  % vertical spacing between mybox environments
\newenvironment{mybox}[1][F]{\par\noindent\gdef\applyvfill{#1}%
   \begin{minipage}{\linewidth}}
   {\end{minipage}\par\if F\applyvfill\vfill\else\vspace{-.5\baselineskip}\fi}
\def\mysize{3cm}
\newcommand\domybox[1][F]{%
        \begin{mybox}[#1]
            ++++++\\
            \vspace{\mysize}\\
            **********
        \end{mybox}
}
\begin{document}
\domybox
\domybox
\domybox
\domybox
\domybox
\domybox
\domybox
\domybox[x]
\end{document}

enter image description here

And here is the result when \mysize is 4cm and 6 invocations (the last one with [x]):

enter image description here

and then this, with \mysize set to 1.5cm and 14 invocations (the last one with [x])

\documentclass[twocolumn]{article}
\newcommand\myskip{}  % vertical spacing between mybox environments
\newenvironment{mybox}[1][F]{\par\noindent\gdef\applyvfill{#1}%
   \begin{minipage}{\linewidth}}
   {\end{minipage}\par\if F\applyvfill\vfill\else\vspace{-.5\baselineskip}\fi}
\newcommand\domybox[1][F]{%
        \begin{mybox}[#1]
            ++++++\\
            \vspace{\mysize}\\
            **********
        \end{mybox}
}
\begin{document}
\def\mysize{1.5cm}
\domybox
\domybox
\domybox
\domybox
\domybox
\domybox
\domybox
\domybox
\domybox
\domybox
\domybox
\domybox
\domybox
\domybox[x]
\end{document}

enter image description here

  • This answer is not generalized enough. But I am curious. Could you explain why did you use -.5\baselineskip for the last box? (Even you told you aren't sure, I want to know your idea) – jnbrq -Canberk Sönmez Jan 22 '15 at 15:17
  • @jnbrq When a page ended on a box with your original code, there seemed to be a extra blank line at the bottom of the right column. I thought subtracting it off with a \vspace{-\baselineskip} might work, but it removed too much space. So I set it to -.5\baselineskip without any logical rationale, and it seemed to work. – Steven B. Segletes Jan 22 '15 at 15:23