1

I'm new in [tex.se] and I want to ask you how do I correct the problem I have with this snippet:

\section{Latex meltdown my brain!!!}

This longtable table shows a weird behaviour. If I don't use a minipage, the result doesn't show as I want

I show you various problems I've encountered mixing the 3 variants: equal size, one more than another, and viceversa.

\begin{longtable}{@{} p{0.48\textwidth} p{0.48\textwidth} @{}}
\rowcolor[HTML]{C0C0C0} 
Column fine & Column with problems \\
BLABLA BLABLABLA BLABLA BLABLABLA BLABLABLA BLABLA BLA                             & \par\begin{minipage}{0.48\textwidth} In eget tortor libero. Duis vulputate scelerisque. \\ Etiam nec ornare nisi, eu semper augue \end{minipage}\\
\rowcolor[HTML]{EFEFEF} 
BLABLA BLABLABLA BLABLA BLABLABLA BLABLA BLA                                       & \par\begin{minipage}{0.48\textwidth} Integer condimentum elit a finibus. \\ Praesent sed vestibulum sapien. \\ Donec molestie eros nulla, et finibus urna ut. \\ Morbi at malesuada erat. \end{minipage}\\
BLABLA BLABLABLA BLABLA BLABLABLA BLABLABLA BLABLA BLA BLABLA BLABLABLA BLABLA BLA & \par\begin{minipage}{0.48\textwidth} Praesent sit amet condimentum lectus: \\ Butvitae dignissim sem tortor ut dolor \end{minipage}\\
\end{longtable}

\clearpage

This code, when I use XeTeX and nice fonts, output this:

The problem shows here!

The packages I used for minimal compiling this snippet are the follows (it could be compiled without most of them, I don't tested with less packages):

\usepackage{tikz}
\usepackage{verbatim}
\usepackage{graphicx}
\usepackage[utf8]{inputenc}
\usepackage{color}
\usepackage{longtable}
\usepackage{colortbl}

\usepackage{kpfonts}
\usepackage[explicit]{titlesec}
\usepackage{fontspec}

The document type is a:

\documentclass[svgnames]{book}

I've tried to change \par with \noindent prior to \begin{minipage}, with no noticeable changes.

I've tried using the solution approach commented here: Problem with balancing multicols with minipage inside but it doesn't work, too.

The question is: What I type into the longtable table or in the minipages to look with correct spacing in the upper and lower parts of the cell?

The minimal compilable document is:

\documentclass[svgnames]{book}
\usepackage{tikz}
\usepackage{verbatim}
\usepackage{graphicx}
\usepackage[utf8]{inputenc}
\usepackage{color}
\usepackage{longtable}
\usepackage{colortbl}

\usepackage{kpfonts}
\usepackage[explicit]{titlesec}
\usepackage{fontspec}

\begin{document}

    \section{Latex meltdown my brain!!!}

    This longtable table shows a weird behaviour. If I don't use a minipage, the result doesn't show as I want

    I show you various problems I've encountered mixing the 3 variants: equal size, one more than another, and viceversa.

    \begin{longtable}{@{} p{0.48\textwidth} p{0.48\textwidth} @{}}
    \rowcolor[HTML]{C0C0C0} 
    Column fine & Column with problems \\
    BLABLA BLABLABLA BLABLA BLABLABLA BLABLABLA BLABLA BLA                             & \par\begin{minipage}{0.48\textwidth} In eget tortor libero. Duis vulputate scelerisque. \\ Etiam nec ornare nisi, eu semper augue \end{minipage}\\
    \rowcolor[HTML]{EFEFEF} 
    BLABLA BLABLABLA BLABLA BLABLABLA BLABLA BLA                                       & \par\begin{minipage}{0.48\textwidth} Integer condimentum elit a finibus. \\ Praesent sed vestibulum sapien. \\ Donec molestie eros nulla, et finibus urna ut. \\ Morbi at malesuada erat. \end{minipage}\\
    BLABLA BLABLABLA BLABLA BLABLABLA BLABLABLA BLABLA BLA BLABLA BLABLABLA BLABLA BLA & \par\begin{minipage}{0.48\textwidth} Praesent sit amet condimentum lectus: \\ Butvitae dignissim sem tortor ut dolor \end{minipage}\\
    \end{longtable}

    \clearpage

\end{document}

I followed the anotations by Andrew Swann, putting \strut at the beggining and the end of the cell, and there is no better spacing around them:

\begin{longtable}{@{} p{0.48\textwidth} p{0.48\textwidth} @{}}
\rowcolor[HTML]{C0C0C0} 
Column fine & Column with problems \\
BLABLA BLABLABLA BLABLA BLABLABLA BLABLABLA BLABLA BLA                             & \strut\begin{minipage}{0.48\textwidth} In eget tortor libero. Duis vulputate scelerisque. \\ Etiam nec ornare nisi, eu semper augue \end{minipage}\strut\\
\rowcolor[HTML]{EFEFEF} 
BLABLA BLABLABLA BLABLA BLABLABLA BLABLA BLA                                       & \strut\begin{minipage}{0.48\textwidth} Integer condimentum elit a finibus. \\ Praesent sed vestibulum sapien. \\ Donec molestie eros nulla, et finibus urna ut. \\ Morbi at malesuada erat. \end{minipage}\strut\\
BLABLA BLABLABLA BLABLA BLABLABLA BLABLABLA BLABLA BLA BLABLA BLABLABLA BLABLA BLA & \strut\begin{minipage}{0.48\textwidth} Praesent sit amet condimentum lectus: \\ Butvitae dignissim sem tortor ut dolor \end{minipage}\strut\\
\end{longtable}

After strut

I try to achieve, exactly, a bit more spacing between minipage and the start/end of the cell in the longtable, without adding extra spacing inside each minipage.

  • Welcome to TeX - LaTeX! Please collect these snippets in to a minimal compilable document so that others can try your code. Does it help to add \strut and the beginning and the end of the text in the cells? – Andrew Swann Dec 11 '18 at 11:36
  • What are you trying to achieve, exactly? – Bernard Dec 11 '18 at 11:43
  • I edit the snippets into a minimal compilable document, and I will copy the \strutparameter you comment – José Manuel Ramos Dec 11 '18 at 11:44
2

I don't understand the reason to include minipages in a longtable. If I remove them and make the whole table a bit prettier, we get this code:

\documentclass[svgnames]{book}
\usepackage[T1]{fontenc}
\usepackage{tikz}
\usepackage{verbatim}
\usepackage{graphicx}
\usepackage[utf8]{inputenc}
\usepackage{color}
\usepackage{longtable}
\usepackage{colortbl, array, booktabs}

\usepackage{kpfonts}
\usepackage[explicit]{titlesec}
%\usepackage{fontspec}

\begin{document}

    \begin{longtable}{@{} m{0.48\textwidth} m{0.48\textwidth} @{}}
    \rowcolor[HTML]{C0C0C0} 
    Column fine & Column with problems \\\addlinespace[1ex]
    BLABLA BLABLABLA BLABLA BLABLABLA BLABLABLA BLABLA BLA &
    In eget tortor libero. Duis vulputate scelerisque. \newline Etiam nec ornare nisi, eu semper augue \\\addlinespace[1ex]
    \rowcolor[HTML]{EFEFEF} 
    BLABLA BLABLABLA BLABLA BLABLABLA BLABLA BLA &  Integer condimentum elit a finibus. \newline Praesent sed vestibulum sapien. \newline Donec molestie eros nulla, et finibus urna ut. \newline Morbi at malesuada erat. \\\addlinespace[1ex]
    BLABLA BLABLABLA BLABLA BLABLABLA BLABLABLA BLABLA BLA BLABLA BLABLABLA BLABLA BLA &  Praesent sit amet condimentum lectus: \newline Butvitae dignissim sem tortor ut dolor \\
    \end{longtable}

\end{document}

I switched to pdftex, so if you need xetex or whatever, remove fontenc and uncomment fontspec.

Result:

enter image description here

EDIT

I switched the columns to from p to m, which balances their content vertically, as can be observed in the new picture.

  • If you quit the minipage, the column fine doesn't show centered vertically, that's why I used minipages to dirty-achieve this. The pdftex is not a problem, the fonts I used are linked locally and are not relevant into the minimal compilation unit. – José Manuel Ramos Dec 11 '18 at 12:31
  • 1
    for columns specifiers instead of p{...} try to use m{...}. – Zarko Dec 11 '18 at 13:10
  • 1
    @Zarko That's why I loaded array for, but then forgot. Corrected, thank you. – Keks Dose Dec 11 '18 at 13:42
  • Good anotation! I will try to use this! – José Manuel Ramos Dec 11 '18 at 13:46
  • I tried to put \addlinespace[1ex] in every row, but unafortunately there is no extra spacing in coloured rows – José Manuel Ramos Dec 11 '18 at 13:55
2

a (small) variation of Keks Dose answer:

  • different definition of columns width (now the table width is equal to \textwidth)
  • used the xcolor package which is already loaded by the tikz package (it is not clear why you declare svgnames options for xcolor but than not used it)
  • for coloring of table's roes are used rowcolors from xtable
  • vertical space around cells is added partly in column definition (for bottom distance) and partly with \extrarowheight (for upper distance)
  • used the raggede2e package for "smart" hyphenation of the cells' contents

    \documentclass[table, svgnames]{book}
    \usepackage[ngerman]{babel}
    \usepackage[utf8]{inputenc}
    \usepackage[T1]{fontenc}
    \usepackage{kpfonts}
    \usepackage{bm}
    \usepackage{tikz}               % it load `"xcolor" with options given in "book" options
                                    % which with option "table" replace "color" and "colortbl"
    \definecolor{MyDarkGray}{HTML}{C0C0C0}  % new
    \definecolor{MyLightGray}{HTML}{EFEFEF} % new
    \usepackage{ragged2e}           % new
    \usepackage{caption}
    \usepackage{booktabs,
                longtable}
    \newcolumntype{M}[1]{>{\RaggedRight}m{#1}<{\smallskip}}  % new
    
    %---------------- show page layout. don't use in a real document!
    \usepackage{showframe}
    \renewcommand\ShowFrameLinethickness{0.15pt}
    \renewcommand*\ShowFrameColor{\color{red}}
    %---------------------------------------------------------------%
    
    \begin{document}
        \begingroup
        \setlength\extrarowheight{3pt}     % new
        \rowcolors{3}{MyLightGray}{white}  % new
    \begin{longtable}{ *{2}{M{\dimexpr0.5\linewidth-2\tabcolsep}} }
        \rowcolor{MyDarkGray}
    Column fine &   Column with problems                    \\
    BLABLA BLABLABLA BLABLA BLA BLABLA BLABLABLA BLABLA BLA
        &   In eget tortor libero. Duis vulputate scelerisque. % \newline
            Etiam nec ornare nisi, eu semper augue          \\
    BLABLA BLABLABLA BLABLA BLABLABLA BLABLA BLA
        &  Integer condimentum elit a finibus.              \newline
        Praesent sed vestibulum sapien.                     \newline
        Donec molestie eros nulla, et finibus urna ut.      \newline
        Morbi at malesuada erat.                            \\
    BLABLA BLABLABLA BLABLA BLABLABLA BLABLABLA BLABLA BLA BLABLA BLABLABLA BLABLA BLA
        &  Praesent sit amet condimentum lectus:            \newline
        Butvitae dignissim sem tortor ut dolor
    \end{longtable}
        \endgroup
    \end{document}
    

enter image description here

0

I propose some improvements to add spme vertical padding to the rows, playing with the booktabs parameters. I also suggest to us the xltabular package, which brings the functionalities of vlongtable  to tabularx. Last, I took the opportunity to simplify your preamble, as soma packages are already loaded by others (e.g. xltabular loads tabularx, which loads array, or the table option for xcolor, lready loaded by tikz, loads  colortbl).

\documentclass[svgnames, table]{book}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{kpfonts}
\usepackage{tikz}
\usepackage{verbatim}
\usepackage{graphicx}
\usepackage{booktabs}
\usepackage{xltabular}
\renewcommand{\tabularxcolumn}[1]{>{\arraybackslash}m{#1}}
\usepackage[explicit]{titlesec}

\begin{document}

{%
\defaultaddspace=1ex
\aboverulesep=0pt
\belowrulesep=0pt
\cmidrulewidth=1ex
\cmidrulekern=-\tabcolsep
\arrayrulecolor[HTML]{C0C0C0}
    \begin{xltabular}{\linewidth}{@{}XX @{}}
\cmidrule[1ex](lr){1-2}
    \rowcolor[HTML]{C0C0C0}
    Column fine & Column with problems \\[1ex]
 \addlinespace
    BLABLA BLABLABLA BLABLA BLABLABLA BLABLABLA BLABLA BLA &
    In eget tortor libero. Duis vulputate scelerisque. \newline Etiam nec ornare nisi, eu semper augue \\
    \addlinespace
    \arrayrulecolor[HTML]{EFEFEF}
\cmidrule(lr){1-2}
    \rowcolor[HTML]{EFEFEF}
    BLABLA BLABLABLA BLABLA BLABLABLA BLABLA BLA & Integer condimentum elit a finibus. \newline Praesent sed vestibulum sapien. \newline Donec molestie eros nulla, et finibus urna ut. \newline Morbi at malesuada erat. \\
\cmidrule(lr){1-2}
    \addlinespace
    BLABLA BLABLABLA BLABLA BLABLABLA BLABLABLA BLABLA BLA BLABLA BLABLABLA BLABLA BLA & Praesent sit amet condimentum lectus: \newline Butvitae dignissim sem tortor ut dolor \\
    \end{xltabular}}%

\end{document} 

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.