6

I have the following problem.

Let's define three types of document elements: Titles, Paragraphs and Longtables. The problem is to setup vertical spaces between them independently.

For example, let's denote:

  • Vertical space #1 between Titles and Paragraphs.
  • Vertical space #2 between Titles and Longtables.
  • Vertical space #3 between Paragraphs and Titles.
  • Vertical space #4 between Paragraphs and Longtables.
  • Vertical space #5 between Longtables and Titles.
  • Vertical space #6 between Longtables and Paragraphs.

The general problem is to set: vspace #1 to V1 cm, vspace #2 to V2 cm, ... , vspace #6 to V6 cm. This should be done in preambula to minimize author's efforts in the document part.

Since this problem was too hard for me, I've tried to solve its particular case where V1 = V2 = ... = V6 = 1cm, i.e. all the vertical spaces #1-#6 are the same.

I've managed to find the following variables that affect these vspaces:

\captionsetup[longtable]{
  belowskip=1cm          % VARIABLE #1
}
\setlength{\LTpre}{1cm}  % VARIABLE #2
\setlength{\LTpost}{1cm} % VARIABLE #3
\titlespacing*{\section}{0pt}{1cm}{1cm} % VARIABLES #4, #5

As I've found out, these variables affect:

  • belowskip - vspaces 2, 4.
  • LTpre - vspaces 2, 4.
  • Ltpost - vspaces 5, 6.
  • titlespacing-3 - vspaces 3, 5.
  • titlespacing-4 - vspaces 1, 2.

You can easily make sure that it is impossible to chose a subset of these variables so that each vspace is covered one and only one time.

Do you have any ideas how to solve this problem (in general or at least in the particular case)?

Here is the code.

\documentclass{book}
\usepackage{titlesec}
\usepackage{longtable}
\usepackage{caption}
\usepackage{lipsum}

\captionsetup[longtable]{
  belowskip=1cm          % VARIABLE #1
}
\setlength{\LTpre}{1cm}  % VARIABLE #2
\setlength{\LTpost}{1cm} % VARIABLE #3
\titlespacing*{\section}{0pt}{1cm}{1cm} % VARIABLES #4, #5


\begin{document}

\section {Title title title title title title}

% Vertical space #1: Title - Paragraph

\lipsum[2] % Paragraph

% Vertical space #3: Paragraph - Title

\section {Title title title title title title}

% Vertical space #2: Title - Longtable

\begin{longtable}{|c|}
  \caption{Table Table Table Table Table Table}\\  
  \hline Something \\ \hline
\end{longtable}   

% Vertical space #6: Longtable - Paragraph

\lipsum[2] % Paragraph

% Vertical space #4: Paragraph - Longtable  

\begin{longtable}{|c|}
  \caption{Table Table Table Table Table Table}\\  
  \hline Something \\ \hline
\end{longtable}   

% Vertical space #5: Longtable - Title 

\section {Title title title title title title}

\end{document}

1 Answer 1

4

I fear the answer is like you indicate: LaTeX2e has only fairly limited functionality when it comes to defining spacing between different objects. Largely it relies on using \addvspace which results in using the maxium of two spaces in a row (from the end of one element and the beginning of a second one). But even there, not all elements use \addvspace but sometimes straight \vspace or \vskip with the result that those spaces then accumulate.

In addition to that LaTeX2e understands about sectional units that come in a row and adjusts the spacing there but that's about it. On the whole that simple scheme works fairly well, but it doesn't help you if you want/need to define precise spacing rules between different elements.

For the latter to be possible LaTeX would need to keep track of the document structure to an extend it currently doesn't. For example, paragraphs are more or less implicit objects so by looking at the begin/end structure alone is not enough.

In the LaTeX3 project we are experimenting with specification possibilities that would allow you do do precisely what you are interested in, but unfortunately that is not yet in a state that I would consider usable. It may however be interesting to look at and even experiment with depending on the application you are doing: http://www.latex-project.org/svnroot/experimental/trunk/l3trial/l3ldb/ --- we are certainly interested in feedback.

You will also find some demonstration and comments about it in the talk I gave last year in India.

4
  • Then maybe the clue is to somehow patch Titles and Longtables? Unfortunately I'm not familiar with this technique to be able to propose any certain solutions. PS: Your second link seems to be the same as the first one. Mar 30, 2012 at 17:36
  • my point is that there isn't a simple way of patching titles or longtables as there is no underlying mechanism to detect if the longtable happens directly after a title or there is something inbetween like a paragraph of text. Theoretically, that is possible of course, but 2e doesn't have the necessary basics -> you would need to basically program all of that. (link fixed) Mar 30, 2012 at 17:47
  • But LaTeX has a mechanism to detect and eliminate double vertical spaces. What if we try to use it for the problem described above? LaTeX 3 would possibly provide more convinient ways to cope with the problem. But the fact is that currently LaTeX 3 is unusable. Mar 30, 2012 at 22:39
  • @IvanBychkov latex2e (and previous versions, actually) doesn't have general mechanisms, actually -- to first order, \addvspace is the only thing it has, and that turns up in all sorts of places in the code of various functions. Nov 21, 2014 at 9:20

You must log in to answer this question.

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