4

I am getting frustrated by not being able to "label" lists in a way where the "label" would stick with the list and a page break (or column break) would not be introduced before it.

Here is a MWE:

\documentclass[12pt]{article}
\usepackage[a5paper]{geometry}
\usepackage{fontspec}
\usepackage{microtype}
\usepackage{multicol}
\usepackage[defaultlines=2,all]{nowidow}
\usepackage{ragged2e}
\usepackage{lipsum}
\usepackage{enumitem}
\usepackage{parskip}

\tolerance=1000

\makeatletter
\newcommand{\indexClass}[1]{\index{#1}}
\newcommand{\class}[1]{#1\indexClass{#1}}
\makeatother

\newcommand{\WviiTwoColumnSetup}{\raggedcolumns\RaggedRight}

\SetEnumitemKey{WviiTwoColumn}{%
  before=\begin{multicols}{2}\WviiTwoColumnSetup,
  after=\end{multicols}}

\begin{document}
\lipsum[1-2]

Convenient Starting Professions\nobreak\nopagebreak\begin{itemize}[WviiTwoColumn]\nopagebreak%
\item \class{Fighter}
\item \class{Thief}
\item \class{Ranger}
\item \class{Bishop}
\item \class{Ninja}
\end{itemize}

\end{document}

If you look at its rendering, you should notice that my "Convenient Starting Professions" label is at page 1 but the list itself is at page 2, despite my desperate attempts to discourage the page break.

(I am using XeLaTeX.)

  • @JohnKormylo: I will try the stackengine solution of the question. One thing I see is different is that in my case, the itemize is wrapped with multicols. – wilx Jun 1 '16 at 13:45
  • The needspace approach should work if you make the space big enough, I have no idea about stackengine. – John Kormylo Jun 1 '16 at 21:11
2

Here's a way to avoid page breaks in the whole object:

\documentclass[12pt]{article}
\usepackage[a5paper]{geometry}
\usepackage{fontspec}
\usepackage{microtype}
\usepackage{multicol}
\usepackage[defaultlines=2,all]{nowidow}
\usepackage{ragged2e}
\usepackage{lipsum}
\usepackage{enumitem}
\usepackage{parskip}

\newcommand{\indexClass}[1]{\index{#1}}
\newcommand{\class}[1]{#1\indexClass{#1}}

\newenvironment{twocolumnitemize}[1]
 {%
  \par\noindent
  \begin{minipage}{\textwidth}
  \begin{multicols}{2}[#1]
  \raggedcolumns\RaggedRight
  \begin{itemize}
 }
 {%
  \end{itemize}
  \end{multicols}
  \end{minipage}
 }

\begin{document}
\lipsum[1-2]

\begin{twocolumnitemize}{Convenient Starting Professions}
\item \class{Fighter}
\item \class{Thief}
\item \class{Ranger}
\item \class{Bishop}
\item \class{Ninja}
\end{twocolumnitemize}

\lipsum[2]

\end{document}

enter image description here

By removing the minipage, you get possible page breaks only in the itemized list.

\documentclass[12pt]{article}
\usepackage[a5paper]{geometry}
\usepackage{fontspec}
\usepackage{microtype}
\usepackage{multicol}
\usepackage[defaultlines=2,all]{nowidow}
\usepackage{ragged2e}
\usepackage{lipsum}
\usepackage{enumitem}
\usepackage{parskip}

\newcommand{\indexClass}[1]{\index{#1}}
\newcommand{\class}[1]{#1\indexClass{#1}}

\newenvironment{twocolumnitemize}[1]
 {%
  \begin{multicols}{2}[#1]
  \raggedcolumns\RaggedRight
  \begin{itemize}
 }
 {%
  \end{itemize}
  \end{multicols}
 }

\begin{document}
\lipsum[1-2]

\begin{twocolumnitemize}{Convenient Starting Professions}
\item \class{Fighter}
\item \class{Thief}
\item \class{Ranger}
\item \class{Bishop}
\item \class{Ninja}
\end{twocolumnitemize}

\lipsum[2]

\end{document}

enter image description here

  • I guess I don't need to point this out, but your understanding of grouping is ridiculously sophisticated. Making multicols work for this question was not even on my radar. Very good answer. – A Feldman Jun 5 '16 at 15:03
  • @AFeldman I happened to remember the optional argument feature of multicols and tried. 😉 – egreg Jun 5 '16 at 15:06
  • After reading your answer I went back to multicol's documentation and found the parameter documented. I did not see it previous because I just skimmed the documentation. – wilx Jun 6 '16 at 7:48
1

Two Answers

1- For Short Lists

Using a \vtop box:

\documentclass[12pt]{article}
\usepackage[a5paper]{geometry}
\usepackage{fontspec}
\usepackage{microtype}
\usepackage{multicol}
\usepackage[defaultlines=2,all]{nowidow}
\usepackage{ragged2e}
\usepackage{lipsum}
\usepackage{enumitem}
\usepackage{parskip}

\tolerance=1000

\makeatletter
\newcommand{\indexClass}[1]{\index{#1}}
\newcommand{\class}[1]{#1\indexClass{#1}}
\makeatother

\newcommand{\WviiTwoColumnSetup}{\raggedcolumns\RaggedRight}

\SetEnumitemKey{WviiTwoColumn}{%
  before=\begin{multicols}{2}\WviiTwoColumnSetup,
  after=\end{multicols}}

\begin{document}
\lipsum[1-2]

\vtop{%

 Convenient Starting Professions%

  \begin{itemize}[WviiTwoColumn]%

     \item \class{Fighter}
     \item \class{Thief}
     \item \class{Ranger}
     \item \class{Bishop}
     \item \class{Ninja}

  \end{itemize}%
}

\end{document}

enter image description here

1- For Long Lists

Per the OP's stated use for very long lists to break over pages. This uses the longtable package:

\documentclass[12pt]{article}
\usepackage{longtable}
\usepackage{enumitem}
\usepackage{lipsum}

\def\It{\textbullet\hskip.2in}

\makeatletter
\newcommand{\indexClass}[1]{\index{#1}}
\newcommand{\class}[1]{#1\indexClass{#1}}
\makeatother

\begin{document}
     \lipsum[1-2]
        \begin{longtable}[l]{llll}

            \caption*{\bfseries\hskip1in Convenient Starting Professions}\\
               \multicolumn{4}{l}

                        \endfirsthead

        \It \class{Fighter} & \It \class{Bishop}\\
        \It \class{Thief} & \It \class{Ninja}\\     
        \It \class{Ranger} & ~\\
        \It \class{Fighter} & \It \class{Bishop}\\
        \It \class{Thief} & \It \class{Ninja}\\     
        \It \class{Ranger} & ~\\
        \It \class{Fighter} & \It \class{Bishop}\\
        \It \class{Thief} & \It \class{Ninja}\\     
        \It \class{Ranger} & ~\\
        \It \class{Fighter} & \It \class{Bishop}\\
        \It \class{Thief} & \It \class{Ninja}\\     
        \It \class{Ranger} & ~\\
        \It \class{Fighter} & \It \class{Bishop}\\
        \It \class{Thief} & \It \class{Ninja}\\     
        \It \class{Ranger} & ~\\
        \It \class{Fighter} & \It \class{Bishop}\\
        \It \class{Thief} & \It \class{Ninja}\\     
        \It \class{Ranger} & ~\\
        \It \class{Fighter} & \It \class{Bishop}\\
        \It \class{Thief} & \It \class{Ninja}\\     
        \It \class{Ranger} & ~\\
        \It \class{Fighter} & \It \class{Bishop}\\
        \It \class{Thief} & \It \class{Ninja}\\     
        \It \class{Ranger} & ~\\
        \It \class{Fighter} & \It \class{Bishop}\\
        \It \class{Thief} & \It \class{Ninja}\\     
        \It \class{Ranger} & ~\\
        \It \class{Fighter} & \It \class{Bishop}\\
        \It \class{Thief} & \It \class{Ninja}\\     
        \It \class{Ranger} & ~\\

        \end{longtable}

\end{document}

enter image description here

By using a \phantom the columns may be separated, for instance:

\It Fighter \phantom{\hskip2in} & \It Bishop\\

(only for the first entry) produces:

enter image description here

For a bit more room between the items a \strut can be added to the definition of \It, \def\It{\textbullet\hskip.2in{\Large\strut}} producing:

enter image description here

  • 1
    Thanks. However, while this works for this small list, I have other lists that are much bigger. Wouldn't putting them in \vtop force LaTeX to break the page early and leave me with half page of empty space? – wilx Jun 2 '16 at 5:32
  • Yes, that's definitely right. That is if the list is long enough to force the page to break. And another problem is that the \vtop will never be able to make a list that exceeds the page that it starts on. So it is not a great solution for longer lists. Maybe something using Stackengine ctan.org/tex-archive/macros/latex/contrib/stackengine?lang=en or even longtable ctan.org/pkg/longtable?lang=en might work better in this situation. – A Feldman Jun 2 '16 at 5:49
  • @wilx Added a longtable solution. – A Feldman Jun 5 '16 at 13:27

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.