如何使表中的列独立运行

如何使表中的列独立运行

我想使该表中的列彼此“独立”,这样如果某一列的句子比其他列的句子长,它们就不会产生空白。

所附的图片显示了问题,以及我想要将文本移动到的位置。

如何删除空白(将文本向上移动)

代码:

\begin{table}[htpb!]
\caption{Byggesystemer}
\label{tab:Byggesystemmer}
\renewcommand{\arraystretch}{1.5}
\strut
\noindent
\begin{tabularx}{\linewidth}{p{3.5cm}@{\hspace{3mm}} >{\raggedright\arraybackslash}X @{\hspace{3mm}}  >{\raggedright\arraybackslash}X >{\raggedright\arraybackslash}X}
\toprule
 Column 1         & Column 2    & Column 3     \\
\midrule
System 1    &  This piece of text will take up some space and therefore use three whole lines & This could be anything \\
& This could be anything  & How do I remove the white space above this? \\
& This could be anything but fills two lines   &  \\
& This could be anything  & Same problem as above \\
\midrule
System 2                &  This could be anything & This piece of text will take up some space and therefore use more than one line \\
& How to remove white space above this? & This could be anything \\
& This could be anything & Problem again \\
\bottomrule
\end{tabularx}
\end{table}

答案1

我估计第 2 列和第 3 列中的信息应该显示为自由格式列表。如果这个假设正确,您可以通过按列分组单元格来实现格式化目标。为了节省垂直空间,我建议保持单倍行距,但对列表项使用悬挂缩进。

在此处输入图片描述

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[danish]{babel}
\usepackage{tabularx,booktabs,ragged2e}
\newcolumntype{L}{>{%
   \RaggedRight\everypar{\hangafter=1\hangindent=1em}}X}

\begin{document}

\begin{table}[htpb!]
\setlength\tabcolsep{1.5mm}
\caption{Byggesystemmer\strut}
\label{tab:Byggesystemmer}
\begin{tabularx}{\linewidth}{@{} lLL @{}}
\toprule
System & Fordele & Ulemper \\
\midrule
Bærende tværvægge &  
  System er hurtigt og let at montere \par
  God lydisolering \par
  Billigere \par
  Oprettelse af ikke bærende vægge &
Begrænset bæredygtighed \\
\midrule
Søjle-plade &  
  Bæredygtighed \par
  Stor planlægningsflexibilitet \par
  Facade udforming &
Dækelementer kan kun optage vandrette kræfter \\
\midrule
Plade-ramme & 
Bæredygtighed \par
  Planlægningsflexibilitet & 
Bjælker er synlige i loftet \\
\midrule
Bærende ydervægge & 
Bæredygtighed \par
  Stor planlægningsflexibilitet \par
  Indre del er rydde & 
Facade er låst \par
  Kan føre til problemer med vinduer  \\
\bottomrule
\end{tabularx}
\end{table}
\end{document}

答案2

那么你可以使用多行来摆弄你的行变化,就像这样:

\documentclass{article}

\usepackage{booktabs}
\usepackage{multirow}
\usepackage{tabularx}

\begin{document}
\begin{table}[htpb!]
    \caption{Byggesystemer}
    \label{tab:Byggesystemmer}
    \renewcommand{\arraystretch}{1.5}
    \strut
    \noindent
    \begin{tabularx}{\linewidth}{p{3.5cm}@{\hspace{3mm}} >{\raggedright\arraybackslash}X @{\hspace{3mm}}  >{\raggedright\arraybackslash}X >{\raggedright\arraybackslash}X}
        \toprule
        Column 1         & Column 2    & Column 3     \\
        \midrule
        System 1    &  \multirow{3}{\hsize}{This piece of text will take up some space and therefore use three whole lines} & This could be anything \\
        &                                               & How do I remove the white space above this? \\
        &                                               & Same problem as above \\
        & This could be anything  &  \\
        & This could be anything but fills two lines   &  \\
        & This could be anything  &  \\
        \midrule
        System 2                &  This could be anything & \multirow{3}{\hsize}{This piece of text will take up some space and therefore use more than one line} \\
        & How to remove white space above this? &  \\
        & This could be anything &  \\
        &  & This could be anything \\
        &  & Problem again \\
        \bottomrule
    \end{tabularx}
\end{table}
\end{document}

你可能会觉得这样会更好:

\documentclass{article}

\usepackage{booktabs}
\usepackage{tabularx}

\begin{document}
\begin{table}[htpb!]
    \caption{Byggesystemer}
    \label{tab:Byggesystemmer}
    \renewcommand{\arraystretch}{1.5}
    \strut
    \noindent
    \begin{tabularx}{\linewidth}{p{3.5cm}@{\hspace{3mm}} >{\raggedright\arraybackslash}X @{\hspace{3mm}}  >{\raggedright\arraybackslash}X >{\raggedright\arraybackslash}X}
        \toprule
        Column 1         & Column 2    & Column 3     \\
        \midrule
        System 1    &  This piece of text will take up some space and therefore use three whole lines \vskip 1ex   
                       This could be anything \vskip 1ex                                                            
                       This could be anything but fills two lines \vskip 1ex                                        
                       This could be anything                                                                    
                           & This could be anything \vskip 1ex
                             How do I remove the white space above this? \vskip 1ex
                             Same problem as above \\
        \midrule
        System 2                &  This could be anything \vskip 1ex
                                   How to remove white space above this? \vskip 1ex
                                   This could be anything                            
                                       & This piece of text will take up some space and therefore use more than one line \vskip 1ex
                                         This could be anything \vskip 1ex
                                         Problem again \\
        \bottomrule
    \end{tabularx}
\end{table}
\end{document}

几点说明

由于您没有将表格行用作真实行,因此您可以尝试强制 LaTeX 执行您想要的操作(第一个选项),或者放弃尝试将您的内容强制放入行中(第二个选项)。

此外,MWE(最小工作示例)是您可以直接复制粘贴到您最喜欢的 tex 编辑器中并编译以查看输出的内容,就像我提供的那样。您的示例缺少足够的前言。

答案3

我制作了一个模板,展示了我如何使用@Mico 的想法来制作它。我为丹麦语道歉,但解决方案可以在间距中看到。

没有空白的解决方案图像

代码:

\newcolumntype{L}{>{%
       \RaggedRight\everypar{\hangafter=1}}X}
    \begin{table}[htpb!]
    \setlength\tabcolsep{2mm}
    \caption{Irregular columns}
    \label{tab:IrregularColumns}
    \begin{tabularx}{\linewidth}{@{} lLL @{}}
    \toprule
    Kolonne 1 & Kolonne 2 & Kolonne 3 \\
    \midrule
    Tekst 1 &  
      Længere tekst, som fylder flere linjer, når man skriver noget langt. \par \vspace{2mm}
      Kort tekst \par \vspace{2mm}
      Kort tekst \par \vspace{2mm}
      Mindre kort tekst &
    Kort tekst \par \vspace{2mm}
    Kort tekst \par \vspace{2mm}
    Længere tekst, som fylder flere linjer, når man skriver noget langt \\
    \midrule
    Tekst 2 &  
      Kort tekst \par \vspace{2mm}
      Mindre kort tekst \par \vspace{2mm}
      Længere tekst, som fylder flere linjer, når man skriver noget langt. &
    Her skriver jeg en masse volapyk, fordi jeg skal vise dig det smarte i, at man kan have forskellige længder i sætningerne uden at det ødelægger noget for kolonnen ved siden af. \\
    \bottomrule
    \end{tabularx}
    \end{table}

相关内容