使表格列变窄(tabu)

使表格列变窄(tabu)

我正在使用 tabu 创建表格,但是我似乎找不到让左边两列变窄、让最右边一列变宽以容纳文本的方法。

我使用的代码是:

\begin{table}[H]
    \centering
    \caption{Kepler orbit parameters}
    \begin{tabu}{*{3}{X[c]}}
        \toprule
        Parameter & Name & Description \\
         \midrule
         a & semi-major axis & The axis that coincides with both focus points of the ellipse \\
         E & Eccentric Anomaly & The angle between the center of equivalent circle with radius $r$ \\
         \bottomrule
    \end{tabu}
    \label{tab:Kepler}
\end{table}

我想让最左边的两列居中,而右边的一列较宽且不居中,这样文本会更易于阅读。有什么建议吗?

答案1

正如 Ulrike Fischer 在评论中提到的那样,tabu应该避免使用该软件包。您可以使用相对较新的tabularray包。(您会发现tabutabularray包之间有相似之处。)

在此处输入图片描述

\documentclass{article}

\usepackage{tabularray}
\UseTblrLibrary{booktabs} %to use booktabs rules 

\begin{document}
\begin{table}
    \centering
    \caption{Kepler orbit parameters}
    \begin{tblr}{
        width = {\textwidth}, %width of the table
        colspec = {@{}ccX[l]@{}}, %column types
        rows = {m} %vertical alignment
    }
        \toprule
        Parameter & Name & Description \\
        \midrule
        a & semi-major axis & The axis that coincides with both focus points of the ellipse \\
        E & Eccentric Anomaly & The angle between the center of equivalent circle with radius $r$ \\
        \bottomrule
    \end{tblr}
\end{table}

\end{document}

答案2

我建议您采用一个tabularx环境。

在此处输入图片描述

\documentclass{article} % or some other suitable document class
\usepackage{tabularx,ragged2e,booktabs}
\newcolumntype{L}{>{\RaggedRight}X}

\begin{document} 
\begin{table}[ht]
\caption{Kepler orbit parameters\strut}\label{tab:Kepler}
\begin{tabularx}{\textwidth}{@{} llL @{}}
      \toprule
      Parameter & Name & Description \\
      \midrule
      $a$ & semi-major axis & The axis that coincides with both focus points of the ellipse \\
      $E$ & Eccentric Anomaly & The angle between the center of equivalent circle with radius $r$ \\
      \bottomrule
\end{tabularx}
\end{table}
\end{document}

答案3

只是为了怀旧,一个使用的示例tabu,当然它不再可行,正如所提到的,它有一些错误,因为实现尚未完成,并且该包已被废弃很长时间,甚至不再可能对单元格进行阴影处理,但当时它对我来说非常有用,因为我可以操纵表格的宽度、单元格及其相对于因子的分布,除了操纵样式之外,它还允许我制作比办公套件或其他类似的所见即所得更好的样式的表格。不幸的是,我使用这个包很长时间,直到单元格阴影错误,而且我最近才开始使用传统软件包,所以我不知道它们是否能达到 tabu 那样的风格,因为我目前制作的是更严肃的文本,它们不使用色彩鲜艳的风格,而是简洁易读。一如既往,这是一个品味问题。

结果:

在此处输入图片描述

梅威瑟:

\documentclass{article}
\usepackage{graphicx} % to rotate text
%Ex-Package for beautifull tables.
\usepackage{tabu}
\usepackage[table]{xcolor}
\definecolor{myblue}{HTML}{002fa7}
\begin{document}
    \begin{table}[!h]
        \def\TableLineSize{3pt}   
        \tabulinesep = 5pt 
        \tabulinestyle{\TableLineSize myblue}
        \caption{Kepler orbit parameters\strut}\label{tab:Kepler}
        \begin{tabu} to \linewidth {|X[1cm]|X[3cm]|X[20lm]|} %note cm is center+middle.
            %tabu sintax X column "|" to indicate vertical line.
            %X[Relative_to_total_factor+horizontal_align(l,c,r)+Vertical_align(m,b,p)], example : 3bm, 0.5lb, etc.
            \tabucline - % Lines musrt be defined using \tabucline. but not in discontinous line.
             \rotatebox{90}{Parameter} & Name & Description \\ \tabucline - 
            $a$ & semi-major axis & The axis that coincides with both focus points of the ellipse \\ \tabucline[0.5pt,myblue] -
            $E$ & Eccentric Anomaly & The angle between the center of equivalent circle with radius $r$ \\ \tabucline -     
        \end{tabu}
    \end{table} 
\end{document}

答案4

具有({NiceTabular}nicematrix经典类似,{tabular} 但具有更多功能)。

\documentclass{article}
\usepackage{nicematrix,booktabs}

\begin{document} 
\begin{table}[ht]
\caption{Kepler orbit parameters\strut}\label{tab:Kepler}
\begin{NiceTabular}{@{}llX[l]@{}}
      \toprule
      Parameter & Name & Description \\
      \midrule
      $a$ & semi-major axis & The axis that coincides with both focus points of the ellipse \\
      $E$ & Eccentric Anomaly & The angle between the center of equivalent circle with radius $r$ \\
      \bottomrule
\end{NiceTabular}
\end{table}
\end{document}

上述代码的输出

相关内容