3

Consider the following two tables: enter image description here

enter image description here

The first table is the table that I wish to have and the second table is the table I obtained for which the code is as follow:

\begin{array}{|c|c|c|c|}
\cline { 2 - 4 } \multicolumn{1}{c|} {} & \|V-QR\|_{2} & \left\|I-Q^{\intercal}Q\right\|_{2} & \left\|I-QQ^{\intercal}\right\|_{2} \\
\hline \text {$\mathsf{CGS3\_QR}$} & & & \\
\text {$\mathsf{MGS\_QR}$} & & & \\
\hline
\end{array}

My only concern is the spacing because in the second table which I got the entries are too narrowed. I hope someone can help and thank you.

Markus G.
  • 2,735
  • 2
    You say table but you are using array, which begs the question: Why? Also, in an actual tabular environment you could use \renewcommand{\arraystretch}{1.2} or an equivalent to change the vertical height of the cells. – Markus G. Jun 11 '21 at 13:20
  • 1
    So, this is not your question exactly, but the very well written answer should also help you improve your tables: https://tex.stackexchange.com/a/156124/118712 – Markus G. Jun 11 '21 at 13:29
  • 2
    Unrelated: Some common advice for tables is to not use vertical lines, unless it is an absolute emergency. Vertical lines interrupt the flow of the reader looking at one row at a time from left to right (or right to left). This is especially true, when you are using the booktabs package, which was created keeping this advice in mind (and will result in gaps if you do try to combine them). – Markus G. Jun 11 '21 at 13:32
  • Hello, thank you very much for your suggestion I will definitely learn from my mistake as for the vertical lines I must say I am dealing with numbers to be written as 2.1x10^-5 for example so I thought of adding vertical lines but I will definitely rethink about it – ZeinabQom Jun 11 '21 at 13:35
  • Well, I wouldn't call it a "mistake". As in all programming in LaTeX many ways will lead to the goal and the output you had was almost what you wanted it to be, so no worries. – Markus G. Jun 11 '21 at 13:41

2 Answers2

3

You can use the \makegapedcells command from makecell:

    \documentclass{article}
\usepackage{amsmath, amssymb}
\usepackage{makecell}

\begin{document}

 \[ \setcellgapes{3pt}\makegapedcells
  \begin{array}{|*{4}{c|}}
    \cline { 2 - 4 } \multicolumn{1}{c|} {} & \|V-QR\|_{2} & \left\|I-Q^{\intercal}Q\right\|_{2} & \left\|I-QQ^{\intercal}\right\|_{2} \\
    \hline \text {$\mathsf{CGS3\_QR}$} & & & \\
    \text {$\mathsf{MGS\_QR}$} & & & \\
    \hline
  \end{array} \]

\end{document} 

enter image description here

Bernard
  • 271,350
  • This is definitely an interesting approach that I certainly did not anticipate. Can you maybe clarify why one might want to use this kind of customised array over a tabular? (Except for maybe array being a maths environment.) – Markus G. Jun 11 '21 at 13:43
  • @MarkusG. : it is precisely one of the reasons: using tabular automatically makes the cells in text mode (the other reason being that in the O.P. code, an array was used). – Bernard Jun 11 '21 at 13:47
2

A small variation of nice @Bernard answer (+1) ...

  • by use of mathtools package is defined \norm
  • contents in the first column is cleanup of superfluous code
\documentclass{article}
\usepackage{mathtools, amssymb}
\DeclarePairedDelimiterX\norm[1]{\|}{\|}{#1}
\usepackage{makecell}

\begin{document} [ \setcellgapes{3pt} \makegapedcells \begin{array}{|{4}{c|}} \cline {2-4} \multicolumn{1}{c|} {} & \norm{V-QR}{2}
& \norm*{I-Q^{\intercal} Q}
{2} & \norm*{I-QQ^{\intercal}}_{2} \ \hline \mathsf{CGS3_QR} & & & \ \mathsf{MGS_QR} & & & \ \hline \end{array} ] \end{document}

enter image description here

Zarko
  • 296,517