3

I have the following table but I want to vertically center the first line of the table (Mid-drive motors). I would I do that?

\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
    Welcome to TeX - LaTeX! This code snippet is quite good, but you would help those answering the question and future visitors if you edited the question to complete it to a minimal working example (MWE) by adding the documentclass and relevant packages – Andrew Swann Aug 6 '16 at 9:59
2
\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

There seems to be considerable overlap between the table's caption and the first row of the tabular material (the material that you want to center vertically). I'd get rid of the first row, and I'd also shorten the caption to make it a bit snappier.

I would further use the line-drawing macros of the booktabs package instead of \hline, and I would forego the use of bold-facing the entries in the (now simplified) header row. Oh, and since the width of the \tabularx environment is set to \textwidth, there's no point in encasing it in a center environment.

enter image description here

\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}
2

The easiest thing here is to use an invisible vertical rule. Invisibility is obtained by making it of zero width. Specifying height and depth in terms of the units ex gives you access to the current font parameters. So I suggest you write the heading as

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

or (thanks to Mico) using the LaTeX \rule command

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

This gives

Sample output

\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}

The unit ex is the nominal height of the character lower case x in the font.

Incidentally you should seriously consider using the booktabs package with its commands \toprule, \midrule and \bottomrule for the horizontal lines.

  • +1. Writing \rule[-1.5ex]{0pt}{4.5ex} may be a bit more LaTeX-idiomatic than \vrule width 0pt height 3ex depth 1.5ex. – Mico Aug 6 '16 at 11:18
  • @Mico Yes, thats the LaTeX way - now added to the answer - but I do find the \vrule syntax easier to remember. – Andrew Swann Aug 6 '16 at 13:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.