1

I have built a command \dateentry which places two minipages next to each other. For some reason, the vertical space between the entries is not consistent. The spacing seems to be larger when it is surrounding an entry whose minipage on the right only contains one line. Why is that and how would I fix this behaviour so that the vertical spacing between the entries is always the same?

MWE as an image

MWE:

\documentclass[
    12pt,
    parskip=half,
]{scrartcl}
\usepackage[
    a4paper,
    left=25mm,
    right=20mm,
    top=25mm,
    bottom=30mm,
    showframe,
]{geometry}
\usepackage{blindtext}

% Font \usepackage{inconsolata} \usepackage[T1]{fontenc} \renewcommand*\familydefault{\sfdefault} %% Only if the base font of the document is to be sans serif

% Date-Entry-Command \newcommand{\dateentry}[2]{

\begin{minipage}[c]{.15\linewidth}
    \hfill#1
\end{minipage}
    \hfill\vline\hfill
\begin{minipage}{.80\linewidth}
    #2
\end{minipage}
\\

}

\begin{document} \dateentry{20XX -- 20YY}{ \textbf{Title} \ \textit{italic text}, \footnotesize{small text} } \dateentry{20XX -- 20YY}{ \textbf{Title} \ \textit{italic text}, \footnotesize{small text} } \dateentry{20XX -- 20YY}{ \textbf{Title} } \dateentry{20XX -- 20YY}{ \textbf{Title} } \dateentry{20XX -- 20YY}{ \textbf{Title} } \dateentry{20XX -- 20YY}{ \textbf{Title} \ \textit{italic text}, \footnotesize{small text} } \dateentry{20XX -- 20YY}{ \textbf{Title} \ \textit{italic text}, \footnotesize{small text} } \dateentry{20XX -- 20YY}{ \textbf{Title} \ \textit{italic text}, \footnotesize{small text} \blindtext } \end{document}

David Carlisle
  • 757,742
Hanns
  • 33
  • I think it's because LaTeX tries it's best to fill the page. You can approach this a few ways. Predefine your space between blocks with vspace, use vfill to creat equal space and still fill the page, or use raggedbottom. – likethevegetable Oct 03 '22 at 15:46
  • I observe that, except when the right-hand element is more than two lines long, the elements in the left-hand column are all the same distance apart. But since the vertical rule separating the columns is the height of the text in the second column, it doesn't appear that the extra space is the result of a minimum fixed height being applied to either of the minipages. – barbara beeton Oct 15 '22 at 23:46

2 Answers2

1

There are several things going on here. The first one is that your definition of \dateentry has some (probably) unintended artifacts, namely spurious spaces and extra line breaks (because of \\ in addition to \par (the empty line); you probably want just \par). Let's clean that up.

\newcommand\dateentry[2]{%
  \par
  \begin{minipage}[c]{.15\linewidth}%
    \hfill#1%
  \end{minipage}%
    \hfill\vline\hfill
  \begin{minipage}{.80\linewidth}%
    #2%
  \end{minipage}%
  \par
}

(It could be improved further, but that's not relevant for this question.)

Now, for clarity, let's also remove the parskip (and set \parindent to zero to avoid overfull boxes) and look at the result.

\documentclass[
    12pt,
%    parskip=half,
  ]{scrartcl}

\usepackage[ a4paper, left=25mm, right=20mm, top=25mm, bottom=30mm, showframe, ]{geometry} \usepackage{blindtext}

% Font \usepackage{inconsolata} \usepackage[T1]{fontenc} \renewcommand*\familydefault{\sfdefault} %% Only if the base font of the document is to be sans serif

% Date-Entry-Command \newcommand\dateentry[2]{% \par \begin{minipage}[c]{.15\linewidth}% \hfill#1% \end{minipage}% \hfill\vline\hfill \begin{minipage}{.80\linewidth}% #2% \end{minipage}% \par }

\setlength\parindent{0pt}

\begin{document}

\dateentry{20XX -- 20YY}{ \textbf{Title} \ \textit{italic text}, \footnotesize{small text} } \dateentry{20XX -- 20YY}{ \textbf{Title} \ \textit{italic text}, \footnotesize{small text} } \dateentry{20XX -- 20YY}{ \textbf{Title} } \dateentry{20XX -- 20YY}{ \textbf{Title} } \dateentry{20XX -- 20YY}{ \textbf{Title} } \dateentry{20XX -- 20YY}{ \textbf{Title} \ \textit{italic text}, \footnotesize{small text} } \dateentry{20XX -- 20YY}{ \textbf{Title} \ \textit{italic text}, \footnotesize{small text} } \dateentry{20XX -- 20YY}{ \textbf{Title} \ \textit{italic text}, \footnotesize{small text} \blindtext }

\rule{1em}{9pt} \textbf{Title}

\rule{1em}{9pt}

\rule{1em}{9pt}

\rule{1em}{20pt}

\rule{1em}{20pt}

\rule{1em}{20pt}

\rule{1em}{9pt}

\rule{1em}{9pt}

\rule{1em}{9pt}

\end{document}

MWE output

As you can see, there are still differences. Those are due to the fact the the single-line boxes are smaller than \baselineskip (so the distance between their base lines is \baselineskip) while the multi-line boxes are higher (so the distances between the boxes is \lineskip). That is true in general, as illustrated by the boxes I added to the MWE.

In order to fix this, you could just give the boxes a minimal height and depth (e.g. including a \rule[-.2\baselineskip]{0pt}{\baselineskip}), but I'd recommend using a package like tcolorbox for your boxes that provides more sophisticated options.

schtandard
  • 14,892
0

Here an alternative approach is proposed.

Instead of dealing with the cumbersome vertical spacing (see schtandard answer) of minipages, it is proposed to use the tikz package for precise positioning and alignment.

The tikz macro consists of three lines:

(1) the node named dates is typeset;

(2) the node named title is typeset some distance to the right of dates, with its content left-aligned and within a 0.75\linewidth box; and

(3) a vertical line is drawn on the left ("west") side of title.

Finally the paragraph is ended and an optional vertical space might be added.

As can be seen, all the distances between the ends of the consecutive vertical lines are equal.

p

Note: \footnotesize is not an environment or a command, but a declaration, like a switch: will put the following text in this size.

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

\usepackage[ a4paper, left=25mm, right=20mm, top=25mm, bottom=30mm, showframe, ]{geometry} \usepackage{blindtext}

% Font \usepackage{inconsolata} \usepackage[T1]{fontenc} \renewcommand*\familydefault{\sfdefault} %% Only if the base font of the document is to be sans serif

% *************************************** changed \usepackage{tikz} \usetikzlibrary{positioning}

\newcommand\dateentry[2]{% \begin{tikzpicture} \node(dates) {#1}; \node(title)[right=0.2cm of dates, align=left, text width=0.75\linewidth]{#2}; \draw[thick] (title.south west)--(title.north west); \end{tikzpicture} \par% end of previous paragraph %\vspace{1ex}% optional vertical space in between } %********************************************************

\begin{document}

\dateentry{20XX -- 20YY}{
\textbf{Title} \\
\textit{italic text},  \footnotesize small text

} \dateentry{20XX -- 20YY}{ \textbf{Title} \ \textit{italic text}, \footnotesize small tex } \dateentry{20XX -- 20YY}{ \textbf{Title} \ } \dateentry{20XX -- 20YY}{ \textbf{Title}\ } \dateentry{20XX -- 20YY}{ \textbf{Title}\ } \dateentry{20XX -- 20YY}{ \textbf{Title} \ \textit{italic text}, \footnotesize small text } \dateentry{20XX -- 20YY}{ \textbf{Title} \ \textit{italic text}, \footnotesize small text } \dateentry{20XX -- 20YY}{ \textbf{Title} \ \textit{italic text}, \footnotesize small text \blindtext }

\end{document}

UPDATE after follow-up question

A tabularx will handle a situation with cells of different sizes, right of left column. The line will take the height of the tallest cell.

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

\usepackage[ a4paper, left=25mm, right=20mm, top=25mm, bottom=30mm, showframe, ]{geometry} \usepackage{blindtext}

% Font \usepackage{inconsolata} \usepackage[T1]{fontenc} \renewcommand*\familydefault{\sfdefault} %% Only if the base font of the document is to be sans serif

%**************************************** added <<<<<<<<<<<<<<<<<<<<< \usepackage{ragged2e} \usepackage{tabularx} \newcolumntype{P}[1]{>{\RaggedRight}m{#1}} \renewcommand{\tabularxcolumn}[1]{m{#1} } \setlength{\extrarowheight}{6pt} % add extra space between rows \setlength{\tabcolsep}{8pt} % twice the space before and after the column

\newcommand\dateentry[2]{% ********* changed <<<<<<<<<<<< \begin{tabularx}{\textwidth}{P{0.2\textwidth}|X}
#1& #2 \ \end{tabularx} \par% end of previous paragraph % \vspace{1ex}% optional vertical space in between } %********************************************************

\begin{document}

\dateentry{20XX -- 20YY}{\textbf{Title} \newline \textit{italic text},  \footnotesize small text}
\dateentry{\textbf{Title} \newline \textit{italic text},  \footnotesize small tex}{20XX -- 20YY}
\dateentry{20XX -- 20YY}{\textbf{Title}}
\dateentry{\textbf{Title} \newline  \textit{italic text},  \footnotesize small text }{  20XX -- 20YY}       
\dateentry{20XX -- 20YY}{   \textbf{Title} \newline \textit{italic text},  \footnotesize small text }
\dateentry{20XX -- 20YY}{   \textbf{Title} \newline \textit{italic text},  \footnotesize    \blindtext  }
\dateentry{\textbf{Title} \newline  As any dedicated reader can clearly see, the Ideal of
    practical reason is a representation of, as far as I know, the things
    in themselves; as I have shown elsewhere}{\textbf{Title} \newline \itshape  Let us suppose that the noumena have nothing to do
    with necessity, since knowledge of the Categories is a
    posteriori.
}

\end{document}

zz

Simon Dispa
  • 39,141
  • What if the left node has a bigger height than the right node? How would I get the vertical line to always have the height of the tallest node, without another line on top of it? So in short: How do I compare the height of both nodes and draw the vertical line from different points depending on which node is higher? Or is there a way to make the two nodes have the same height, while also maintaining the vertically centered text? – Hanns Oct 15 '22 at 09:24
  • @Hanns tikzworks by placing content in "boxes" and placing them very precisely relative to each other. This allows to work around the issue in your question about variable vertical spacing between inputs.

    As you saw, the code is very simple and was meant to solve your specific question. The implicit assumption is that the title will be equal to or larger than the date, so here the line is always drawn on the left side of the title box.

    There are many approaches to having a layout with "cells" of different sizes and a line down the middle. I suggest asking another question.

    – Simon Dispa Oct 15 '22 at 21:16