表格内文本垂直和水平居中

表格内文本垂直和水平居中

我想将表格内的所有文本水平和垂直居中,例如在示例代码中,文本“角速度”垂直和水平地位于其单元格的中心,而列的宽度没有变化(第1列和第3列的宽​​度为2厘米,第2列和第4列的宽度为5厘米)。

\documentclass{article}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{mathrsfs}
\usepackage{caption}
\usepackage{mathtools,amssymb}
\usepackage{amsthm,amssymb}
\usepackage{bm}
\begin{document}
\begin{table}[h]
    \begin{center}
        \renewcommand{\arraystretch}{1.35}
        \captionsetup{justification=centering}
        \caption{
        {List of variables} 
        }
        \label{tbl: List of variables}
        \begin{tabular}{|p{20mm}|p{50mm}|p{20mm}|p{50mm}|}
            \noalign{\hrule height 2pt}
            Variables       & Definition      & Variables       & Definition    \\
            \noalign{\hrule height 2pt}
            $\mathbf{J}  $                      & moment of inertia  matrix  &$\mathbf{C}_{L/B}$ & Direction Cosine Matrix \\
                \hline
   $\bm{q}$&quaternion vector&$\bm{\omega}_{L/B}$& angular velocity relative to LVLH coordinate system expressed in BFCS \\
   \hline
  $\mathbf{M}$& augmented skew-symmetric matrix  &$\sum{T}_{ext}$ & total external torque \\
   \hline
   $\mathbf{h}_B$ &angular momentum vector& $\bm{\omega}_{E/B}$&  angular velocity relative to ECI coordinate system expressed in BFCS \\
   \hline
   $\omega_{wx}$, $\omega_{wy}$, $\omega_{wz}$ & angular velocity of the RWs &$I_w$ & MOI of the RWs \\
   \hline
  $\omega_{j}$& angular velocity& $\bm{\omega}_{E/L}$ & the satellite's angular velocity relative to LVLH coordinate system with respect to ECI \\
   \hline
  $\bm{x}$&state vector & $\bm{u}$ & control torque vector\\
  \hline
  $T_s$ &  sampling time & $T_x$, $T_y$, $T_z$  &  applied torques  \\
  \hline
 $\alpha$, $\beta$ & fractional-order parameters & $\mathbf{Q}$, $\mathbf{R}$&weighting matrices\\
 \hline
   $\omega_{x}$, $\omega_{y}$, $\omega_{z}$& satellite angular velocity& $\bm{\omega}^\times_{L/B}$& the skew-symmetric matrix of the angular velocity  \\
   \hline
    $\bm{T}_{dis}$&disturbance torque&$v$&the velocity  of the satellite\\
   \hline
   $r$& the position of the satellite&&
\\
   \noalign{\hrule height 2pt}
        \end{tabular}
    \end{center}
\end{table}
\end{document}
'''

答案1

  • 您的表格比默认分页\textwidth定义的要宽。——您可以考虑通过在文档前言中添加“\usepackage{geometry}”来增加它。article
  • 简单的代码,可以使用包来编写所需的表格格式tabularray
\documentclass{article}
%---------------- show page layout. don't use in a real document!
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%
\usepackage{lipsum}% For dummy text. Don't use in a real document

\usepackage{mathrsfs}
\usepackage{caption}
\usepackage{bm}
\usepackage{tabularray}

\begin{document}
    \begin{table}[h]
\caption{List of variables}
\label{tbl: List of variables}
\begin{tblr}{hline{1,2,Z} = 1pt, hline{3-Y}, vlines, 
             colspec = {*{2}{Q[c,m, mode=math] X[c,m]} },
             colsep  = 4pt,
             row{1}  = {mode=text}
             }
Variables       & Definition    
                    & Variables
                        & Definition                \\
\mathbf{J}      & moment of inertia  matrix  
                    & \mathbf{C}_{L/B}
                        & Direction Cosine Matrix   \\
\bm{q}          & cquaternion vector
                    & \bm{\omega}_{L/B}
                        & angular velocity relative to LVLH coordinate system expressed in BFCS \\
\mathbf{M}      & augmented skew-symmetric matrix  
                    & \sum{T}_{\mathrm{ext}}
                        & total external torque     \\
\mathbf{h}_B    & angular momentum vector
                    & \bm{\omega}_{E/B}
                        & angular velocity relative to ECI coordinate system expressed in BFCS \\
\omega_{wx}, \omega_{wy}, \omega_{wz}
                & angular velocity of the RWs
                    & I_w
                        & MOI of the RWs            \\
\omega_{j}      & angular velocity
                    & \bm{\omega}_{E/L}
                        & the satellite's angular velocity relative to LVLH coordinate system with respect to ECI \\
\bm{x}          & state vector
                    & \bm{u}
                        & control torque vector     \\
T_s             &  sampling time
                    & T_x, T_y, T_z
                        &  applied torques          \\
\alpha, \beta   & fractional-order parameters
                    & \mathbf{Q}, \mathbf{R}
                        & weighting matrices        \\
\omega_{x}, \omega_{y}, \omega_{z}
                & satellite angular velocity
                    & \bm{\omega}^\times_{L/B}
                        & the skew-symmetric matrix of the angular velocity  \\
\bm{T}_{dis}    & disturbance torque
                    & v & the velocity  of the satellite    \\
r               & the position of the satellite
                    &   &                           \\
\end{tblr}
    \end{table}
\end{document}

在此处输入图片描述

编辑: 顺便说一句,我认为如果单元格内容左对齐,而不是垂直居中,省略所有垂直线,并且对于水平规则使用booktabs第一、第二和最后一条规则,表格会更漂亮(看起来更专业):

\documentclass{article}
%\usepackage{geometry}
%---------------- show page layout. don't use in a real document!
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%
\usepackage{lipsum}% For dummy text. Don't use in a real document

\usepackage{mathrsfs}
\usepackage{caption}
\usepackage{bm}
\usepackage{tabularray}
\UseTblrLibrary{booktabs}

\begin{document}
    \begin{table}[ht]
\caption{List of variables}
\label{tbl: List of variables}
\begin{tblr}{colsep  = 4pt,
             colspec = {@{} *{2}{Q[l, mode=math] X[l, font=\linespread{0.88}\selectfont} @{}},
             row{1}  = {mode=text}
             row{2-Z} = {rowsep=3pt}
             }
    \toprule
Variables       & Definition    
                    & Variables
                        & Definition                \\
    \midrule
\mathbf{J}      & moment of inertia  matrix  
                    & \mathbf{C}_{L/B}
                        & Direction Cosine Matrix   \\
\bm{q}          & cquaternion vector
                    & \bm{\omega}_{L/B}
                        & angular velocity relative to LVLH coordinate system expressed in BFCS \\
\mathbf{M}      & augmented skew-symmetric matrix  
                    & \sum{T}_{\mathrm{ext}}
                        & total external torque     \\
\mathbf{h}_B    & angular momentum vector
                    & \bm{\omega}_{E/B}
                        & angular velocity relative to ECI coordinate system expressed in BFCS \\
\omega_{wx}, \omega_{wy}, \omega_{wz}
                & angular velocity of the RWs
                    & I_w
                        & MOI of the RWs            \\
\omega_{j}      & angular velocity
                    & \bm{\omega}_{E/L}
                        & the satellite's angular velocity relative to LVLH coordinate system with respect to ECI \\
\bm{x}          & state vector
                    & \bm{u}
                        & control torque vector     \\
T_s             &  sampling time
                    & T_x, T_y, T_z
                        &  applied torques          \\
\alpha, \beta   & fractional-order parameters
                    & \mathbf{Q}, \mathbf{R}
                        & weighting matrices        \\
\omega_{x}, \omega_{y}, \omega_{z}
                & satellite angular velocity
                    & \bm{\omega}^\times_{L/B}
                        & the skew-symmetric matrix of the angular velocity  \\
\bm{T}_{dis}    & disturbance torque
                    & v & the velocity  of the satellite    \\
r               & the position of the satellite
                    &   &                           \\
    \bottomrule
\end{tblr}
    \end{table}
\end{document}

在此处输入图片描述

(红线表示页面布局)

答案2

对于垂直和水平居中的文本,我们可以使用{\centering\arraybackslash}m{width}with 包array。以及用于垂直和水平烧灼文本的代码:

\documentclass{article}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{mathrsfs}
\usepackage{caption}
\usepackage{mathtools,amssymb}
\usepackage{amsthm,amssymb}
\usepackage{bm}
\usepackage{array}
\begin{document}
\begin{table}[h]
    \begin{center}
        \renewcommand{\arraystretch}{1.35}
        \captionsetup{justification=centering}
        \caption{
        {List of variables} 
        }
        \label{tbl: List of variables}
        \begin{tabular}{|>{\centering\arraybackslash}m{.2\linewidth}|>{\centering\arraybackslash}m{0.4\linewidth}|>{\centering\arraybackslash}m{.2\linewidth}|>{\centering\arraybackslash}m{.4\linewidth}|}
            \noalign{\hrule height 2pt}
            Variables       & Definition      & Variables       & Definition    \\
            \noalign{\hrule height 2pt}
            $\mathbf{J}  $                      & moment of inertia  matrix  &$\mathbf{C}_{L/B}$ & Direction Cosine Matrix \\
                \hline
   $\bm{q}$&quaternion vector&$\bm{\omega}_{L/B}$& angular velocity relative to LVLH coordinate system expressed in BFCS \\
   \hline
  $\mathbf{M}$& augmented skew-symmetric matrix  &$\sum{T}_{ext}$ & total external torque \\
   \hline
   $\mathbf{h}_B$ &angular momentum vector& $\bm{\omega}_{E/B}$&  angular velocity relative to ECI coordinate system expressed in BFCS \\
   \hline
   $\omega_{wx}$, $\omega_{wy}$, $\omega_{wz}$ & angular velocity of the RWs &$I_w$ & MOI of the RWs \\
   \hline
  $\omega_{j}$& angular velocity& $\bm{\omega}_{E/L}$ & the satellite's angular velocity relative to LVLH coordinate system with respect to ECI \\
   \hline
  $\bm{x}$&state vector & $\bm{u}$ & control torque vector\\
  \hline
  $T_s$ &  sampling time & $T_x$, $T_y$, $T_z$  &  applied torques  \\
  \hline
 $\alpha$, $\beta$ & fractional-order parameters & $\mathbf{Q}$, $\mathbf{R}$&weighting matrices\\
 \hline
   $\omega_{x}$, $\omega_{y}$, $\omega_{z}$& satellite angular velocity& $\bm{\omega}^\times_{L/B}$& the skew-symmetric matrix of the angular velocity  \\
   \hline
    $\bm{T}_{dis}$&disturbance torque&$v$&the velocity  of the satellite\\
   \hline
   $r$& the position of the satellite&&
\\
   \noalign{\hrule height 2pt}
        \end{tabular}
    \end{center}
\end{table}
\end{document}

在此处输入图片描述

相关内容