4

I have this table, in which the text is touching the horizontal lines above and below, I tried some of the solutions to stretch the cells I found in the web. I managed to stretch the cell but I can't keep it center aligned.

This would be a MWE:

    \documentclass[a4paper,11pt,twoside]{article}
    \usepackage{amssymb}
    \usepackage{amsfonts}
    \usepackage{array}
    \usepackage{mathtools}
    \usepackage{mathabx} 
\everymath{\displaystyle}
     \usepackage{tabularx}
    \begin{document}
    \begin{table}[H]
        \centering
        \begin{tabularx}{1.3\textwidth}{ c | X }
                \hline 
                    Objetivos de diseño & $\frac{W_{TO}}{S_w} $, $\frac{T_{TO}}{W_{TO}} $, $A$, $C_{Do}$, $\varphi$, $N_e$, $C_{Lmax_{TO}}$, $C_{Lmax_{L}}$, $C_{Lmax}$ \\\hline 
                    Especificaciones iniciales &  $\frac{W_{CR}}{W_{TO}}$, $\frac{W}{W_{TO}}$, $\frac{W_{L}}{W_{TO}}$, $q$, $\sigma$, $S_{TO}$, $S_e$, $n$ \\\hline
                    Factores adicionales & $\frac{T_{TO}}{T_2} $, $\gamma$, $\eta$, $c_T$, $\frac{T_{TO}}{T_{CR}} $\\  \hline
            \end{tabularx}
    \end{table}
        \end{document}
piptin
  • 389

3 Answers3

4

Modifying arraystretch doesn't produce vertically centred cells. I propose a solution based on the cellspace package: it defines minimal distances between the top of a cell and the bottom of the above cell or line, and betwen the bottom of a cell and the top of the below cell/line. One has to use the pre-qualifier S before the qualifier. By default it works with the usual qualifiers l,c,r, p{}, m{}, b{}, and we may add the X qualifier.

I also use the makecell package, in order to have horizontal rules of variable thickness.

\documentclass[a4paper,11pt,twoside]{article}
\usepackage[utf8]{inputenc}
\usepackage{amssymb}
\usepackage{amsfonts}
\usepackage{array}
\usepackage{mathtools}
\usepackage{mathabx}
\everymath{\displaystyle}
 \usepackage{tabularx}
\renewcommand{\tabularxcolumn}[1]{>{\centering\arraybackslash}m{#1}}

\usepackage{makecell}

\usepackage{cellspace}
\setlength\cellspacetoplimit{6pt}
\setlength\cellspacebottomlimit{6pt}
\addparagraphcolumntypes{X}

\begin{document}

\begin{table}[H]
    \centering
    \begin{tabularx}{1.3\textwidth}{ l!{\vrule width1pt}>{$}S{X}<{$}}
            \Xhline{1pt}
                Objetivos de diseño & \frac{W_{TO}}{S_w} , \frac{T_{TO}}{W_{TO}} , A, C_{Do}, φ, N_e, C_{Lmax_{TO}}, C_{Lmax_{L}}, C_{Lmax} \\
\hline
Especificaciones iniciales & \frac{W_{CR}}{W_{TO}}, \frac{W}{W_{TO}}, \frac{W_{L}}{W_{TO}}, q, σ, S_{TO}, S_e, n \\\hline
Factores adicionales & \frac{T_{TO}}{T_2} , γ, η, c_T, \frac{T_{TO}}{T_{CR}} \\
            \Xhline{1pt}
        \end{tabularx}
\end{table}

    \end{document} 

enter image description here

Bernard
  • 271,350
  • This does the job, however I have trouble making it work with work other packages I really need. Namely xcolor, colortbl and pgfplots. When I load these, it works with the usual qualifiers l,c,r but not with p{}, m{}, b{}, X – piptin Sep 06 '14 at 21:41
  • @piptin: do you mean with these packages it doesn't add any vertical spacing? I suppose you use macros from these packages in your tables? – Bernard Sep 06 '14 at 21:45
  • no, actually, just adding the packages to preamble is enough for the spacing to disappear, but only for the columns types p{}, m{}, b{}, X, for the others works – piptin Sep 06 '14 at 22:22
  • I hadn't thought of testing that. I was aware of problems with the matrix*environments (from mathtools) for which the package author wrote a workaround. I'll report him this problem. – Bernard Sep 06 '14 at 23:56
  • @piptin: A workaround could be to have an Sl qualifier for the first column, with sufficiently great value for the minima — I tested with 12pt which seems acceptable. Of course it's only a workaround, to be adapted depending on your real table. – Bernard Sep 07 '14 at 00:11
  • for this case I think it's better to use the qualifier in a c column for the second one, since the X column is not really needed here – piptin Sep 07 '14 at 14:55
  • If you don't need multiline cells, it' perfect: the simpler, the better;). – Bernard Sep 07 '14 at 14:57
3

I think you are looking for something like

\documentclass[a4paper,11pt,twoside]{article}
\usepackage{amssymb}
\usepackage{amsfonts}
\usepackage{array}
\usepackage{mathtools}
\usepackage{mathabx} 
 \usepackage{tabularx}
\begin{document}
\begin{table}
    \centering
\renewcommand\arraystretch{1.7}
    \begin{tabularx}{\textwidth}{ c | >{\centering\arraybackslash}X }
            \hline 
                Objetivos de diseño & $\frac{W_{TO}}{S_w} $, $\frac{T_{TO}}{W_{TO}} $, $A$, $C_{Do}$, $\varphi$, $N_e$, $C_{Lmax_{TO}}$, $C_{Lmax_{L}}$, $C_{Lmax}$ \\\hline 
                Especificaciones iniciales &  $\frac{W_{CR}}{W_{TO}}$, $\frac{W}{W_{TO}}$, $\frac{W_{L}}{W_{TO}}$, $q$, $\sigma$, $S_{TO}$, $S_e$, $n$ \\\hline
                Factores adicionales & $\frac{T_{TO}}{T_2} $, $\gamma$, $\eta$, $c_T$, $\frac{T_{TO}}{T_{CR}} $\\  \hline
        \end{tabularx}
\end{table}
    \end{document}
David Carlisle
  • 757,742
  • 1
    @piptin globally setting \everymath{\displaystyle} rarely makes good results, are you sure ypu want that? anyeway if ypu set it for this table then just increas \arraystretch more if needed, or alternatively set each entry in the second column as a single display using \[....\] rather than a sequence of inline $xx..$ ... – David Carlisle Sep 06 '14 at 17:48
  • I really want that, but I tried it again and now it works in the MWE. I just can't seem to get it to work in my document. I'll try to look for the problem. – piptin Sep 06 '14 at 17:54
  • 1
    @piptin there are centuries of typesetting tradition indicating inline math should be set differently to display math... (the example you have here is different: it is "really" a display, so setting it locally is reasonably if you choose to use $ rather than \[ – David Carlisle Sep 06 '14 at 17:57
  • I did't know you could put a math environment inside a table, good to know. I'll try to use inline math where it should be then :) – piptin Sep 06 '14 at 18:12
  • I'm going to remove this as the answer since it really doesn't centre vertically the cells, it only adds space above. I had a typo after every line in the table there was a \\[15pt] so it looked centred – piptin Sep 06 '14 at 21:33
1

You can add a strut using an invisible rule:

\newcommand{\mystrut}{\rule[-12pt]{0pt}{30pt}}  %% adjust -12pt and 30pt as you wish

and add it in >{\mystrut} c.

Code:

\documentclass[a4paper,11pt,twoside]{article}
\usepackage{amssymb}
\usepackage{amsfonts}
\usepackage{array}
\usepackage{mathtools}
\usepackage{mathabx}
\usepackage{tabularx}
\newcommand{\mystrut}{\rule[-12pt]{0pt}{30pt}}

\begin{document}
\begin{table}
    \centering
    \begin{tabularx}{1.3\textwidth}{>{\mystrut} c | >{\centering\arraybackslash}X }
            \hline
                Objetivos de diseño & $\frac{W_{TO}}{S_w} $, $\frac{T_{TO}}{W_{TO}} $, $A$, $C_{Do}$, $\varphi$, $N_e$, $C_{Lmax_{TO}}$, $C_{Lmax_{L}}$, $C_{Lmax}$ \\\hline
                Especificaciones iniciales &  $\frac{W_{CR}}{W_{TO}}$, $\frac{W}{W_{TO}}$, $\frac{W_{L}}{W_{TO}}$, $q$, $\sigma$, $S_{TO}$, $S_e$, $n$ \\\hline
                Factores adicionales & $\frac{T_{TO}}{T_2} $, $\gamma$, $\eta$, $c_T$, $\frac{T_{TO}}{T_{CR}} $\\  \hline
        \end{tabularx}
\end{table}
    \end{document}

enter image description here

  • this looks nice and easy and clean, but it really doesn't vertically align the cell, you have to play with the strut dimension to get it vertically aligned – piptin Sep 07 '14 at 15:05