3
\begin{tabular}{c|c|c|c} 
&$\text{A}$&$\overline{\text{A}}$&\\ 
\hline
$\text{B}$&9&6&15\\ 
\hline 
$\overline{\text{B}}$&3&12&15\\ 
\hline
&12&18&30 
\end{tabular}

enter image description here

But as you can see the B ist a little bit to near to the top.

Is there a way to make it more like this?

enter image description here

Mico
  • 506,678
  • 4
    Please stop tagging all your questions as biblatex https://tex.stackexchange.com/questions/657763/how-to-make-an-equation-more-aligned#comment1638486_657763 This has nothing to do with biblatex – David Carlisle Sep 20 '22 at 13:10

3 Answers3

3
\documentclass{article}
\usepackage{tabularray}
\usepackage{amsmath}
\begin{document}
\begin{tblr}{colspec={cccc},hlines,vlines,rows={abovesep+={2pt}}}
                      & $\text{A}$ & $\overline{\text{A}}$ &    \\
$\text{B}$            & 9          & 6                     & 15 \\
$\overline{\text{B}}$ & 3          & 12                    & 15 \\
                      & 12         & 18                    & 30
\end{tblr}
\end{document}

enter image description here

Clara
  • 6,012
  • Hello I tried to enter it in Discord but i get following Error: ``! LaTeX Error: Illegal character in array arg.

    See the LaTeX manual or LaTeX Companion for explanation. Type H for immediate help. ...

    l.61 ...ccc},hlines,vlines,rows={abovesep+={2pt}}}

    You're in trouble here. Try typing to proceed. If that doesn't work, type X to quit.``

    – user279680 Sep 20 '22 at 12:48
  • @user279680 I am on TeX Live 2022. You can try it on Overleaf with 2022. – Clara Sep 20 '22 at 13:01
  • I want it to work on discord, the code that i posted worked on it – user279680 Sep 20 '22 at 13:11
  • @user279680 Sorry, I don't know what is Discord? Can you give me a link describe it? – Clara Sep 20 '22 at 14:14
3

(I added a second solution after the OP posted a follow-up request)

  • First solution: Increase the value of \arraystretch. This affects the height of all rows.

    My main suggestion would be to execute \renewcommand\arraystretch{1.25}. (The default value of this parameter is 1.0.) Additionally, I'd like to suggest that you (a) employ an array environment instead of a tabular environment (saving you from having to type lots of $ characters) and (b) replace \overline with \bar. Finally, I'd usse \mathrminstead of\text`.

  • Second solution: insert typographic "struts" to increase the height and depth of selected rows.

    Note the use of \TBstrut in the third array environment in the following screenshot.


enter image description here

\documentclass{article} % or some other suitable document class
\usepackage{array}

% Define typographic "struts", as suggested by Claudio Beccari % in a piece published in TeX and TUG News, Vol. 2, 1993. \newcommand\Tstrut{\rule{0pt}{2.4ex}} % "top" strut \newcommand\Bstrut{\rule[-0.9ex]{0pt}{0pt}} % "bottom" strut \newcommand{\TBstrut}{\Tstrut\Bstrut} % top&bottom struts

\begin{document} % default setup [ \begin{array}[t]{c|c|c|c} & \mathrm{A} & \bar{\mathrm{A}} & \ \hline \mathrm{B} &9& 6&15 \
\hline \bar{\mathrm{B}}&3&12&15 \
\hline & 12 & 18 & 30 \end{array} \qquad % 1st solution: increase value of \arraystretch \renewcommand\arraystretch{1.25} % <-- new \begin{array}[t]{c|c|c|c} & \mathrm{A} & \bar{\mathrm{A}} & \ \hline \mathrm{B} &9& 6&15 \ \hline \bar{\mathrm{B}}&3&12&15 \ \hline & 12 & 18 & 30 \end{array} \qquad % 2nd solution: insert typographic struts in rows 2 and 3 \renewcommand\arraystretch{1} % <-- reset to default \begin{array}[t]{c|c|c|c} & \mathrm{A} & \bar{\mathrm{A}} & \ \hline \mathrm{B} &9& 6&15 \TBstrut \ % <-- note \TBstrut \hline \bar{\mathrm{B}}&3&12&15 \TBstrut \ % <-- note \TBstrut \hline & 12 & 18 & 30 \end{array} ] \end{document}

Mico
  • 506,678
  • 1
    can you just do it for the second and third row also? – user279680 Sep 20 '22 at 13:20
  • 1
    i like it more with arraystretch{1.25} but thank you already very much – user279680 Sep 20 '22 at 13:22
  • @user279680 - Please see my updated answer, which provides an alternative answer that relies on inserting typographical struts in just rows 2 and 3 of the array environment. (I've also set the value of \arraystretch to 1.25 in the first solution.) – Mico Sep 20 '22 at 13:50
2

Here is an option with nicematrix and booktabs (which provides the \midrule command).

enter image description here

\documentclass{article}

\usepackage{amsmath, nicematrix, booktabs}

\begin{document}

\begin{NiceTabular}{c|c|c|c} &$\text{A}$&$\overline{\text{A}}$&\ \midrule $\text{B}$&9&6&15\ \midrule $\overline{\text{B}}$&3&12&15\ \midrule &12&18&30 \end{NiceTabular}

\end{document}

Sandy G
  • 42,558