3

Background

Similar questions have been asked before on this forum, but my question is a bit wider. The ultimate goal is to define an environment that is useful for automatic documentation of mathematical models and computer code combined with text and perhaps lots of pictures and tabulary data. Repetive contents are frequently encountered, which calls for a precise control of the spacing of the environment in order to avoid seemingly random vertical shifts in the typeset material. In particular these environments: equation, align, gather, table, figure, verbatim, enumerate, itemize, description, and (lst)listing. With precise control of the spacing I mean to e.g. be able to turn all spacing off.

Ideally, I want a LaTeX environment that can be used to wrap said environments, put a caption on the contents and write the information to a TOC file. The wrapper should furthermore exist in two versions: One that allows page breaks and another that treats the contents as a LaTeX float object. So, I am probably asking for two wrappers...

Is it possible to control LaTeX on this level of precision? I mean practically, not theoretically? I know that LaTeX is not made for grid typesetting but I use LaTeX for a lot of different writings and would like to give it a try.

Examples

To pin my question down, I have made a couple of working examples illustrating the situation using align* wrapped inside \begingroup...\endgroup and a user-defined environment called myfloat respectively. I have tried my best to eliminate all vertical spacing in the output, but there is a space between the caption and the align* environment that I cannot explain:

The effect of placing an <code>equation</code> caption outside and inside <code>myfloat</code>

Commenting in/out two lines at the bottom of the code, the example also works for itemize. In this case there is a space at the end of the itemize environment that I cannot explain:

The effect of placing an <code>itemize</code> list caption outside and inside <code>myfloat</code>

Note: The example(s) are meaningful for two different page geometries. One geometry that typeset the environments side-by-side on the same page (shown above) and a different geometry that typeset the environments (with column break) on two separate pages. To see the effect you have to comment in/out two lines of code in the preamble.

The code

  \documentclass[10pt,english]{article}

  \usepackage[utf8]{inputenc}
  \usepackage{multicol}
  \usepackage{caption}
  \usepackage{amsmath}
  \usepackage{float}
  \usepackage{enumitem}

% Page Layout
  \setlength{\topmargin}{0pt}
  \setlength{\topskip}{0pt}

% Paragraphs
  \setlength{\parindent}{0pt}
  \setlength{\parskip}{0pt}
  \setlength{\parsep}{0pt}
%
% https://tex.stackexchange.com/questions/188568/
% what-does-normallineskiplimit-do
%
% https://tex.stackexchange.com/questions/21676/
% an-equation-skip-problem-amsmath-package-and-above-belowdisplayskip/21694
%
% https://tex.stackexchange.com/questions/49072/
% is-changing-lineskiplimit-to-some-negative-value-a-good-idea-and-what-the-valu
%
  \setlength{\normallineskiplimit}{0pt}
  \setlength{\lineskiplimit}{0pt} 
  \setlength{\normalbaselineskip}{0pt}
  \setlength{\baselineskip}{0pt}
  \setlength{\normallineskip}{0pt}
  \setlength{\lineskip}{0pt}

% Floats
  \floatstyle{plaintop}
  \newfloat{myfloat}{H}{loe}
  \floatname{myfloat}{}
%
  \setlength{\floatsep}{0pt}
  \setlength{\textfloatsep}{0pt}
  \setlength{\intextsep}{0pt}
  \setlength{\dbltextfloatsep}{0pt}
  \setlength{\dblfloatsep}{0pt}
  \setlength{\abovecaptionskip}{0pt}
  \setlength{\belowcaptionskip}{0pt}

% Math
  \setlength{\abovedisplayskip}{0pt}
  \setlength{\belowdisplayskip}{0pt}
  \setlength{\abovedisplayshortskip}{0pt}
  \setlength{\abovedisplayskip}{0pt}
%
% https://tex.stackexchange.com/questions/69662/
% how-to-globally-change-the-spacing-around-equations
%
  \expandafter\def\expandafter\normalsize\expandafter{%
    \normalsize%
    \setlength{\abovedisplayshortskip}{0pt}%
    \setlength{\abovedisplayskip}{0pt}%
    \setlength{\belowdisplayshortskip}{0pt}%
    \setlength{\belowdisplayskip}{0pt}%
  }

% Lists
  \setlist{nolistsep}
%
  \setlength{\topsep}{0pt}
  \setlength{\partopsep}{0pt}
  \setlength{\itemsep}{0pt}

% ----------------------------------------------
% Environments typeset on separate pages
% ----------------------------------------------
% \usepackage[width=100mm,height=30mm]{geometry}

% ----------------------------------------------
% Environments typeset side-by-side on same page
% ----------------------------------------------
  \usepackage[width=100mm,height=60mm]{geometry}

% ----------------------------------------------
% Example table
% ----------------------------------------------
  \def\EQN{%
  \begin{align*}
    \allowdisplaybreaks
    f(x) & = e^{ix} \\
    f(x) & = e^{ix} \\
    f(x) & = e^{ix} \\
    f(x) & = e^{ix} \\
    f(x) & = e^{ix} \\
    f(x) & = e^{ix}
  \end{align*}
  }

% ----------------------------------------------
% Example list
% ----------------------------------------------
  \def\LST{%
  \begin{itemize}
    \item $ f(x) = e^{ix} $
    \item $ f(x) = e^{ix} $
    \item $ f(x) = e^{ix} $
    \item $ f(x) = e^{ix} $
    \item $ f(x) = e^{ix} $
    \item $ f(x) = e^{ix} $
    \item $ f(x) = e^{ix} $
    \item $ f(x) = e^{ix} $
  \end{itemize}
  }

% ----------------------------------------------
% Some text
% ----------------------------------------------
  \def\TXT{%
  Lorem ipsum dolor sit amet, 
  consectetur adipisicing elit, 
  sed do eiusmod tempor incididunt 
  ut labore et dolore magna aliqua. 
  }

\begin{document}
\begin{multicols}{2}
\raggedcolumns%
%
\begingroup
  \captionof*{myfloat}{Caption outside myfloat}%
  \allowdisplaybreaks%
  \EQN%
% \LST%
\endgroup
%
\TXT%
\vfill%
%
\begin{myfloat}[H]
  \caption*{Caption inside myfloat}%
  \EQN%
% \LST%
\end{myfloat}
%
\TXT%
\vfill%
%
\end{multicols}
\end{document}
Tore H-W
  • 493

0 Answers0