lvjr / tabularray

Typeset tabulars and arrays with LaTeX3
https://ctan.org/pkg/tabularray
247 stars 22 forks source link

@ specifiers in colspec and centering alignment #393

Closed latexstudio closed 1 year ago

latexstudio commented 1 year ago

如下是代码:

\documentclass[a4paper]{article}
\usepackage{ctex}  
\usepackage{tabularray} 
\begin{document}

\noindent\begin{tblr}{vlines, hlines,colspec={@{}cQ[c,3cm]@{}},%
     %rows={belowsep=-3pt,abovesep=10pt},%
     %column{1,2}={font=\zihao{4}},% 小2号、黑体
     %hline{2,3,4,5,6}={2}{.4pt,solid},%               
   }
  \makebox[6em][s]{学\hspace{\fill}生\hspace{\fill}姓\hspace{\fill}名}:&张王\\ 
  \makebox[6em][s]{指\hspace{\fill}导\hspace{\fill}教\hspace{\fill}师}:&赵钱孙\\ 
  \makebox[6em][s]{合作指导教师}:&张帆\\ 
  \makebox[6em][s]{专\hspace{\fill}业\hspace{\fill}名\hspace{\fill}称}:&数学与应用数学\\ 
  \makebox[6em][s]{所\hspace{\fill}在\hspace{\fill}学\hspace{\fill}院}:&理学院\\ 
\end{tblr}

\end{document}

效果来看,表格里的内容明显偏右。 如果该用 tabularx 等 @{} 不影响单元格的居中显示。

lvjr commented 1 year ago

With colspec={@{}cQ[c,3cm]@{}}, you set leftsep=0pt for the first column and set rightsep=0pt for the second column. But by default rightsep=6pt for the first column and leftsep=6pt for the second column. Therefore the cells look not centered.

PS: please always use English in reporting potential bugs of this package.

\documentclass[a4paper]{article}
\usepackage{array,amssymb} 
\usepackage{tabularray}
\SetTblrInner[tblr]{rowsep=0pt}
\setlength\parindent{0pt}
\newcommand\mybox{$\blacksquare$}
\begin{document}

\section{tabularray}

\begin{tblr}{vlines,colspec={@{}cQ[c,3cm]@{}}}
\hline
  \mybox\mybox             & \mybox\mybox\mybox\mybox\mybox\mybox\mybox \\
\hline
  \mybox\mybox\mybox\mybox & \mybox\mybox\mybox\mybox\mybox \\
\hline
\end{tblr}

\medskip

\begin{tblr}{|@{}c|Q[c,3cm]@{}|}
\hline
  \mybox\mybox             & \mybox\mybox\mybox\mybox\mybox\mybox\mybox \\
\hline
  \mybox\mybox\mybox\mybox & \mybox\mybox\mybox\mybox\mybox \\
\hline
\end{tblr}

\section{tabular}

\begin{tabular}{|@{}c|>{\centering\arraybackslash}b{3cm}@{}|}
\hline
  \mybox\mybox             & \mybox\mybox\mybox\mybox\mybox\mybox\mybox \\
\hline
  \mybox\mybox\mybox\mybox & \mybox\mybox\mybox\mybox\mybox \\
\hline
\end{tabular}

\end{document}

image