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}
3
  • The cells that are touching the horizontal rules are not centred (since they're in an X-column). Do you want them centred?
    – Werner
    Commented Sep 6, 2014 at 17:18
  • @Werner I want them vertically centered, I know the X column doen't vertically center cells but I didn't want add more code since I don't know how to properly do this
    – piptin
    Commented Sep 6, 2014 at 17:29
  • 1
    Use something like \renewcommand{\arraystretch}{<num>} (as suggested in Column and row padding in tables) and update the X-column to use an m-type column instead of the default p-type column (as suggested in Vertical alignment in tabularx X-column type). That is, \renewcommand{\tabularxcolumn}[1]{m{#1}}.
    – Werner
    Commented Sep 6, 2014 at 17:33

3 Answers 3

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

7
  • 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
    Commented Sep 6, 2014 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
    Commented Sep 6, 2014 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
    Commented Sep 6, 2014 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
    Commented Sep 6, 2014 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
    Commented Sep 7, 2014 at 0:11
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}
5
  • 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..$ ... Commented Sep 6, 2014 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
    Commented Sep 6, 2014 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 \[ Commented Sep 6, 2014 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
    Commented Sep 6, 2014 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
    Commented Sep 6, 2014 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

1
  • 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
    Commented Sep 7, 2014 at 15:05

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .