如何左對齊表格內的矩陣?

如何左對齊表格內的矩陣?

我有一個包含兩個矩陣的表。我想左對齊這些矩陣,而不是中心對齊。我使用的是 IEEE 格式。另外,矩陣的括號與表格的[]括號非常接近。\hline有什麼辦法可以在括號和水平線之間留出空白嗎?

\begin{table*}[!t]
\renewcommand{\arraystretch}{1.3}
\caption{This is table}
\label{table_network_architecture}
\centering
\begin{tabular}{c|c}
\hline
\bfseries Name & \bfseries Matrix  \\
\hline\hline
%Dense 2
Text 1 & $\left[ \begin{array}{c} 30 \times 30 \\ 30 \times 30 \end{array}\right]$\\
\hline
Text 1 & $\left[ \begin{array}{c} 30 \times 30 \\ 30 \times 30 \end{array}\right]-100$\\
\hline
\hline
\end{tabular}   
\end{table*}

答案1

我更喜歡booktabsgernot 所示的方式,但如果您堅持統治您的桌子,您可以使用makecell

\documentclass{article}
\usepackage{amsmath}
\usepackage{newtxtext,newtxmath}
\usepackage{makecell}

\begin{document}

\begin{table}[htp]
\centering

\caption{This is table}
\label{table_network_architecture}
\medskip

\setcellgapes{3pt}\makegapedcells

\begin{tabular}{l|l}
\hline
\multicolumn{1}{c|}{\bfseries Name} & \multicolumn{1}{c}{\bfseries Matrix} \\
\hline
Text 1 & $\begin{bmatrix} 30 \times 30 \\ 30 \times 30 \end{bmatrix}$ \\
\hline
Text 2, longer & $\begin{bmatrix} 30 \times 30 \\ 30 \times 30 \end{bmatrix}-100$ \\
\hline
\end{tabular}

\end{table}

\end{document}

在此輸入影像描述

答案2

若要左對齊列中的元素,請使用l而不是c作為列說明符。

額外空間的問題不能簡單地透過增加 來解決\arraystretch,因為它以與數組相同的方式影響表。人們可以\arraystretch在數組之前將 重置為 1,但這仍然沒有給出很好的間距。解決這個問題的一種方法是使用booktabs套件。

\left[\begin{array}{c} ... \end{array}\right]最後一句話:您可以使用\begin{bmatrix} ... \end{bmatrix};代替bmatrix是在包中定義的amsmath

在此輸入影像描述

\documentclass{IEEEtran}
\usepackage{booktabs}
\usepackage{amsmath}
\begin{document}
\begin{tabular}{cl}
\toprule
\bfseries Name & \bfseries Matrix  \\
\midrule
Text 1 & 
$\begin{bmatrix} 30 \times 30 \\ 30 \times 30 \end{bmatrix}$\\
\midrule
Text 1 &
$\begin{bmatrix} 30 \times 30 \\ 30 \times 30 \end{bmatrix}-100$\\
\bottomrule
\end{tabular}   
\end{document}

答案3

可以使用with\fboxsep在所有邊上添加 2pt ( } 間隙。\fbox\fboxrule=0pt

\documentclass[twocolumn]{article}
\usepackage{mathtools}
\begin{document}
\begin{table*}[!t]
\renewcommand{\arraystretch}{1.3}
\setlength{\fboxrule}{0pt}
\caption{This is table}
\label{table_network_architecture}
\centering
\begin{tabular}{c|l}
\hline
\bfseries Name & \bfseries Matrix  \\
\hline\hline
%Dense 2
Text 1 & \fbox{$\left[ \begin{array}{c} 30 \times 30 \\ 30 \times 30 \end{array}\right]$}\\
\hline
Text 1 & \fbox{$\left[ \begin{array}{c} 30 \times 30 \\ 30 \times 30 \end{array}\right]-100$}\\
\hline
\hline
\end{tabular}   
\end{table*}
\end{document}

示範


或者,可以使用以下命令為超大文字添加適當的支柱

\documentclass[twocolumn]{article}
\usepackage{mathtools}

\newcommand{\arraybox}[1]% #1 = extra large text
{\bgroup
  \sbox0{#1}% measure
  \rule{0pt}{\arraystretch\ht0}% top strut
  \rule[-\arraystretch\dp0]{0pt}{0pt}% bottom strut
  \box0
\egroup}

\begin{document}
\begin{table*}[!t]
\renewcommand{\arraystretch}{1.3}
\caption{This is table}
\label{table_network_architecture}
\centering
\begin{tabular}{c|l}
\hline
\bfseries Name & \bfseries Matrix  \\
\hline\hline
%Dense 2
Text 1 & \arraybox{$\left[ \begin{array}{c} 30 \times 30 \\ 30 \times 30 \end{array}\right]$}\\
\hline
Text 1 & \arraybox{$\left[ \begin{array}{c} 30 \times 30 \\ 30 \times 30 \end{array}\right]-100$}\\
\hline
\hline
\end{tabular}   
\end{table*}
\end{document}

演示2

相關內容