1

I currently have a table that has grown a bit and no longer fits its intended space. Since I expect this table to keep growing in the future, I need to make it page-breakable while keeping its current style. There are many posts out there on how to get page-breakable tables, but I have not been able to use any of the solutions I have found because I either got errors I could not wrap my head around, or the final output did not look as intended.

I share below a MWE which shows my current (non-breakable) table as well as a screenshot of the output it produces. What the MWE does is create a list environment which I then invoke whenever necessary. My goal is to replicate this output but making sure that the table will correctly break (rather than jump) whenever it reaches a page break.

\documentclass[a4paper]{article}

\begin{document}

\newenvironment{entrylist}{%
  \noindent
  \begin{tabular*}{\textwidth}{@{\extracolsep{\fill}}rl}
}{%
  \end{tabular*}
}
\newcommand{\entry}[4]{%
    \parbox[t]{1.75cm}{#1\raggedleft}&\parbox[t]{\dimexpr\textwidth-2\tabcolsep-1.75cm}{\strut%
    \textbf{#2}%
    \hfill%
    {\footnotesize #3\par\strut}%
    #4\vspace{\parsep}%
  }\\}

\begin{entrylist}

  \entry
    {XXXX}
    {Fancy stuff 1}
    {Fancy stuff 1}
    {Fancy stuff 1}

  \entry
    {YYYY}
    {Fancy stuff 2}
    {Fancy stuff 2}
    {Fancy stuff 2}

  \entry
    {ZZZZ}
    {Fancy stuff 3}
    {Fancy stuff 3}
    {Fancy stuff 3}
    
\end{entrylist}

\end{document}

enter image description here

Thank you all very much for your time.

3 Answers 3

2

You need not encapsulate the whole stuff into tabular environment. You can define format of each \entry by your macros. The \smallskip after \hbox is page-breakable, of course.

\newdimen\colsep \colsep=1em
\def\topbox#1#2{\vtop{\parindent=0pt \hsize=\dimexpr#1\relax #2}}
\def\entry#1#2#3#4{\par
   \hbox{\topbox{1.75cm}{#1\raggedleft}\kern\colsep
         \topbox{\hsize-2\colsep-1.75cm}{{\bf#2}\hfill {\footnotesize#3}\endgraf#4\strut}}
   \smallskip
}

  \entry
    {XXXX}
    {Fancy stuff 1}
    {Fancy stuff 1}
    {Fancy stuff 1}

  \entry
    {YYYY}
    {Fancy stuff 2}
    {Fancy stuff 2}
    {Fancy stuff 2}

  \entry
    {ZZZZ}
    {Fancy stuff 3}
    {Fancy stuff 3}
    {Fancy stuff 3}
1
  • Thank you very much for your answer: it provides a very elegant solution to the problem at hand. Hence, I have decided to accept it. However, I am not entirely sure I should do this, since Mico's and egreg's answers do answer my specific question while yours does not answer it but provides a better approach to the problem instead. Thank you!
    – EoDmnFOr3q
    Commented Apr 13, 2022 at 16:26
2

I think all you need to do is

  • load the longtable package and issue the instructions \setlength\LTleft{0pt} and \setlength\LTright{0pt} in the preamble and

  • replace \begin{tabular*}{\textwidth} with \begin{longtable} and \end{tabular*} with \end{longtable} in the definition of the entrylist environment.

Optionally, you could delete the \noindent directive at the start of the definition of the entrylist environment.

See section 5, entitled "Adjustment", of longtable user guide for more information about what the length parameters \LTleft and \LTright do.

1
  • Thank you very much for your answer. Please, see my comment under wipet's answer to see why I have accepted his/her answer (despite my doubts on what I should do).
    – EoDmnFOr3q
    Commented Apr 13, 2022 at 16:27
1

Use longtable.

\documentclass[a4paper]{article}
\usepackage{longtable,array}

\usepackage{lipsum} % for nonsense text
\usepackage{showframe} % for showing the page boundaries

\newlength{\entrylistwidth}
\setlength{\entrylistwidth}{1.75cm}
\newenvironment{entrylist}{%
  \begin{longtable}{
    @{}
    w{l}{\entrylistwidth}
    p{\dimexpr\textwidth-2\tabcolsep-\entrylistwidth}
    @{}
  }
}{\end{longtable}}

\newcommand{\entry}[4]{%
  #1 & \textbf{#2}\hfill{\footnotesize #3\par}#4\\\noalign{\vspace{\parsep}}%
}

\begin{document}

\begin{entrylist}

  \entry
    {XXXX}
    {Fancy stuff 1}
    {Fancy stuff 1}
    {\lipsum[1][1-3]}

  \entry
    {YYYY}
    {Fancy stuff 2}
    {Fancy stuff 2}
    {\lipsum[2][1-3]}

  \entry
    {ZZZZ}
    {Fancy stuff 3}
    {Fancy stuff 3}
    {\lipsum[3][1-3]}
    
  \entry
    {ZZZZ}
    {Fancy stuff 3}
    {Fancy stuff 3}
    {\lipsum[3][1-3]}
    
  \entry
    {ZZZZ}
    {Fancy stuff 3}
    {Fancy stuff 3}
    {\lipsum[3][1-3]}
    
  \entry
    {ZZZZ}
    {Fancy stuff 3}
    {Fancy stuff 3}
    {\lipsum[3][1-3]}
    
  \entry
    {ZZZZ}
    {Fancy stuff 3}
    {Fancy stuff 3}
    {\lipsum[3][1-3]}
    
  \entry
    {ZZZZ}
    {Fancy stuff 3}
    {Fancy stuff 3}
    {\lipsum[3][1-3]}
    
  \entry
    {ZZZZ}
    {Fancy stuff 3}
    {Fancy stuff 3}
    {\lipsum[3][1-3]}
    
  \entry
    {ZZZZ}
    {Fancy stuff 3}
    {Fancy stuff 3}
    {\lipsum[3][1-3]}
    
  \entry
    {ZZZZ}
    {Fancy stuff 3}
    {Fancy stuff 3}
    {\lipsum[3][1-3]}
    
  \entry
    {ZZZZ}
    {Fancy stuff 3}
    {Fancy stuff 3}
    {\lipsum[3][1-3]}
    
  \entry
    {ZZZZ}
    {Fancy stuff 3}
    {Fancy stuff 3}
    {\lipsum[3][1-3]}
    
  \entry
    {ZZZZ}
    {Fancy stuff 3}
    {Fancy stuff 3}
    {\lipsum[3][1-3]}
    
  \entry
    {ZZZZ}
    {Fancy stuff 3}
    {Fancy stuff 3}
    {\lipsum[3][1-3]}
    
  \entry
    {ZZZZ}
    {Fancy stuff 3}
    {Fancy stuff 3}
    {\lipsum[3][1-3]}
    
  \entry
    {ZZZZ}
    {Fancy stuff 3}
    {Fancy stuff 3}
    {\lipsum[3][1-3]}
    
  \entry
    {ZZZZ}
    {Fancy stuff 3}
    {Fancy stuff 3}
    {\lipsum[3][1-3]}
    
  \entry
    {ZZZZ}
    {Fancy stuff 3}
    {Fancy stuff 3}
    {\lipsum[3][1-3]}
    
  \entry
    {ZZZZ}
    {Fancy stuff 3}
    {Fancy stuff 3}
    {\lipsum[3][1-3]}
    
  \entry
    {ZZZZ}
    {Fancy stuff 3}
    {Fancy stuff 3}
    {\lipsum[3][1-3]}
    
  \entry
    {ZZZZ}
    {Fancy stuff 3}
    {Fancy stuff 3}
    {\lipsum[3][1-3]}
    
  \entry
    {ZZZZ}
    {Fancy stuff 3}
    {Fancy stuff 3}
    {\lipsum[3][1-3]}
    
\end{entrylist}

\end{document}

enter image description here

4
  • Thank you for your answer. It is almost what I need: the only problem is that the contents of the left column (i.e., "XXXX", "YYYY", "ZZZZ") should be left ragged left. I can't find a way to tweak your code such that they are ragged left. Any hint?
    – EoDmnFOr3q
    Commented Apr 12, 2022 at 21:30
  • 1
    @Hector If you have longer entries for the first column that should be split across lines, change w{l}{\entrylistwidth} into >{\raggedright}p{\entrylistwidth}
    – egreg
    Commented Apr 12, 2022 at 21:40
  • Thank you very much for your further comment. Please, see my comment under wipet's answer to see why I have accepted his/her answer (despite my doubts on what I should do).
    – EoDmnFOr3q
    Commented Apr 13, 2022 at 16:27
  • 1
    @Hector I'd say that mixing plain TeX style with LaTeX is not the best idea, if you don't know the subtleties. Anyway, the choice is yours.
    – egreg
    Commented Apr 13, 2022 at 16:43

You must log in to answer this question.

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