2

I am trying to maintain the uniformity of equations living in different cells inside a table. Here is the code:

\begin{center}
\begin{tabular}{|c|c|c|}
\hline
 $Y^{2}B^{2}$ & $Z^{2}\chi^{2}$ & $X^{2}\lambda^{2}$ \\ \hline
 $\mathcal{O}_{1} = \mathrm{wc}_{1}(\partial_{\mu}A_{\nu}-\partial_{\nu}A_{\mu})(\partial^{\mu}A^{\nu}-\partial^{\nu}A^{\mu})$ & $\mathcal{O}_{7}= \mathrm{wc}_{7}Z^{\mu\nu}Z_{\mu}(\phi^{\dagger}\phi)^{2}$ & $\mathcal{O}_{9} = \gamma^{\mu}\gamma^{\nu}+\gamma^{\nu}\gamma^{\mu}$ \\ \hline
 $\mathcal{O}_{2} = \mathrm{wc}_{2} X^{\mu}X_{\mu}B^{\rho\sigma}B_{\rho\sigma}$ & $\mathcal{O}_{8} = \mathrm{wc}_{8}\bar{\psi}(i\gamma^{\mu}\partial_{\mu}-m)\psi-\frac{1}{4}F_{\mu\nu}F^{\mu\nu}$ & $\mathcal{O}_{10} = g^{\mu\nu}$ \\ \hline
\end{tabular}
\end{center}

It looks like a mess because of poor alignment. In addition to that, the expressions are very close to each other makes the equations unreadable. Can anyone guide me on how to fix these two issues:

  1. Same alignment for all expressions living in different cells.
  2. Optimizing the cell size to make expressions readable.
2
  • What exactly does "uniform alignment" refer to in this context? As far as I can tell, all contents should be horizontally centered inside of their cells. Waht would you like to achieve instead? Please also make your code compilable by adding the documentclass as well as the relevant packages. If you use geometry, please also include the corresponding settings in your MWE. Currently, your table is quite wide and depending on the settings it ight be possible that it does not fit into the available space.
    – leandriis
    Commented Jan 10, 2021 at 18:40
  • Thank you for your suggestions. I am doing the needful change as per your guideline.
    – Mass
    Commented Jan 10, 2021 at 18:44

3 Answers 3

3

Do you mean something like this:

\begin{center}
\renewcommand{\arraystretch}{1.5}
\begin{tabular}{|l|l|l|}
\hline
 \multicolumn{1}{|c|}{$Y^{2}B^{2}$} &  \multicolumn{1}{c|}{$Z^{2}\chi^{2}$} &  \multicolumn{1}{c|}{$X^{2}\lambda^{2}$} \\ \hline
 $\mathcal{O}_{1} = \mathrm{wc}_{1}(\partial_{\mu}A_{\nu}-\partial_{\nu}A_{\mu})(\partial^{\mu}A^{\nu}-\partial^{\nu}A^{\mu})$ & $\mathcal{O}_{7}= \mathrm{wc}_{7}Z^{\mu\nu}Z_{\mu}(\phi^{\dagger}\phi)^{2}$ & $\mathcal{O}_{9} = \gamma^{\mu}\gamma^{\nu}+\gamma^{\nu}\gamma^{\mu}$ \\ \hline
 $\mathcal{O}_{2} = \mathrm{wc}_{2} X^{\mu}X_{\mu}B^{\rho\sigma}B_{\rho\sigma}$ & $\mathcal{O}_{8} = \mathrm{wc}_{8}\bar{\psi}(i\gamma^{\mu}\partial_{\mu}-m)\psi-\frac{1}{4}F_{\mu\nu}F^{\mu\nu}$ & $\mathcal{O}_{10} = g^{\mu\nu}$ \\ \hline
\end{tabular}
\end{center}

?

enter image description here

3
  • 1
    This is exactly what I was looking for. Thank you!
    – Mass
    Commented Jan 10, 2021 at 18:42
  • 1
    Welcome ... you can play around with the \arraystretch factor
    – koleygr
    Commented Jan 10, 2021 at 18:42
  • 1
    Noted with thanks.
    – Mass
    Commented Jan 10, 2021 at 18:43
3

Stll another variant: I replaced \arraystretch with some vertical padding at the top and bottom of cells obtained with the cellspace package. Another small improvement is the use of the medsize fractions n defined by nccmath, to avoid the size discrepancy between fractions in a tabular or array environment and the rest of the formula.

\documentclass{article}
\usepackage[hmargin=2.5cm]{geometry}
\usepackage{nccmath}
\usepackage{array}
\usepackage[column=O, math]{cellspace}
\setlength{\cellspacetoplimit}{4pt}
\setlength{\cellspacebottomlimit}{4pt}

\begin{document}

\[
\begin{tabular}{|*{3}{>{$}Ol<{$}|}}
\hline
 \multicolumn{1}{|c|}{$ Y^{2}B^{2} $}
   & \multicolumn{1}{c|}{$ Z^{2}\chi^{2} $}
     & \multicolumn{1}{c|}{$ X^{2}\lambda^{2} $} \\ \hline
 \mathcal{O}_{1} = \mathrm{wc}_{1}(\partial_{\mu}A_{\nu}-\partial_{\nu}A_{\mu})(\partial^{\mu}A^{\nu}-\partial^{\nu}A^{\mu}) & \mathcal{O}_{7}= \mathrm{wc}_{7}Z^{\mu\nu}Z_{\mu}(\phi^{\dagger}\phi)^{2}
 & \mathcal{O}_{9\phantom{1}} = \gamma^{\mu}\gamma^{\nu}+\gamma^{\nu}\gamma^{\mu} \\
\hline
 \mathcal{O}_{2} = \mathrm{wc}_{2} X^{\mu}X_{\mu}B^{\rho\sigma}B_{\rho\sigma}
 & \mathcal{O}_{8} = \mathrm{wc}_{8}\bar{\psi}(i\gamma^{\mu}\partial_{\mu}-m)\psi-\mfrac{1}{4}F_{\mu\nu}F^{\mu\nu}
 & \mathcal{O}_{10} = g^{\mu\nu} \\
\hline
\end{tabular}
\]

\end{document} 

enter image description here

3

Building upon koleygr's code, here is a slightly different version using an array instead of a tabular and \phantom to improve the alignment of the = in the last column:

enter image description here

\documentclass{article}
\usepackage[margin=2cm]{geometry}
\begin{document}

\[
\renewcommand{\arraystretch}{1.5}
\begin{array}{|l|l|l|}
\hline
 \multicolumn{1}{|c|}{Y^{2}B^{2}} 
   &  \multicolumn{1}{c|}{Z^{2}\chi^{2}} 
     &  \multicolumn{1}{c|}{X^{2}\lambda^{2}} \\ \hline
 \mathcal{O}_{1} = \mathrm{wc}_{1}(\partial_{\mu}A_{\nu}-\partial_{\nu}A_{\mu})(\partial^{\mu}A^{\nu}-\partial^{\nu}A^{\mu}) & \mathcal{O}_{7}= \mathrm{wc}_{7}Z^{\mu\nu}Z_{\mu}(\phi^{\dagger}\phi)^{2} 
 & \mathcal{O}_{9\phantom{1}} = \gamma^{\mu}\gamma^{\nu}+\gamma^{\nu}\gamma^{\mu} \\ 
\hline
 \mathcal{O}_{2} = \mathrm{wc}_{2} X^{\mu}X_{\mu}B^{\rho\sigma}B_{\rho\sigma} 
 & \mathcal{O}_{8} = \mathrm{wc}_{8}\bar{\psi}(i\gamma^{\mu}\partial_{\mu}-m)\psi-\frac{1}{4}F_{\mu\nu}F^{\mu\nu} 
 & \mathcal{O}_{10} = g^{\mu\nu} \\ 
\hline
\end{array}
\]
\end{document}

Update:

In order to increase the horizontal space between the text and a vertical line, you can adjust the value of \arraycolsep to suit your needs. To change the vertical space between the text and a horizontal line, you could use \setcellgapes from the makecell package. The following MWE contains three somewhat exaggerated examples to show the effect of the two commands:

enter image description here

\documentclass{article}
\usepackage[margin=2cm]{geometry}

\usepackage{makecell}
\begin{document}

\[
\renewcommand{\arraycolsep}{10pt}
\setcellgapes{\arraycolsep}
\makegapedcells
\begin{array}{|l|l|l|}
\hline
 \multicolumn{1}{|c|}{Y^{2}B^{2}} 
   &  \multicolumn{1}{c|}{Z^{2}\chi^{2}} 
     &  \multicolumn{1}{c|}{X^{2}\lambda^{2}} \\ \hline
 \mathcal{O}_{1} = \mathrm{wc}_{1}(\partial_{\mu}A_{\nu}-\partial_{\nu}A_{\mu})(\partial^{\mu}A^{\nu}-\partial^{\nu}A^{\mu}) & \mathcal{O}_{7}= \mathrm{wc}_{7}Z^{\mu\nu}Z_{\mu}(\phi^{\dagger}\phi)^{2} 
 & \mathcal{O}_{9\phantom{1}} = \gamma^{\mu}\gamma^{\nu}+\gamma^{\nu}\gamma^{\mu} \\ 
\hline
 \mathcal{O}_{2} = \mathrm{wc}_{2} X^{\mu}X_{\mu}B^{\rho\sigma}B_{\rho\sigma} 
 & \mathcal{O}_{8} = \mathrm{wc}_{8}\bar{\psi}(i\gamma^{\mu}\partial_{\mu}-m)\psi-\frac{1}{4}F_{\mu\nu}F^{\mu\nu} 
 & \mathcal{O}_{10} = g^{\mu\nu} \\ 
\hline
\end{array}
\]

\[
\renewcommand{\arraycolsep}{5pt}
\setcellgapes{20pt}
\makegapedcells
\begin{array}{|l|l|l|}
\hline
 \multicolumn{1}{|c|}{Y^{2}B^{2}} 
   &  \multicolumn{1}{c|}{Z^{2}\chi^{2}} 
     &  \multicolumn{1}{c|}{X^{2}\lambda^{2}} \\ \hline
 \mathcal{O}_{1} = \mathrm{wc}_{1}(\partial_{\mu}A_{\nu}-\partial_{\nu}A_{\mu})(\partial^{\mu}A^{\nu}-\partial^{\nu}A^{\mu}) & \mathcal{O}_{7}= \mathrm{wc}_{7}Z^{\mu\nu}Z_{\mu}(\phi^{\dagger}\phi)^{2} 
 & \mathcal{O}_{9\phantom{1}} = \gamma^{\mu}\gamma^{\nu}+\gamma^{\nu}\gamma^{\mu} \\ 
\hline
 \mathcal{O}_{2} = \mathrm{wc}_{2} X^{\mu}X_{\mu}B^{\rho\sigma}B_{\rho\sigma} 
 & \mathcal{O}_{8} = \mathrm{wc}_{8}\bar{\psi}(i\gamma^{\mu}\partial_{\mu}-m)\psi-\frac{1}{4}F_{\mu\nu}F^{\mu\nu} 
 & \mathcal{O}_{10} = g^{\mu\nu} \\ 
\hline
\end{array}
\]

\[
\renewcommand{\arraycolsep}{20pt}
\setcellgapes{5pt}
\makegapedcells
\begin{array}{|l|l|l|}
\hline
 \multicolumn{1}{|c|}{Y^{2}B^{2}} 
   &  \multicolumn{1}{c|}{Z^{2}\chi^{2}} 
     &  \multicolumn{1}{c|}{X^{2}\lambda^{2}} \\ \hline
 \mathcal{O}_{1} = \mathrm{wc}_{1}(\partial_{\mu}A_{\nu}-\partial_{\nu}A_{\mu})(\partial^{\mu}A^{\nu}-\partial^{\nu}A^{\mu}) & \mathcal{O}_{7}= \mathrm{wc}_{7}Z^{\mu\nu}Z_{\mu}(\phi^{\dagger}\phi)^{2} 
 & \mathcal{O}_{9\phantom{1}} = \gamma^{\mu}\gamma^{\nu}+\gamma^{\nu}\gamma^{\mu} \\ 
\hline
 \mathcal{O}_{2} = \mathrm{wc}_{2} X^{\mu}X_{\mu}B^{\rho\sigma}B_{\rho\sigma} 
 & \mathcal{O}_{8} = \mathrm{wc}_{8}\bar{\psi}(i\gamma^{\mu}\partial_{\mu}-m)\psi-\frac{1}{4}F_{\mu\nu}F^{\mu\nu} 
 & \mathcal{O}_{10} = g^{\mu\nu} \\ 
\hline
\end{array}
\]


\end{document}
5
  • thank you for your valuable input. I am just curious, will it be possible to make cell size a litter bigger so that expressions in different cells become easily readable?
    – Mass
    Commented Jan 10, 2021 at 19:29
  • 1
    Do you want to increase the widths or the heights of the cells?
    – leandriis
    Commented Jan 10, 2021 at 19:32
  • I am afraid, you got me correct!
    – Mass
    Commented Jan 10, 2021 at 19:39
  • 1
    Since I am still not sure if you referred to width or height, I updated my anser to sho how you can adjust the width, the height or both. Feel free to adjust the values to suit your needs.
    – leandriis
    Commented Jan 10, 2021 at 20:13
  • Adjusting both height and width makes the table look elegant. Thank you!
    – Mass
    Commented Jan 10, 2021 at 20:21

You must log in to answer this question.

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