0

Related questions:

I am looking to create an environment which groups definitions for better legibility. Example:

\begin{gdefi}
\defi{Ring}{Some long description}
\defi{Homomorphism}{Some long description}
\end{gdefi}

The first argument to defi should create a column of uniform width (of the longest argument), with the remaining page-width taken up by the second argument. I would also like for this environment to break across pages for longer groups of definitions.

Illustration

Implementations I have tried:

  1. Create a two-column ltablex, as suggested here, but have been unable to get my document to compile. See below for a non-page-breaking version using tabularx.
  2. Create a description environment which, however, does not use visually separated columns. Using enumitem, I was able to tweak this somewhat by manually setting a fixed width for the left column. See below for a version using enumitem and a manually-specified width of the left column.

I much prefer approach #1, as it appears to be more more easily extendible. One extension I have in mind is creating different definition commands, each with its own formatting.

Example 1: A non-page-breaking version using tabularx

\documentclass[parskip=half-, DIV=12]{scrartcl}

\usepackage{xparse}
\usepackage{tabularx}
\usepackage{lipsum}

\newcolumntype{L}{>{\raggedright\arraybackslash}X}

\newif\ifingdefi

\newcommand{\defi}[2]{%
\ifingdefi%
\textbf{#1}:~&#2\\
\else%
\begin{tabularx}{\textwidth}{@{}l@{~}L@{}}
\textbf{#1}:~&#2\\%
\end{tabularx}%
\fi
}

\DeclareDocumentEnvironment{gdefi}{o}
{%
\ingdefitrue%
\tabularx{\textwidth}{@{}l@{~}L@{}}
}
{%
\endtabularx%
\ingdefifalse%
}

\begin{document}

% This environment should break across two pages
\begin{gdefi}
\defi{Def. 1}{\lipsum[1]}
\defi{Definition 2}{\lipsum[1]}
\defi{Definition 3}{\lipsum[1]}
\defi{Definition 4}{\lipsum[1]}
\defi{Definition 5}{\lipsum[1]}
\end{gdefi}

\end{document}

Example 2: An implementation using enumitem, which only works when manually specifying the width of the first column.

\documentclass[parskip=half-, DIV=12]{scrartcl}

\usepackage{xparse}
\usepackage{lipsum}

\newif\ifingdefi

\newcommand{\defi}[2]{%
\ifingdefi%
\item[#1] #2
\else%
\begin{description}
\item[#1] #2
\end{description}%
\fi
}

\DeclareDocumentEnvironment{gdefi}{o}
{%
\ingdefitrue%
\IfNoValueTF{#1}{%
\begin{description}
}{%
\begin{description}[#1]
}
}
{%
\end{description}
\ingdefifalse%
}

\usepackage{enumitem}

\begin{document}

\begin{gdefi}[leftmargin=10em,style=nextline]
  \defi{Def. 1}{\lipsum[1]}
  \defi{Definition 2}{\lipsum[1]}
  \defi{Definition 3}{\lipsum[1]}
  \defi{Definition 4}{\lipsum[1]}
  \defi{Definition 5}{\lipsum[1]}
\end{gdefi}

\end{document}
4
  • 1
    What about xltabular? Did you already try with this package?
    – leandriis
    Jan 3, 2020 at 10:09
  • 1
    Two general comments: Using a longtable-like approach (for example with xltabular) will only introduce page breaks inbetween two Definitions, not within the text of one definition. Depending on the length of the corresponding texts, this might lead to quite large white spaces. Depending on the length of the longest term in the first column compared to the other term, there will be huge amounts of white space and a large separation between the term and its definition text.
    – leandriis
    Jan 3, 2020 at 10:16
  • 1
    Using a description-like approach would on the other hand enable page breaks within description texts. Personally, I would stick to a standard definition environment only slightly indenting the second an dfollowing lines of the respective definition. To add more visual separation between consecutive items, you could also introduce a small vertical white space between them using the itemsep option.
    – leandriis
    Jan 3, 2020 at 10:17
  • @leandriis Thank you for your helpful comments. xltabular indeed works the way I want it to. I will also look into your suggestion of a customized description environment, I certainly see the appeal of this approach.
    – Julian
    Jan 3, 2020 at 18:43

1 Answer 1

0

As suggested by leandriis, the xltabular packages works well:

  • Auto-fits the size of the left column
  • Breaks across pages

Working example for approach #1 in my question:

\documentclass[parskip=half-, DIV=12]{scrartcl}

\usepackage{xparse}
\usepackage{xltabular}
\usepackage{lipsum}

\newcolumntype{L}{>{\raggedright\arraybackslash}X}

\newif\ifingdefi

\newcommand{\defi}[2]{%
\ifingdefi%
\textbf{#1}:~&#2\\
\else%
\xltabular{\textwidth}{@{}l@{~}L@{}}
\textbf{#1}:~&#2\\%
\endxltabular
\fi
}

\DeclareDocumentEnvironment{gdefi}{o}
{%
\ingdefitrue%
\xltabular{\textwidth}{@{}l@{~}L@{}}
}
{%
\endxltabular
\ingdefifalse%
}

\begin{document}

\begin{gdefi}
\defi{Def. 1}{\lipsum[1]}
\defi{Definition 2}{\lipsum[1]}
\defi{Definition 3}{\lipsum[1]}
\defi{Definition 4}{\lipsum[1]}
\defi{Definition 5}{\lipsum[1]}
\end{gdefi}

\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .