Remove vertical spacing around align* environment in tabularx cell

  • Context: LaTeX 
  • Thread starter Thread starter Wrichik Basu
  • Start date Start date
  • Tags Tags
    Cell Vertical
Click For Summary
SUMMARY

This discussion addresses the issue of excessive vertical spacing around the align* environments within a tabularx cell in LaTeX. The user successfully resolved this by setting the lengths \abovedisplayskip, \belowdisplayskip, \abovedisplayshortskip, and \belowdisplayshortskip to 0pt, which normalized the spacing. The final LaTeX code reflects these adjustments, providing a more visually appealing table layout.

PREREQUISITES
  • Familiarity with LaTeX document preparation system
  • Understanding of the tabularx package for table formatting
  • Knowledge of mathematical environments in LaTeX, specifically align*
  • Basic understanding of LaTeX length commands and spacing adjustments
NEXT STEPS
  • Explore advanced table formatting using the tabularx package
  • Learn about customizing spacing in LaTeX documents
  • Investigate the mathtools package for enhanced mathematical typesetting
  • Study the use of makecell for improved cell formatting in tables
USEFUL FOR

LaTeX users, academic writers, and anyone involved in creating complex tables with mathematical content who seeks to optimize the presentation of their documents.

Wrichik Basu
Science Advisor
Insights Author
Gold Member
Messages
2,180
Reaction score
2,690
I have created a table which has some equations in it. The LaTeX code is as follows:

[CODE title="LaTeX code"]\documentclass[a4paper,12pt]{article}

\usepackage{mathtools}
\usepackage{physics}
\usepackage{tabularx}
\usepackage{makecell}

\newcommand{\tev}{\ensuremath{\mathcal{U}}}
\newcommand{\sch}[1]{\ensuremath{#1^\mathrm{(S)}}}
\newcommand{\hei}[1]{\ensuremath{#1^\mathrm{(H)}}}
\newcommand{\Ham}{\ensuremath{\mathcal{H}}}
\newcommand{\bfnt}[1]{{\bfseries #1}}
\newcommand{\ifnt}[1]{{\itshape #1}}

\begin{document}

\begin{center}
\begin{tabularx}{\linewidth}{|l|X|X|}

\hline

{} & \multicolumn{1}{c|}{\bfnt{Schr\"odinger picture}} & \multicolumn{1}{c|}{\bfnt{Heisenberg picture}} \\

\hline

\textbf{State ket} & \makecell[X]{\vspace{0.2cm} Moving:\\%
\vbox{%
\begin{align*}
\ket{\alpha, t_0; t} &= \tev \ket{\alpha, t_0} \\[0.5em]
i \hbar \pdv{t} \ket{\alpha, t_0; t} &= \Ham \ket{\alpha, t_0; t}.
\end{align*}%
}} & Stationary \\

\hline

\textbf{Observable} & Stationary & \makecell[X]{\vspace{0.3cm} Moving:\\%
\vbox{%
\begin{align*}
\hei{A}(t) &= \tev^\dagger(t) \sch{A} \tev(t) \\[0.7em]
\dv{\hei{A}}{t} &= \dfrac{1}{i\hbar} \comm{\hei{A}}{\Ham}.
\end{align*}%
}} \\

\hline

\textbf{Base ket} & Stationary & \makecell[X]{\vspace{0.3cm} Moving oppositely:\\%
\vbox{%
\begin{align*}
\ket{a', t}_\mathrm{H} &= \tev^\dagger \ket{a'}; \\[0.7em]
i\hbar\pdv{t} \ket{a', t}_\mathrm{H} &= -\Ham \ket{a', t}_\mathrm{H}.
\end{align*}%
}} \\

\hline

\end{tabularx}
\end{center}

\end{document}[/CODE]

The code renders as shown below:

2022-08-14_16-29-1.png

As you can see, there is a lot of extra vertical space around the align* environments, which I have marked with blue arrows. How can I remove this space?
 
Physics news on Phys.org
The lengths you need to set are
Code:
\abovedisplayskip
\belowdisplayskip
\abovedisplayshortskip
\belowdisplayshortskip
 
  • Like
Likes   Reactions: Wrichik Basu
@pasmith Thanks. Setting those lengths to 0pt reduced the spacing to what is normal. This is how it looks now:

1660491578041.png

The entire code (for future visitors):
[CODE title="LaTeX code" highlight="19-22"]\documentclass[a4paper,12pt]{article}

\usepackage{mathtools}
\usepackage{physics}
\usepackage{tabularx}
\usepackage{makecell}

\newcommand{\tev}{\ensuremath{\mathcal{U}}}
\newcommand{\sch}[1]{\ensuremath{#1^\mathrm{(S)}}}
\newcommand{\hei}[1]{\ensuremath{#1^\mathrm{(H)}}}
\newcommand{\Ham}{\ensuremath{\mathcal{H}}}
\newcommand{\bfnt}[1]{{\bfseries #1}}
\newcommand{\ifnt}[1]{{\itshape #1}}

\begin{document}

\bgroup

\setlength{\abovedisplayskip}{0pt}
\setlength{\belowdisplayskip}{0pt}
\setlength{\abovedisplayshortskip}{0pt}
\setlength{\belowdisplayshortskip}{0pt}

\begin{center}
\begin{tabularx}{\linewidth}{|l|X|X|}

\hline

{} & \multicolumn{1}{c|}{\bfnt{Schr\"odinger picture}} & \multicolumn{1}{c|}{\bfnt{Heisenberg picture}} \\

\hline

\textbf{State ket} & \makecell[X]{\vspace{0.2cm} Moving:\\%
\vbox{%
\begin{align*}
\ket{\alpha, t_0; t} &= \tev \ket{\alpha, t_0} \\[0.5em]
i \hbar \pdv{t} \ket{\alpha, t_0; t} &= \Ham \ket{\alpha, t_0; t}.
\end{align*}%
}} & Stationary \\

\hline

\textbf{Observable} & Stationary & \makecell[X]{\vspace{0.3cm} Moving:\\%
\vbox{%
\begin{align*}
\hei{A}(t) &= \tev^\dagger(t) \sch{A} \tev(t) \\[0.7em]
\dv{\hei{A}}{t} &= \dfrac{1}{i\hbar} \comm{\hei{A}}{\Ham}.
\end{align*}%
}} \\

\hline

\textbf{Base ket} & Stationary & \makecell[X]{\vspace{0.3cm} Moving oppositely:\\%
\vbox{
\begin{align*}
\ket{a', t}_\mathrm{H} &= \tev^\dagger \ket{a'}; \\[0.7em]
i\hbar\pdv{t} \ket{a', t}_\mathrm{H} &= -\Ham \ket{a', t}_\mathrm{H}.
\end{align*}
}} \\

\hline

\end{tabularx}
\end{center}

\egroup

\end{document}[/CODE]
 

Similar threads

  • · Replies 2 ·
Replies
2
Views
4K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 9 ·
Replies
9
Views
6K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 2 ·
Replies
2
Views
6K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 4 ·
Replies
4
Views
5K
  • · Replies 766 ·
26
Replies
766
Views
742K