4

I am trying to align the text in my table in the middle instead of the top. As seen in the figure below, the words "Longitudinal Derivatives", "Lateral Derivatives", "Dimensional" and "Non-Dimensional" are all touching the top of the cell instead of being in the middle.

enter image description here

The code for my table is below:

\begin{table}[H]
    \centering
    \caption{\label{tab:derivative} Stability derivatives for chosen wing design}
    \vspace{5pt}
        \begin{tabular}{|ll|ll|l|ll|ll|}
            \cline{1-4} \cline{6-9}
            \multicolumn{4}{|l|}{Longitudinal Derivatives}                          &  & \multicolumn{4}{l|}{Lateral Derivatives}                               \\ \cline{1-4} \cline{6-9} 
            \multicolumn{2}{|l|}{Dimensional} & \multicolumn{2}{l|}{Nondimensional} &  & \multicolumn{2}{l|}{Dimensional} & \multicolumn{2}{l|}{Nondimensional} \\ \cline{1-4} \cline{6-9} 
            $X_u$         & -0.4859           & $C_{X_u}$            & -0.072023    &  & $Y_v$         & -1.4526          & $C_{Y_{\beta}}$     & -0.21531      \\
            $X_w$         & 3.7512            & $C_{X_{\alpha}}$     & 0.55602      &  & $Y_p$         & -0.47694         & $C_{Y_p}$           & -0.070706     \\
            $X_q$         & 0.0000                 & $C_{X_q}$            & 0.0000            &  & $Y_r$         & 0.98276          & $C_{Y_r}$           & 0.14569       \\
            $Z_u$         & -11.82            & $C_{Z_u}$            & -0.011068    &  & $L_v$         & -0.72589         & $C_{L_{\beta}}$     & -0.053806     \\
            $Z_w$         & -47.489           & $C_{Z_{\alpha}}$     & 7.0392       &  & $L_p$         & -8.6412          & $C_{L_p}$           & -0.64062      \\
            $Z_q$         & -11.547           & $C_{Z_q}$            & 22.005       &  & $L_r$         & 3.1536           & $C_{L_r}$           & 0.23379       \\
            $M_u$         & 0.0026819         & $C_{M_u}$            & 0.0025556    &  & $N_v$         & 0.76742          & $C_{N_{\beta}}$     & 0.056885      \\
            $M_w$         & -4.4338           & $C_{M_{\alpha}}$     & -4.2249      &  & $N_p$         & -1.4856          & $C_{N_p}$           & -0.11014      \\
            $M_q$         & -4.6375           & $C_{M_q}$            & -56.816      &  & $N_r$         & -0.45003         & $C_{N_r}$           & -0.033363     \\ \cline{1-4} \cline{6-9} 
        \end{tabular}
\end{table}
Chryron
  • 157
  • 5
  • That's not what I mean though. I want the text to be left aligned but not positioned near the top of the cell. As you can see, there is very clearly less space above the word "Dimensional" then there is below it. I want the words to be vertically in the middle. – Chryron Apr 22 '20 at 21:27
  • Sorry, I misunderstood. I've deleted my earlier comment. – Mico Apr 22 '20 at 21:31
  • If you had words containing gjpy they would probably be touching the bottom too. Try playing with \arraystretch (macro, defaults to 1). Either that or \raisebox{\dimexpr 0.5\dp\strutbox-0.5\ht\strutbox}. – John Kormylo Apr 22 '20 at 21:36

5 Answers5

5

There are ways to achieve your stated objective directly, by inserting suitably-sized typographic struts; see, for instance, this answer. (Shameless self-citation alert!)

However, I think you're better off taking a different approach: Give the table a more open 'look' by getting rid of all vertical lines and replacing \hline and \cline with the rule-drawing macros of the booktabs package. I think it would also be a good idea to (a) align the numbers in the four data columns on their decimal markers and (b) introduce a bit of extra (vertical) whitespace after rows 3 and 6.

enter image description here

\documentclass{article}
\usepackage{booktabs} % for well-spaced horizontal rules
\usepackage{siunitx}  % for 'S' column type
\newcolumntype{L}{>{$}l<{$}} % left-aligned, automatic math mode
\newcolumntype{T}[1]{S[table-format=#1]}
\sisetup{group-digits=false}

\begin{document}
\begin{table}
\caption{Stability derivatives for chosen wing design}
\label{tab:derivative}

\setlength\extrarowheight{1pt} % optional
\setlength\tabcolsep{0pt} % let LaTeX figure out intercolumn whitespace amounts
\begin{tabular*}{\textwidth}{@{\extracolsep{\fill}} 
   LT{-2.7} LT{-2.7} LT{-1.5} LT{-1.6} }
%\toprule
\cmidrule[\heavyrulewidth]{1-4} \cmidrule[\heavyrulewidth]{5-8}
\multicolumn{4}{c}{Longitudinal Derivatives} & \multicolumn{4}{c}{Lateral Derivatives} \\ 
\cmidrule{1-4} \cmidrule{5-8} 
\multicolumn{2}{c}{Dimensional} & \multicolumn{2}{c}{Nondimensional} & 
\multicolumn{2}{c}{Dimensional} & \multicolumn{2}{c}{Nondimensional} \\ 
\cmidrule{1-2} \cmidrule{3-4} \cmidrule{5-6} \cmidrule{7-8} 
X_u & -0.4859   & C_{X_u}        & -0.072023 & Y_v & -1.4526  & C_{Y_{\beta}} & -0.21531  \\
X_w & 3.7512    & C_{X_{\alpha}} & 0.55602   & Y_p & -0.47694 & C_{Y_p}       & -0.070706 \\
X_q & 0.0000    & C_{X_q}        & 0.0000    & Y_r &  0.98276 & C_{Y_r}       & 0.14569   \\
\addlinespace
Z_u & -11.82    & C_{Z_u}        & -0.011068 & L_v & -0.72589 & C_{L_{\beta}} & -0.053806 \\
Z_w & -47.489   & C_{Z_{\alpha}} & 7.0392    & L_p & -8.6412  & C_{L_p}       & -0.64062  \\
Z_q & -11.547   & C_{Z_q}        & 22.005    & L_r &  3.1536  & C_{L_r}       & 0.23379   \\
\addlinespace
M_u & 0.0026819 & C_{M_u}        & 0.0025556 & N_v &  0.76742 & C_{N_{\beta}} & 0.056885  \\
M_w & -4.4338   & C_{M_{\alpha}} & -4.2249   & N_p & -1.4856  & C_{N_p}       & -0.11014  \\
M_q & -4.6375   & C_{M_q}        & -56.816   & N_r & -0.45003 & C_{N_r}       & -0.033363 \\
%\bottomrule
\cmidrule[\heavyrulewidth]{1-4} \cmidrule[\heavyrulewidth]{5-8}
\end{tabular*}
\end{table}
\end{document}
Mico
  • 506,678
  • I do like how this one looks so will probably use this table instead. But it is strange that it isn't easy to align the text in the middle without using struts normally. – Chryron Apr 22 '20 at 23:02
  • Why are the numbers on the longitudinal derivatives column not aligned but the ones on the lateral derivatives column are? How do you align the numbers on the left column? @Mico – Chryron Apr 28 '20 at 20:32
  • @NazmusSaadat - Please clarify what you mean by "why are the numbers [in] the longitudinal derivatives column not [being] aligned"? For sure, the numbers in all four data columns are aligned on their respective decimal markers. Please look closely. That's what I was referring to when I wrote "I think it would also be a good idea to (a) align the numbers in the four data columns on their decimal markers" in my answer. – Mico Apr 28 '20 at 20:59
  • Ah I was hoping to align the numbers on their leftmost digit instead. Which line in your code specifies alignment on the decimal point exactly and how do you change it to be aligned on the leftmost digit? – Chryron Apr 28 '20 at 22:40
  • You asked, "Which line in your code specifies alignment on the decimal point"? It's the string LT{-2.7} LT{-2.7} LT{-1.5} LT{-1.6}. The L and T column types were defined earlier. The L type specifies left-alignment plus automatic math mode. The T type performs alignment on the decimal marker; T{-2.7} informs LaTeX to set aside enough space for a number with 2 digits before the decimal marker as well as a sign symbol (+ or -) and up to 7 decimal digits. If you don't want alignment on the decimal markers, I suggest you change the 4 instances of T{<something>} to L. – Mico Apr 29 '20 at 04:40
  • the L column type does not ignore the sign symbol when aligning the numbers on the left. Is there a column type that can align the numbers on the leftmost digit instead of the decimal point while ignoring the sign symbol? – Chryron Apr 29 '20 at 09:54
  • @NazmusSaadat - No. Otherwise, don't you think I would have mentioned it long ago? A general remark: You seem to keep finding faults with my answer, and you use what I perceive to be an unpleasant, demanding, and cross tone. Frankly, I've gotten tired of being pushed around needlessly. If you really dislike my answer so strongly, just go ahead and un-accept it. I have no qualms deleting it after you un-accept it. (I cannot delete an answer that's been marked as "accepted".) Thank you. – Mico Apr 29 '20 at 10:16
5

Yet another solution based on the cellspace package, which defines a minimal vertical padding in cells with specifier prefixed with the letter S, or another you may choose as a package option, when siunitx, like here, is loaded.

I add various small improvements to the layout, removing the first line and loading caption to customise easily the layout of the caption.

\documentclass[11pt]{article}
\usepackage{geometry}
\usepackage[column=O]{cellspace}
\setlength{\cellspacetoplimit}{4pt}
\setlength{\cellspacebottomlimit}{4pt}
\usepackage{caption}
\captionsetup{labelfont=sc, textfont=it, skip=6pt}
\usepackage{siunitx}

\begin{document}

\begin{table} [!htb]
\sisetup{table-format=-2.7, table-number-alignment=center}
    \centering
    \caption{\label{tab:derivative} Stability derivatives for chosen wing design}
        \begin{tabular}{|OlS|lS|l|lS[table-format=-1.5]|lS[table-format=-1.6]|}
            \multicolumn{4}{c}{Longitudinal Derivatives} &\multicolumn{1}{c}{} & \multicolumn{4}{c}{Lateral Derivatives} \\ \cline{1-4} \cline{6-9}
            \multicolumn{2}{|Oc|}{Dimensional} & \multicolumn{2}{Oc|}{Nondimensional} & & \multicolumn{2}{Oc|}{Dimensional} & \multicolumn{2}{Oc|}{Nondimensional} \\ \cline{1-4} \cline{6-9}
            $X_u$ & -0.4859 & $C_{X_u}$ & -0.072023 & & $Y_v$ & -1.4526 & $C_{Y_{\beta}}$ & -0.21531 \\
            $X_w$ & 3.7512 & $C_{X_{\alpha}}$ & 0.55602 & & $Y_p$ & -0.47694 & $C_{Y_p}$ & -0.070706 \\
            $X_q$ & 0.0000 & $C_{X_q}$ & 0.0000 & & $Y_r$ & 0.98276 & $C_{Y_r}$ & 0.14569 \\[1ex]
            $Z_u$ & -11.82 & $C_{Z_u}$ & -0.011068 & & $L_v$ & -0.72589 & $C_{L_{\beta}}$ & -0.053806 \\
            $Z_w$ & -47.489 & $C_{Z_{\alpha}}$ & 7.0392 & & $L_p$ & -8.6412 & $C_{L_p}$ & -0.64062 \\
            $Z_q$ & -11.547 & $C_{Z_q}$ & 22.005 & & $L_r$ & 3.1536 & $C_{L_r}$ & 0.23379 \\[1ex]
            $M_u$ & 0.0026819 & $C_{M_u}$ & 0.0025556 & & $N_v$ & 0.76742 & $C_{N_{\beta}}$ & 0.056885 \\
            $M_w$ & -4.4338 & $C_{M_{\alpha}}$ & -4.2249 & & $N_p$ & -1.4856 & $C_{N_p}$ & -0.11014 \\
            $M_q$ & -4.6375 & $C_{M_q}$ & -56.816 & & $N_r$ & -0.45003 & $C_{N_r}$ & -0.033363 \\ \cline{1-4} \cline{6-9}
        \end{tabular}
\end{table}

\end{document} 

enter image description here

Bernard
  • 271,350
4

You can use \renewcommand*{\arraystretch}{1.1} into your table.

\documentclass[12pt]{article}
\usepackage[utf8]{inputenc}
\begin{document}
\begin{table}[h]
\renewcommand*{\arraystretch}{1.1} %%% <------------------
    \centering
    \caption{\label{tab:derivative} Stability derivatives for chosen wing design}
    \vspace{5pt}
        \begin{tabular}{|ll|ll|l|ll|ll|}
            \cline{1-4} \cline{6-9}
            \multicolumn{4}{|l|}{Longitudinal Derivatives}                          &  & \multicolumn{4}{l|}{Lateral Derivatives}                               \\ \cline{1-4} \cline{6-9} 
            \multicolumn{2}{|l|}{Dimensional} & \multicolumn{2}{l|}{Nondimensional} &  & \multicolumn{2}{l|}{Dimensional} & \multicolumn{2}{l|}{Nondimensional} \\ \cline{1-4} \cline{6-9} 
            $X_u$         & -0.4859           & $C_{X_u}$            & -0.072023    &  & $Y_v$         & -1.4526          & $C_{Y_{\beta}}$     & -0.21531      \\
            $X_w$         & 3.7512            & $C_{X_{\alpha}}$     & 0.55602      &  & $Y_p$         & -0.47694         & $C_{Y_p}$           & -0.070706     \\
            $X_q$         & 0.0000                 & $C_{X_q}$            & 0.0000            &  & $Y_r$         & 0.98276          & $C_{Y_r}$           & 0.14569       \\
            $Z_u$         & -11.82            & $C_{Z_u}$            & -0.011068    &  & $L_v$         & -0.72589         & $C_{L_{\beta}}$     & -0.053806     \\
            $Z_w$         & -47.489           & $C_{Z_{\alpha}}$     & 7.0392       &  & $L_p$         & -8.6412          & $C_{L_p}$           & -0.64062      \\
            $Z_q$         & -11.547           & $C_{Z_q}$            & 22.005       &  & $L_r$         & 3.1536           & $C_{L_r}$           & 0.23379       \\
            $M_u$         & 0.0026819         & $C_{M_u}$            & 0.0025556    &  & $N_v$         & 0.76742          & $C_{N_{\beta}}$     & 0.056885      \\
            $M_w$         & -4.4338           & $C_{M_{\alpha}}$     & -4.2249      &  & $N_p$         & -1.4856          & $C_{N_p}$           & -0.11014      \\
            $M_q$         & -4.6375           & $C_{M_q}$            & -56.816      &  & $N_r$         & -0.45003         & $C_{N_r}$           & -0.033363     \\ \cline{1-4} \cline{6-9} 
        \end{tabular}
\end{table}

\end{document}

enter image description here

Sebastiano
  • 54,118
  • 1
    I feel like this doesn't really fix the problem but hides it better and makes the table itself longer. But it is pretty useful to know so thanks! – Chryron Apr 22 '20 at 23:01
1

First, one should remark that, by default, the command \cline protrudes in the following row. In {NiceTabular} of nicematrix, this behaviour is corrected.

However, the space will probably seem still insufficient in the first two rows. In {NiceTabular}, the vertical padding can be changed row by row with the command \RowStyle and its key cell-space-top-limit.

\documentclass{article}
\usepackage{caption}
\usepackage{nicematrix}

\begin{document}

\begin{table} \centering \caption{\label{tab:derivative} Stability derivatives for chosen wing design} \begin{NiceTabular}{|ll|ll|l|ll|ll|} \cline{1-4} \cline{6-9} \RowStyle[cell-space-top-limit=2pt]{} \Block{1-4}{Longitudinal Derivatives} &&& & & \Block{1-4}{Lateral Derivatives} \ \cline{1-4} \cline{6-9} \RowStyle[cell-space-top-limit=2pt]{} \Block{1-2}{Dimensional} && \Block{1-2}{Nondimensional} && & \Block{1-2}{Dimensional} && \Block{1-2}{Nondimensional} \ \cline{1-4} \cline{6-9} $X_u$ & -0.4859 & $C_{X_u}$ & -0.072023 & & $Y_v$ & -1.4526 & $C_{Y_{\beta}}$ & -0.21531 \ $X_w$ & 3.7512 & $C_{X_{\alpha}}$ & 0.55602 & & $Y_p$ & -0.47694 & $C_{Y_p}$ & -0.070706 \ $X_q$ & 0.0000 & $C_{X_q}$ & 0.0000 & & $Y_r$ & 0.98276 & $C_{Y_r}$ & 0.14569 \ $Z_u$ & -11.82 & $C_{Z_u}$ & -0.011068 & & $L_v$ & -0.72589 & $C_{L_{\beta}}$ & -0.053806 \ $Z_w$ & -47.489 & $C_{Z_{\alpha}}$ & 7.0392 & & $L_p$ & -8.6412 & $C_{L_p}$ & -0.64062 \ $Z_q$ & -11.547 & $C_{Z_q}$ & 22.005 & & $L_r$ & 3.1536 & $C_{L_r}$ & 0.23379 \ $M_u$ & 0.0026819 & $C_{M_u}$ & 0.0025556 & & $N_v$ & 0.76742 & $C_{N_{\beta}}$ & 0.056885 \ $M_w$ & -4.4338 & $C_{M_{\alpha}}$ & -4.2249 & & $N_p$ & -1.4856 & $C_{N_p}$ & -0.11014 \ $M_q$ & -4.6375 & $C_{M_q}$ & -56.816 & & $N_r$ & -0.45003 & $C_{N_r}$ & -0.033363 \ \cline{1-4} \cline{6-9} \end{NiceTabular} \end{table}

\end{document}

Output of the above code

F. Pantigny
  • 40,250
1

One more possibilities: by use of the tabularray and siunitx packages :-):

\documentclass{article}
\usepackage{amsmath}
\usepackage[skip=1ex]{caption}
\usepackage{tabularray}
\UseTblrLibrary{siunitx}
\NewColumnType{C}{>{$}c<{$}}

\begin{document} \begin{table} \centering \caption{Stability derivatives for chosen wing design} \label{tab:derivative} \begin{tblr}{vlines, colspec={C S[table-format=-2.7] C S[table-format=-2.7] c C S[table-format=-2.7] C S[table-format=-2.7]} } \cline[1pt]{1-4} \cline[1pt]{6-9} \SetCell[c=4]{c} \text{Longitudinal Derivatives} &&&& & \SetCell[c=4]{c} \text{Lateral Derivatives} &&& \ \cline{1-4} \cline{6-9} \SetCell[c=2]{c} \text{Dimensional} && \SetCell[c=2]{c} \text{Nondimensional} && & \SetCell[c=2]{c} \text{Dimensional} && \SetCell[c=2]{c} \text{Nondimensional} & \ \cline[0.6pt]{1-4} \cline[0.6pt]{6-9} X_u & - 0.4859 & C_{X_u} & -0.072023 && Y_v & -1.4526 & C_{Y_{\beta}} & -0.21531 \ X_w & 3.7512 & C_{X_{\alpha}} & 0.55602 && Y_p & -0.47694 & C_{Y_p} & -0.070706 \ X_q & 0.0000 & C_{X_q} & 0.0000 && Y_r & 0.98276 & C_{Y_r} & 0.14569 \ Z_u & -11.82 & C_{Z_u} & -0.011068 && L_v & -0.72589 & C_{L_{\beta}} & -0.053806 \ Z_w & -47.489 & C_{Z_{\alpha}} & 7.0392 && L_p & -8.6412 & C_{L_p} & -0.64062 \ Z_q & -11.547 & C_{Z_q} & 22.005 && L_r & 3.1536 & C_{L_r} & 0.23379 \ M_u & 0.0026819 & C_{M_u} & 0.0025556 && N_v & 0.76742 & C_{N_{\beta}} & 0.056885 \ M_w & - 4.4338 & C_{M_{\alpha}} & -4.2249 && N_p & -1.4856 & C_{N_p} & -0.11014 \ M_q & - 4.6375 & C_{M_q} & -56.816 && N_r & -0.45003 & C_{N_r} & -0.033363 \ \cline[1pt]{1-4} \cline[1pt]{6-9} \end{tblr} \end{table} \end{document}

enter image description here

Zarko
  • 296,517