创建具有多行选项固定宽度和换行文本的表格

创建具有多行选项固定宽度和换行文本的表格

我正在尝试使用多行选项创建一个表。我正在使用以下代码:

\documentclass[10pt]{article}
%\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{textcomp}
\usepackage{microtype}
\usepackage{graphicx}
\usepackage{multirow}

\begin{document}
\begin{table}[h]
    \newcommand{\lambdabar}{{\mkern0.75mu\mathchar '26\mkern -9.75mu\lambda}}
    \centering
    \begin{tabular}{r@{=}ll}
        \hline
        \hline
            $a_0$ & $\frac{\hbar^2}{m e^2}$
             & \multirow{2}{7cm}{Bohr (radius of electron orbit in Bohr's model of Hydrogen)} \\ 
              & $5.29\times10^{-9}$ & \\
            $\lambdabar_c$ & $\alpha a_0 = \frac{\hbar}{m c}$
              & \multirow{2}{7cm}{Reduced Compton wavelength ($\lambda_c = \lambda_c/2$). $ \lambda_c $ is change of wavelength of photon scattered at 90\textdegree by a stationary electron due to recoil of electron.} \\ 
               & $3.86159\times10^{-11} $cm & \\
            $ r_0 $ & $\alpha^2 a_0 = \alpha \lambdabar_c = \frac{d^2}{m c^2}$
            &  \multirow{2}{7cm}{Classical radius of electron (size for which electrostatic self energy equals rest mass energy)} \\ 
             & $2.81794\times10^{-13}$cm  & \\
        \hline
        \hline
    \end{tabular} 
\end{table}
\end{document}

我得到了以下输出: 在此处输入图片描述

这里我们可以看到最后两行出现在第三行和第四行。为什么会出现这种情况?如何才能使其正确?

答案1

multirow不适用于在一个表格单元格中拥有更多行。为此,您应该使用适当类型的列,例如p{<column width>}或使用tabularx(如我在下面的示例中使用的)tabulary等。对于数学内容,最好以某种方式声明表格列>{$}c<{$}(或其他类型的列)。我希望下面的例子能够对您有所帮助。

\documentclass[10pt]{article}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{textcomp}
\usepackage{tabularx}

\begin{document}
\begin{table}[h]
    \newcommand{\lambdabar}{{\mkern0.75mu\mathchar '26\mkern -9.75mu\lambda}}
    \renewcommand{\tabularxcolumn}[1]{m{#1}}
    \renewcommand{\arraystretch}{1.4}
    \centering
    \begin{tabularx}{\hsize}{>{$}m{4cm}<{$}X}
        \hline
        \hline
a_0=\dfrac{\hbar^2}{m e^2}=5.29\times10^{-9}
            & Bohr (radius of electron orbit in Bohr's model of Hydrogen)   \\
\begin{aligned}
\lambdabar_c  & =\alpha a_0 = \dfrac{\hbar}{m c}\newline\\
              & = 3.86159\times10^{-11}\ \text{cm}
\end{aligned}
            &   Reduced Compton wavelength ($\lambda_c=\lambda_c/2$). $\lambda_c$ is change of wavelength of photon scattered at 90\textdegree by a stationary electron due to recoil of electron.                             \\
\begin{aligned}
r_0 & = \alpha^2 a_0 = \alpha\lambdabar_c = \dfrac{d^2}{m c^2}\\
    & = 2.81794\times10^{-13}\ \text{cm}
\end{aligned}
            &  Classical radius of electron (size for which electrostatic self energy equals rest mass energy)                                        \\
        \hline
        \hline
    \end{tabularx}
\end{table}
\end{document}

在此处输入图片描述

答案2

这是 TABstacked 的替代方案。

\documentclass[10pt]{article}
%\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{textcomp}
\usepackage{microtype}
\usepackage{graphicx}
\usepackage{multirow}
\usepackage{tabstackengine}
\TABstackMath
\begin{document}
\begin{table}[ht]
  \renewcommand\arraystretch{1.4}
  \setstackgap{L}{1.3\normalbaselineskip}
    \newcommand{\lambdabar}{{\mkern0.75mu\mathchar '26\mkern -9.75mu\lambda}}
    \centering
    \begin{tabular}{lp{2.65in}}
        \hline
        \hline
        {\alignLongunderstack{a_0 =&\frac{\hbar^2}{m e^2}\\
           =&5.29\times10^{-9}}}
        & Bohr (radius of electron orbit in Bohr's model of Hydrogen) \\ 
        {\alignLongunderstack{\lambdabar_c =& \alpha a_0 = \frac{\hbar}{m c}\\
           =&3.86159\times10^{-11} \text{cm}}}
        & Reduced Compton wavelength ($\lambda_c = \lambda_c/2$). 
          $ \lambda_c $ is change of wavelength of photon scattered 
          at 90\textdegree by a stationary electron due to recoil 
          of electron. \\ 
        {\alignLongunderstack{ r_0  =& \alpha^2 a_0 = \alpha \lambdabar_c 
          = \frac{d^2}{m c^2}\\=&2.81794\times10^{-13} \text{ cm}}}
        &  Classical radius of electron (size for which electrostatic 
          self energy equals rest mass energy) \\ 
        \hline
        \hline
    \end{tabular} 
\end{table}

\end{document}

在此处输入图片描述

答案3

第三行(减少...)的文本占用 4 行,而不是 2 行。要修复此问题,您可以输入 '\multirow{2}...`,然后留下 2 个空行。

\documentclass[10pt]{article}
%\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{textcomp}
\usepackage{microtype}
\usepackage{graphicx}
\usepackage{multirow}

\begin{document}
\begin{table}[h]
\newcommand{\lambdabar}{{\mkern0.75mu\mathchar '26\mkern -9.75mu\lambda}}
\centering
\begin{tabular}{r@{=}ll}
    \hline
    \hline
        $a_0$ & $\frac{\hbar^2}{m e^2}$
         & \multirow{2}{7cm}{Bohr (radius of electron orbit in Bohr's model of Hydrogen)} \\ 
          & $5.29\times10^{-9}$ & \\
        $\lambdabar_c$ & $\alpha a_0 = \frac{\hbar}{m c}$
          & \multirow{4}{7cm}{Reduced Compton wavelength ($\lambda_c =     \lambda_c/2$). $ \lambda_c $ is change of wavelength of photon scattered at 90\textdegree by a stationary electron due to recoil of electron.} \\ 
           & $3.86159\times10^{-11} $cm & \\
           \\
           \\
        $ r_0 $ & $\alpha^2 a_0 = \alpha \lambdabar_c = \frac{d^2}{m c^2}$
        &  \multirow{2}{7cm}{Classical radius of electron (size for which electrostatic self energy equals rest mass energy)} \\ 
         & $2.81794\times10^{-13}$cm  & \\
    \hline
    \hline
\end{tabular} 
\end{table}
\end{document}

这会产生副作用,即=在某些行中带有符号。我将从列规范中取出它们,并将第 1 列和第 2 列放在相同的位置。

相关内容