垂直對齊表格儲存格中的內容

垂直對齊表格儲存格中的內容

我有以下程式碼:

\begin{table}[h]
\begin{tabularx}{\textwidth}{ m{4cm}  X }
                            & Derivations \\
    $v=v_0+at$              & test \newline test \newline test \\
    $x=x_0+v_0t+½at^2$      & a\\
    $v^2-v_0^2=2a(x-x_0)$   & a\\
    $x-x_0=½t(v_0-v)$       & a  
\end{tabularx}
\end{table}

m{4cm}製作一個 4 公分寬的柱子垂直居中的內容根據這個答案另一個問題。我已經添加了array包。但不會發生垂直居中;結果是:

在此輸入影像描述

如何使左列(由$..$方程式組成)中的內容垂直居中對齊。

答案1

包中的程式碼makecell非常簡單:它允許在\makecell\thead命令中換行。請注意,預設對齊方式是垂直和水平對齊。

\documentclass{article}
\usepackage{tabularx}
\usepackage{makecell}
\renewcommand\cellalign{lc}

\begin{document}

\begin{table}[h]
  \begin{tabularx}{\linewidth}{ m{4cm} X}
                          & Derivations \\
    $v=v_0+at$ & \makecell{test \\ test \\ test }\\
    $x=x_0+v_0t+½at^2$ & a \\
    $v^2-v_0^2=2a(x-x_0)$ & a \\
    $x-x_0=½t(v_0-v)$ & a \\
  \end{tabularx}
\end{table}

\end{document} 

在此輸入影像描述

答案2

我不會使用\newline您創建較大單元格的方式來居中。

\documentclass{article}
\usepackage{tabularx}
\usepackage{multirow}
\begin{document}
\begin{table}[h]
\begin{tabularx}{\textwidth}{ m{4cm}  X }
                                  & Derivations \\
    \multirow{3}{4cm}{$v=v_0+at$} & test \\
                                  & test \\
                                  & test \\
    $x=x_0+v_0t+½at^2$            & a \\
    $v^2-v_0^2=2a(x-x_0)$         & a \\
    $x-x_0=½t(v_0-v)$             & a \\
\end{tabularx}
\end{table}
\end{document}

這使:

多行結果

意味著您不一定需要m{4cm},但如果您希望其他內容在單元格中垂直居中,則可以保留它。

將來,請在您的 MWE 中發布您的序言:)。

答案3

一種解法是在等式兩邊都使用 \hfil

\documentclass{article}
\usepackage{tabularx}
\begin{document}
\begin{table}[h]
\begin{tabularx}{\textwidth}{ m{4cm}  X }
                        & Derivations \\
\hfil$v=v_0+at$\hfil             & test \newline test \newline test \\
\hfil$x=x_0+v_0t+½at^2$\hfil     & a\\
\hfil$v^2-v_0^2=2a(x-x_0)$\hfil  & a\\
\hfil$x-x_0=½t(v_0-v)$\hfil     & a  
\end{tabularx}
\end{table}
\end{document}

在此輸入影像描述

相關內容