垂直居中表格元素

垂直居中表格元素

我有下表,但我想将表格的第一行(中置驱动电机)垂直居中。我应该这样做吗?

\begin{table}[h]
\begin{center}
\begin{tabularx}{\textwidth}{ X  X }\hline
\multicolumn{2}{c}{\textbf{\large{Mid-drive motors}}} \\ [1.5ex]
  \hline
  \textbf{Advantages} & \textbf{Disadvantages} \\
  \hline
  Use the own gears of the bicycle & Wear a tear \\
  Consistent in steep hills & Big contact forces changing gears \\
  Lighter & Expensive \\
  More efficient & More noisy \\ 
  Low and centered mass center & More moving parts - more maintenance \\
  Higher torques\\
  Better suited for poor pavement \\ 
  \hline
\end{tabularx}
\end{center}
\caption{Advantages and disadvantages on the use of Mid-drive motors.}
\label{tabMid}
\end{table}
\FloatBarrier

答案1

\documentclass{article}
\usepackage{tabularx}
\usepackage{booktabs}
\begin{document}
\begin{table}%[h]% This is for fine tuning at the very end
%   \begin{center}% just useless clutter
        \begin{tabularx}{\textwidth}{ X  X }\toprule
            \multicolumn{2}{c}{\textbf{\large Mid-drive motors\strut}} \\ 
            \midrule
            \textbf{Advantages} & \textbf{Disadvantages} \\
            \midrule
            Use the own gears of the bicycle & Wear a tear \\
            Consistent in steep hills & Big contact forces changing gears \\
            Lighter & Expensive \\
            More efficient & More noisy \\ 
            Low and centered mass center & More moving parts - more maintenance \\
            Higher torques\\
            Better suited for poor pavement \\ 
            \bottomrule
        \end{tabularx}
%   \end{center}
    \caption{Advantages and disadvantages on the use of Mid-drive motors.}
    \label{tabMid}
\end{table}
\end{document}

答案2

表格标题和表格材料(您想要垂直居中的材料)的第一行之间似乎有相当大的重叠。我会删除第一行,还会缩短标题以使其更简洁一些。

我将进一步使用包的线条绘制宏,booktabs而不是\hline,并且我将放弃使用粗体显示(现已简化)标题行中的条目。哦,由于环境的宽度\tabularx设置为\textwidth,因此没有必要将其封装在center环境中。

在此处输入图片描述

\documentclass{article}
\usepackage{tabularx,booktabs,ragged2e,caption}
\newcolumntype{L}{>{\RaggedRight\arraybackslash}X} 
\begin{document}

\begin{table}
\setlength\tabcolsep{2pt}
\caption{Advantages and disadvantages of mid-drive motors.}
\label{tabMid-mod}
\begin{tabularx}{\textwidth}{ @{}LL@{} }
\toprule
\addlinespace
  Advantages & Disadvantages \\
\midrule
  Use the own gears of the bicycle & Wear a tear \\
  Consistent in steep hills & Big contact forces changing gears \\
  Lighter & Expensive \\
  More efficient & More noisy \\ 
  Low and centered mass center & More moving parts: more maintenance \\
  Higher torques\\
  Better suited for poor pavement \\ 
\bottomrule
\end{tabularx}
\end{table}

\end{document}

答案3

这里最简单的方法是使用不可见的垂直规则。通过将其宽度设为零来实现不可见性。以单位形式指定高度和深度ex可让您访问当前字体参数。因此,我建议您将标题写为

\multicolumn{2}{c}{\textbf{\large 
  \vrule width 0pt height 3ex depth 1.5ex 
  Mid-drive motors}} \\

或者(感谢 Mico)使用 LaTeX\rule命令

\multicolumn{2}{c}{\textbf{\large 
  \rule[-1.5ex]{0pt}{4.5ex}
  Mid-drive motors}} \\

这给出

示例输出

\documentclass{article}

\usepackage{tabularx}

\begin{document}

\begin{table}
  \centering
  \begin{tabularx}{\textwidth}{ X X }\hline
    \multicolumn{2}{c}{\textbf{\large
    \vrule width 0pt height 3ex depth 1.5ex
    Mid-drive motors}} \\
    \hline
    \textbf{Advantages} & \textbf{Disadvantages} \\
    \hline
    Use the own gears of the bicycle & Wear a tear \\
    Consistent in steep hills & Big contact forces changing gears \\
    Lighter & Expensive \\
    More efficient & More noisy \\
    Low and centered mass center & More moving parts - more maintenance \\
    Higher torques\\
    Better suited for poor pavement \\
    \hline
  \end{tabularx}
  \caption{Advantages and disadvantages on the use of Mid-drive
  motors.}
  \label{tabMid}
\end{table}

\end{document}

单位ex是字体中字符小写x的标称高度。

顺便说一句,您应该认真考虑使用该booktabs包及其命令\toprule以及水平线。\midrule\bottomrule

相关内容