将 tabularray 开发的整个表格左对齐

将 tabularray 开发的整个表格左对齐

我有一张由 tabularray 开发的表格,但是在文档中找不到如何将整个表格左对齐以使整个表格再次居中。

在此处输入图片描述

这是代码:

\documentclass{article}
\usepackage{tabularray}
\usepackage[table]{xcolor}
\begin{document}


\begin{tblr}{
colspec={cccccccc},
rowspec={Q[gray!20]Q[]Q[gray!10]Q[]Q[gray!10]Q[]Q[gray!10]Q[]}, 
vline{2-8} = {0-1}{0.3pt,gray!50},
vline{2-8} = {2-7}{0.3pt,gray!30},
hline{1,2,8} = {0.1pt,azure5}}
Dataset  & \# clusters & \# Train neurons & \# Test neurons & \# Extra neurons & Architectures & Train loss & Test loss\\
1  & Beta & Gamma & Alpha & Beta & Gamma & Beta & Gamma\\
2  & Beta & Gamma & Alpha & Beta & Gamma & Beta & Gamma\\
3  & Beta & Gamma & Alpha & Beta & Gamma & Beta & Gamma\\
4  & Beta & Gamma & Alpha & Beta & Gamma & Beta & Gamma\\
5  & Beta & Gamma & Alpha & Beta & Gamma & Beta & Gamma\\
6  & Beta & Gamma & Alpha & Beta & Gamma & Beta & Gamma\\

\end{tblr}


\end{document}

答案1

您的表格太大,无法显示在同一行,因此我为您提供了两种解决方案:

  1. 像这样缩小表格的大小
\documentclass{article}
\usepackage[table]{xcolor}
\usepackage{tabularray}
\usepackage{graphicx}
\begin{document}
\scalebox{0.7}{
\begin{tblr}{
colspec={cccccccc},
rowspec={Q[gray!20]Q[]Q[gray!10]Q[]Q[gray!10]Q[]Q[gray!10]Q[]}, 
vline{2-8} = {0-1}{0.3pt,gray!50},
vline{2-8} = {2-7}{0.3pt,gray!30},
hline{1,2,8} = {0.1pt,azure5}}
Dataset  & \# clusters & \# Train neurons & \# Test neurons & \# Extra neurons & Architectures & Train loss & Test loss\\
1  & Beta & Gamma & Alpha & Beta & Gamma & Beta & Gamma\\
2  & Beta & Gamma & Alpha & Beta & Gamma & Beta & Gamma\\
3  & Beta & Gamma & Alpha & Beta & Gamma & Beta & Gamma\\
4  & Beta & Gamma & Alpha & Beta & Gamma & Beta & Gamma\\
5  & Beta & Gamma & Alpha & Beta & Gamma & Beta & Gamma\\
6  & Beta & Gamma & Alpha & Beta & Gamma & Beta & Gamma\\

\end{tblr}}

\end{document}
  1. 更改页面的边框:
\documentclass{article}
\usepackage[table]{xcolor}
\usepackage{tabularray}
\usepackage[a4paper,bindingoffset=0.2in,%
left=0.1in,right=0.5in,top=0.6in,bottom=0.5in,%
footskip=.1in]{geometry}
\begin{document}
\begin{tblr}{
colspec={cccccccc},
rowspec={Q[gray!20]Q[]Q[gray!10]Q[]Q[gray!10]Q[]Q[gray!10]Q[]}, 
vline{2-8} = {0-1}{0.3pt,gray!50},
vline{2-8} = {2-7}{0.3pt,gray!30},
hline{1,2,8} = {0.1pt,azure5}}
Dataset  & \# clusters & \# Train neurons & \# Test neurons & \# Extra neurons & Architectures & Train loss & Test loss\\
1  & Beta & Gamma & Alpha & Beta & Gamma & Beta & Gamma\\
2  & Beta & Gamma & Alpha & Beta & Gamma & Beta & Gamma\\
3  & Beta & Gamma & Alpha & Beta & Gamma & Beta & Gamma\\
4  & Beta & Gamma & Alpha & Beta & Gamma & Beta & Gamma\\
5  & Beta & Gamma & Alpha & Beta & Gamma & Beta & Gamma\\
6  & Beta & Gamma & Alpha & Beta & Gamma & Beta & Gamma\\

\end{tblr}

\end{document}

答案2

以下是两种解决方案:

  1. 使用:

    • \centerline{...}使得桌子的两个边缘能够和谐地溢出。

    • font=\scriptsize以减小标题的大小。

    • colsep=1pt减少列之间的空间。

  2. 使用:

    • \rotatebox{angle}{text}(从graphicx)旋转列标题。

注:带有tabularrayZ表示表格的最后一行,row{odd}适用于奇数行。

\documentclass{article}
\usepackage{xcolor}
\usepackage{tabularray}
\usepackage{lipsum}
\usepackage{graphicx}
\begin{document}
\lipsum[1]

\centerline{
  \begin{tblr}{
      colspec={cccccccc},
      colsep=1pt,
      % colors and lines for the table
      row{odd}={bg=gray!10},
      vline{2-8} = {0.3pt,gray!30},
      hline{1,2,Z} = {0.1pt,azure5},
      % colors and lines for the title row
      row{1}={font=\scriptsize,bg=gray!10},
      vline{2-8} = {0-1}{0.3pt,gray!50},
    }
    Dataset & \# clusters & \# Train neurons & \# Test neurons & \# Extra neurons & Architectures & Train loss & Test loss \\
    1       & Beta        & Gamma            & Alpha           & Beta             & Gamma         & Beta       & Gamma     \\
    2       & Beta        & Gamma            & Alpha           & Beta             & Gamma         & Beta       & Gamma     \\
    3       & Beta        & Gamma            & Alpha           & Beta             & Gamma         & Beta       & Gamma     \\
    4       & Beta        & Gamma            & Alpha           & Beta             & Gamma         & Beta       & Gamma     \\
    5       & Beta        & Gamma            & Alpha           & Beta             & Gamma         & Beta       & Gamma     \\
    6       & Beta        & Gamma            & Alpha           & Beta             & Gamma         & Beta       & Gamma     \\
  \end{tblr}
}

\lipsum[2]

\centerline{
  \begin{tblr}{
      colspec={cccccccc},
      % colors and lines for the table
      row{odd}={bg=gray!10},
      vline{2-8} = {0.3pt,gray!30},
      hline{1,2,Z} = {0.1pt,azure5},
      % colors and lines for the title row
      row{1}={cmd=\rotatebox{90},font=\footnotesize,bg=gray!10},
      vline{2-8} = {0-1}{0.3pt,gray!50},
    }
    Dataset & \# clusters & \# Train neurons & \# Test neurons & \# Extra neurons & Architectures & Train loss & Test loss \\
    1       & Beta        & Gamma            & Alpha           & Beta             & Gamma         & Beta       & Gamma     \\
    2       & Beta        & Gamma            & Alpha           & Beta             & Gamma         & Beta       & Gamma     \\
    3       & Beta        & Gamma            & Alpha           & Beta             & Gamma         & Beta       & Gamma     \\
    4       & Beta        & Gamma            & Alpha           & Beta             & Gamma         & Beta       & Gamma     \\
    5       & Beta        & Gamma            & Alpha           & Beta             & Gamma         & Beta       & Gamma     \\
    6       & Beta        & Gamma            & Alpha           & Beta             & Gamma         & Beta       & Gamma     \\
  \end{tblr}
}

\lipsum[3]

\end{document}

在此处输入图片描述

相关内容