3

I have a table that contains two matrices. I want to left-align these matrices, instead of center align. I am using IEEE format. In addition, the bracket []of matrix is very close to the \hline of the table. Could we have any way to make a margin between the bracket and the 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*}
0

3 Answers 3

4

I'd prefer the booktabs way shown by gernot, but if you insist in ruling your table, you can use 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}

enter image description here

0
5

To left-align the elements in a column, use l instead of c as column specifier.

The problem with the extra space cannot be solved simply by increasing \arraystretch, because it affects the table in the same way as the arrays. One can reset the \arraystretch to 1 immediately before the arrays, but this still gives no nice spacing. One way to solve it is to use the booktabs package.

Final remark: Instead of \left[\begin{array}{c} ... \end{array}\right] you can use \begin{bmatrix} ... \end{bmatrix}; bmatrix is defined in the package amsmath.

enter image description here

\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}
2
  • But \midrule make my \vline is not continuous.
    – John
    Commented Apr 27, 2017 at 13:30
  • @user8264 Many people, in particular those in professional typesetting, consider vertical lines as redundant, even as confusing rather than supporting. The booktabs package operates under the assumption that you don't use vertical lines.
    – gernot
    Commented Apr 27, 2017 at 13:45
3

One can add a 2pt (\fboxsep} gap on all sides using \fbox with \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}

demo


Alternatively, one can add appropriate struts for extra large text using

\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}

demo 2

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .