Graphics, Figures & TablesLongtable : Cell jumps current page and exceeds the page after

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
Akexandre
Posts: 9
Joined: Thu Mar 26, 2020 3:31 am

Longtable : Cell jumps current page and exceeds the page after

Post by Akexandre »

Hello guys

I'm a beginner and I'm using Overleaf for making a CV 8-)

Here my issue :
I want something like an array with Column left date and Colomn right the related tasks (and over things inside like List / custom parbox / etc : so containt is really big).

It appears by using this approach, the column left is nicely sized but if the right cell has a bad behaviorand disappearsby exceeding the page from bottom.

Here the code to better explain with lipsum to fill in with big amount of data :

Code: Select all

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{longtable}
\usepackage{lipsum}

\begin{document}

    \begin{longtable}[c]{| c | p{5cm} |}
        \hline 
        2019 - 2020 & Test
        \hline
        2019 - 2020 & \lipsum
        \hline 
        2019 - 2020 & Test
        \hline 
    \end{longtable}
\end{document}
This is simple but I do not find after hours and hours comparing 150 different CV how to solve this (even if it's possible). :shock:

I'm opened to any idea about this issue or if you have a better design to suggest, I would be happy to better understand and improve my comprehension about this.

Thank you very much for helping me :)

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

Ijon Tichy
Posts: 640
Joined: Mon Dec 24, 2018 10:12 am

Longtable : Cell jumps current page and exceeds the page after

Post by Ijon Tichy »

Your example is not working, because of the missing \\ or \tabularnewline at the end of the table rows. However, I don't think, that this is your main problem. You main problem is, that longtable does not provide page breaks inside a table cell but only after table rows. If you really need page breaks everywhere, you can use a list instead of a table. Lists provide page breaks almost everywhere. But lists do not provide vertical rules/lines. However you should always avoid vertical rules, because they decline the readability.
\documentclass{article}
\usepackage[utf8]{inputenc}% not needed since LaTeX 2018-04-01
\usepackage{lipsum}
\usepackage{scrextend}% provides labeling environment

\begin{document}

\begin{labeling}{2019--2020}% the argument is a length pattern
\item[2019--2020] Test
\item[2019--2020] \lipsum
\item[2019--2020] Test
\end{labeling}
\end{document}
If you really need the ugly boxed layout, you have to do the page breaks manually by splitting the related table cell to two table rows:
\documentclass{article}
\usepackage{xltabular}% combination of longtable and tabularx
\usepackage{lipsum}

\begin{document}

\begin{xltabular}{\linewidth}{|c|X|}% combination of longtable and tabularx
    \hline 
    2019--2020 & Test \\
    \hline
    2019--2020 & \lipsum[1-4] \\% splitted to allow page break
               & \lipsum[5-7] \\% continue
    2019--2020 & Test \\
    \hline 
\end{xltabular}
\end{document}
Sorry, but I can no longer participate here as the administrator is trampling on my wishes on one of his other platforms. :cry:
Akexandre
Posts: 9
Joined: Thu Mar 26, 2020 3:31 am

Longtable : Cell jumps current page and exceeds the page after

Post by Akexandre »

Thank you very much for responding so quickly :shock:

I like the first approach and It sounds to fit the expected layout I'm looking for ;)

So I'm going to play with labelling and scrextend

Have a very good day and take care of you (especially during this period)
Akexandre
Posts: 9
Joined: Thu Mar 26, 2020 3:31 am

Longtable : Cell jumps current page and exceeds the page after

Post by Akexandre »

Hello

May I ask you a quick question related to the useful example you provide ? (with labeling)
I'm going to use it mutlitple time but I would like to have the same size on multiple instance

Here my question : do we have something like variable where I can set a size and I'll use it each time ?

Instead of this :

Code: Select all

\begin{labeling}{2019--2020}
\end{labeling}

\begin{labeling}{2019}
\end{labeling}

\begin{labeling}{2019 - 2018 - 2020}
\end{labeling}
to have something like this :

Code: Select all

$variable = 3cm (or a define ?)
 
\begin{labeling}{$variable}
\end{labeling}

\begin{labeling}{$variable}
\end{labeling}

\begin{labeling}{$variable}
\end{labeling}
It will align the 3 labeling with the same size (if not possible, I'll take the longest text). But I would like to know best practise, that's why I'm asking you help ;)

Thank you for helping me :)
User avatar
Ijon Tichy
Posts: 640
Joined: Mon Dec 24, 2018 10:12 am

Longtable : Cell jumps current page and exceeds the page after

Post by Ijon Tichy »

You can use \newenvironment{cv}{\labeling{2019--2020}}{\endlabeling} in your document preamble and then use

Code: Select all

\begin{cv}
\item[2018] …
\item[2019--2020]…
\end{cv}
One of the advantages of LaTeX is, that you can define your own commands and enviroments using already existing commands and environment (or the commands, that are used to begin and end existing environment). And it is recommended to do so to improve the separation of form and content. Whenever you need code more than once, it is a good idea to ask yourself: Is is a good idea to define a command or environment for this.

Hint: To set a width of 3cm you can use \hspace{3cm} as pattern. But this will not give exactly 3cm, because the label separation will be added additionally.

BTW: There are other package, that can be used to define a new type of list, e.g., enumitem, Using scrextend's labeling environment was only a easy and quick suggestion.
Sorry, but I can no longer participate here as the administrator is trampling on my wishes on one of his other platforms. :cry:
Akexandre
Posts: 9
Joined: Thu Mar 26, 2020 3:31 am

Longtable : Cell jumps current page and exceeds the page after

Post by Akexandre »

Hello Ijon Tichy

This is absolutely perfect. The example you gave to me cover exactly the expected result and your additional information gaves me opportunity to reach the next level of my CV (with newenv).

I would like to thank you for your help

Have a very good evening :)
Post Reply