单元格内迷你页面的长表间距问题

单元格内迷你页面的长表间距问题

我是 [tex.se] 的新手,我想问您如何解决此代码片段中出现的问题:

\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

当我使用 XeTeX 和漂亮的字体时,此代码输出以下内容:

问题就出现在这里!

我用于最少编译此代码片段的软件包如下(没有其中大多数也可以进行编译,我没有使用较少的软件包进行测试):

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

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

文档类型为:

\documentclass[svgnames]{book}

我曾尝试过进行更改,\par但没有明显的变化。\noindent\begin{minipage}

我尝试使用此处评论的解决方案:平衡多列与小页面之间的问题但它也不起作用。

问题是:我在长表或小页面中输入什么内容才能使单元格的上部和下部具有正确的间距?

最小可编译文档是:

\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}

我遵循了 Andrew Swann 的注释,将其放在\strut单元格的开始和结束处,并且它们周围没有更好的间距:

\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}

支撑后

我尝试在小型页面和长表中单元格的开始/结束之间实现稍微多一点的间距,而不在每个小型页面内添加额外的间距。

答案1

我不明白为什么要在长表中包括小页面。如果我删除它们并使整个表更漂亮一些,我们会得到以下代码:

\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}

我切换到了 pdftex,所以如果您需要 xetex 或其他什么,请删除 fontenc 并取消注释 fontspec。

结果:

在此处输入图片描述

编辑

我将列从 p 切换到 m,以垂直方式平衡其内容,如在新图片中所见。

答案2

的(小)变化剂量回答:

  • 列宽定义不同(现在表格宽度等于\textwidth
  • 使用xcolor已经被tikz包加载的包(不清楚为什么声明了svgnames选项xcolor但没有使用它)
  • rowcolors用于表的鱼子着色xtable
  • 单元格周围的垂直空间部分添加到列定义中(用于底部距离),部分添加到列定义中\extrarowheight(用于上部距离)
  • 使用该raggede2e包对单元格内容进行“智能”连字

    \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}
    

在此处输入图片描述

答案3

我建议进行一些改进,使用 booktabs 参数为行添加 spme 垂直填充。我还向我们推荐了将xltabularv 的功能引入 的包longtable tabularx最后,我借此机会简化了您的序言,因为 soma 包已被其他人加载(例如xltabularloads tabularx、 which loads array,或table的选项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} 

在此处输入图片描述

相关内容