2

I try with some recommendations to add vertical space for cells with equations, and I couldn't achieve it.

Here is my MWE:

\documentclass[12pt,a4paper]{article}
    \usepackage{array}
\usepackage{makecell}
\renewcommand\theadfont{\normalsize\bfseries}
\usepackage[math]{cellspace}
\setlength\cellspacetoplimit{4pt}
\setlength\cellspacebottomlimit{4pt}

\usepackage{color,colortbl,hhline}
\definecolor{Gray}{gray}{0.9}
\usepackage{caption}
\usepackage{amsmath}

\begin{document}    
\begin{table}[htpb]
    \centering
    \caption{Solución de la ecuación }
        \begin{tabular}{|p{1cm}|p{12cm}|}
        \hline
        \rowcolor{Gray} \thead{Caso} & \thead{Solución} \\
        \hline
        $\zeta = 1$ & $u(t) = [u(0) + (\dot u(0) + u(0) \omega_n )t]e^{-\omega_n t}$\\\hline
        $\zeta > 1$ & $u(t) = \dfrac{e^{-\omega_n\zeta}}{2\omega_n\sqrt{\zeta^2-1}}\left\lbrace\left[\omega_n(\zeta+\sqrt{\zeta^2-1})u(0)+\dot u(0)\right]e^{\omega_n\sqrt{\zeta^2-1}}-\big[\omega_n(\zeta - \sqrt{\zeta^2-1})u(0)+\dot u(0)\big]e^{-\omega_n\sqrt{\zeta^2-1}}\right\rbrace$ \\\hline
        $\zeta < 1$ & $u(t) = e^{-\omega_n\zeta t}\left[u(0)\cos{\omega_Dt} + \left(\dfrac{\dot u(0) + \omega_n\zeta u(0)}{\omega_D}\right)\right]$ \\\hline
        \end{tabular}
    \end{table}
\end{document}

Update

Maybe I can't anchieve the solution because of conflicts between some packages. This is my preamble, and the Typeset Engine is pdfLaTeX:

\documentclass[12pt,a4paper]{article}

%\usepackage{polyglossia}
%\setdefaultlanguage[babelshorthands]{spanish}
%\usepackage[Ligatures=TeX]{fontspec}
\usepackage[spanish,es-noshorthands]{babel}
\usepackage[T1]{fontenc}%http://tex.stackexchange.com/questions/44694/fontenc-vs-inputenc
\usepackage[utf8]{inputenc}
\usepackage{mathptmx}%http://tex.stackexchange.com/questions/669/how-do-i-make-my-document-use-the-times-font-both-for-the-text-and-the-math
%\fontspec{Times New Roman}
%\usepackage{fontspec}
%\setmainfont{Times New Roman}
%\usepackage[T1]{fontenc}
%\usepackage{ifthen}
%\usepackage{fontspec}
%\setmainfont{Arial}

\usepackage[table]{xcolor}

%\usepackage[htt]{hyphenat}
%
%\usepackage{pdflscape}

%\usepackage[title]{appendix}

\usepackage[style=apa]{biblatex}
\addbibresource{bibltarea6.bib}

%\usepackage{array,multirow}
\usepackage{makecell}
\renewcommand\theadfont{\normalsize\bfseries}
\renewcommand\theadgape{}
\usepackage[math]{cellspace}
\setlength\cellspacetoplimit{4pt}
\setlength\cellspacebottomlimit{4pt}

\usepackage{listings}
\lstset{
basicstyle = \ttfamily,
keywordstyle= \color{blue}\textbf,
commentstyle= \color{gray},
stringstyle= \color{green!70!black},
stringstyle= \color{red},
columns= fullflexible,
numbers= left,
numberstyle= \scriptsize\sffamily\color{gray},
xleftmargin= 0.07\textwidth,
xrightmargin= 0.05\textwidth,
showstringspaces = false,
}

%\usepackage{inconsolata}

%\newcommand{\Cpp}{C\texttt{++}}
%\renewcommand{\lstlistingname}{Código}
%\renewcommand{\lstlistlistingname}{Índice de códigos}

%\usepackage{tikz}
%\usepgflibrary{arrows.meta}
%\tikzset{%
%  newTip/.tip={Bar[sep=-1.45pt, width=10pt] Circle[sep=-1.25pt,width=2.5pt,length=2.5pt]}
%  }
%\usetikzlibrary{patterns}
%
%\usepackage{tikz}
%\usepgflibrary{arrows.meta,shapes.arrows}
%\tikzset{%
%  newTip/.tip={Bar[sep=-1.45pt, width=10pt] Circle[sep=-1.25pt,width=2.5pt,length=2.5pt]}
%  }
%\usetikzlibrary{patterns}
%\usetikzlibrary{calc}

%\usepackage{caption}
%\usepackage{subcaption}

\usepackage{amsmath}
\usepackage{mathtools}
%\setcounter{MaxMatrixCols}{25}

\usepackage{siunitx}
\sisetup{per-mode = symbol}

%\usepackage{pgfplots}

%\newcounter{myrow}

%\usepackage{longtable}
%\usepackage{threeparttable}

%\usepackage[inline]{enumitem}
%\usepackage{hyperref}

\usepackage{titlesec}
\titleformat*{\section}{\bfseries\normalsize}
\titleformat*{\subsection}{\bfseries\normalsize}
\titleformat*{\subsubsection}{\bfseries\normalsize}

\usepackage[ampersand]{easylist}

%\usepackage{layout}

\usepackage{color,colortbl,hhline}
\definecolor{Gray}{gray}{0.9}

%\usepackage[a4paper,left=3cm, top=3cm, right=2.5cm, bottom=2.5cm]{geometry}

\setlength{\hoffset}{.46cm}
\setlength{\oddsidemargin}{13.08pt}
\setlength{\evensidemargin}{0cm}
\setlength{\marginparwidth}{0cm}
\setlength{\topmargin}{-7mm}
\setlength{\marginparsep}{0cm}
\setlength{\headheight}{8mm}
\setlength{\headsep}{4.6mm}
\setlength{\textheight}{24cm}
\setlength{\footskip}{8mm}
\setlength{\textwidth}{15.5cm}

\usepackage{fancyhdr}
\pagestyle{fancy}
 \lhead{\footnotesize{Pontificia Universidad Católica del Perú}\\ \footnotesize{Escuela de Posgrado - Ingeniería Civil}}%Significa que est
 \chead{}%Vac
 \rhead{\footnotesize{Dinámica de Estructuras\\ Tarea 1}}
 \lfoot{\footnotesize{}}%Pie izquierdo
 \cfoot{\thepage}
 \rfoot{\footnotesize{Fernández Yopla, Isai}}

 \renewcommand{\headrulewidth}{0.4pt}%Falta investigar
 \renewcommand{\footrulewidth}{0.4pt}

\usepackage[pass]{geometry}%pass tells output driver which paper size use.
Isai
  • 4,153

2 Answers2

5

equation in the second row/column is far to long. you need to split it in two lines. for example with use the aligned environment from the package mathtools. for more vertical space you should used S column specifier from cellspace. for example for the second column: S{p{12cm}}:

edit:

  • in cases, when the siunitx package is used, the S specifier from the cellspace package had to be replaced by C, i.e. C{p(12cm)}
  • in mwe below i consider only for table relevant packages
  • off-topic: since you also use the geometry package, you can define page layout with it and remove all other low level page layout definitions in your preamble

\documentclass[12pt,a4paper]{article}
\usepackage[T1]{fontenc}%http://tex.stackexchange.com/questions/44694/fontenc-vs-inputenc
\usepackage[utf8]{inputenc}
\usepackage[spanish,es-noshorthands]{babel}
\usepackage{mathptmx}%http://tex.stackexchange.com/questions/669/how-do-i-make-my-document-use-the-times-font-both-for-the-text-and-the-math

\usepackage{makecell,hhline}        % <---
\renewcommand\theadfont{\normalsize\bfseries}
\renewcommand\theadgape{}
\usepackage{cellspace}              % <---
\setlength\cellspacetoplimit{4pt}
\setlength\cellspacebottomlimit{4pt}

\usepackage{mathtools}              % it load "amsmath" too
\usepackage{siunitx}                % <--- used it, the "S" from the "cellspace# package
                                    %  had to be replaced with "C"
\usepackage[table]{xcolor}          % <---
\definecolor{Gray}{gray}{0.9}
\usepackage{geometry}               % for simple determination of page layout.
                                    % see its documentation!

\begin{document}
    \begin{table}[htpb]
    \centering
\caption{Solución de la ecuación }
    \begin{tabular}{|p{1cm}|C{p{12cm}}|}
        \hline
        \rowcolor{Gray}
        \thead{Caso} & \thead{Solución}             \\
        \hline
        $\zeta = 1$  & $u(t) = \bigl[u(0) + \bigl(\dot{u}(0) + u(0) \omega_n\bigr) t\bigr] e^{-\omega_n t}$     \\ \hline
        $\zeta > 1$ & $\begin{multlined}
            u(t) = \dfrac{e^{-\omega_n\zeta}}{2\omega_n\sqrt{\zeta^2-1}}
            \biggl\{\Bigl[\omega_n\Bigl(\zeta+\sqrt{\zeta^2-1}\Bigr)u(0)+\dot{u}(0)\Bigr] e^{\omega_n\sqrt{\zeta^2-1}} -  \\
            \Bigl[\omega_n\Bigl(\zeta - \sqrt{\zeta^2-1}\Bigr)u(0)+\dot{u}(0)\Bigr] e^{-\omega_n\sqrt{\zeta^2-1}}
            \biggr\}
                        \end{multlined}$                \\  \hline
        $\zeta < 1$ & $u(t) = e^{-\omega_n\zeta t}
        \biggl[u(0)\cos{\omega_Dt} + 
            \biggl(\dfrac{\dot{u}(0) + \omega_n\zeta u(0)}{\omega_D}\biggr)
        \biggr]$                                        \\  \hline
        \end{tabular}
    \end{table}
\end{document}

enter image description here

Zarko
  • 296,517
  • I think that I have some packages in conflict, because I don't have the results, and S doesn't work: "./T1Dyn18.Isai.tex:299: Package array Error: Illegal pream-token (p{12cm}): `c' used." – Isai Sep 01 '18 at 07:10
  • I have been working with pdfLaTeX. – Isai Sep 01 '18 at 07:15
  • ups, at editing table code i overwrite last three lines of mwe code. sorry. now corrected. i consider all packages in mwe in your question and compile mwe with pdfLaTeX. apparently you tested table code in document with different preamble. solution, as it is now, works (tested again). – Zarko Sep 01 '18 at 07:24
  • I have updated the question with my preamble, I would like you to help me to fix this. – Isai Sep 01 '18 at 07:33
  • 2
    @Isai, as i suspect, your real preamble is different. problem cause use of the siunitx package. when you use it, than S from cellspace had to be replaced by C. i will edit my answer asap. – Zarko Sep 01 '18 at 07:35
  • Thanks for your intention, I think that the software has problems. I have Texpad. – Isai Sep 01 '18 at 15:46
  • It is done with updated packages. – Isai Sep 01 '18 at 16:04
3

As @Zarko has already pointed out in his answer, the main problem is that one of the main equations is far too long to fit in a single row. Use an aligned environment to introduce a suitably chosen line break.

Once you've line-broken the long equation, there's no need to use p column types; instead, just use the basic l column type for both columns.

In order to declutter the tabular material some more, I would remove the repetitive u(t) = parts from the cells and, instead, stick that information into the table's caption.

I would also like to suggest that you give the table a much more open "look", mainly by getting rid of all vertical and horizontal black lines -- they're simply not needed. I'd also load the booktabs package and use its \addlinespace macro to further increase whitespace between rows.

In addition, I would replace all \left and \right directives with explicit sizing instructions.

enter image description here

\documentclass[12pt,a4paper]{article}
\usepackage[spanish]{babel} % new
\usepackage{array}
\usepackage{booktabs} % for "\addlinespace" macro
\usepackage[table]{xcolor}
\definecolor{Gray}{gray}{0.9}
\usepackage[skip=0.333\baselineskip]{caption}
\usepackage{amsmath} % for 'aligned' environment

\begin{document}    
\begin{table}[htpb]
\setlength\extrarowheight{3pt}
\centering
\caption{Solución de la ecuación por $u(t)$}
\begin{tabular}{ll}
\rowcolor{Gray} \textbf{Caso} & \textbf{Solución } \\
\addlinespace
$\zeta = 1$ & 
$\displaystyle
  \bigl[u(0) + (\dot u(0) + u(0) \omega_n )t\bigr]
         e^{-\omega_n t}
$\\ \addlinespace
$\zeta > 1$ & 
$\begin{aligned}[t]
\frac{e^{-\omega_n\zeta}}{2\omega_n\sqrt{\zeta^2-1}}\Bigl\lbrace
  &\bigr[\omega_n(\zeta+\sqrt{\zeta^2-1})u(0)+\dot u(0)\bigr] 
    e^{\omega_n\sqrt{\zeta^2-1}}\\
-&\bigl[\omega_n(\zeta - \sqrt{\zeta^2-1})u(0)+\dot u(0)\bigr]
    e^{-\omega_n\sqrt{\zeta^2-1}}\,
\Bigr\rbrace
\end{aligned}$ \\ \addlinespace
$\zeta < 1$ & 
$\displaystyle 
e^{-\omega_n\zeta t}\bigl[u(0)\cos{\omega_Dt} 
+ \bigl(\dot u(0) + \omega_n\zeta u(0)\bigr)\big/\omega_D
\bigr]$ \\
\end{tabular}
\end{table}
\end{document}
Mico
  • 506,678
  • Thank you very much. But I have to work with siunitx, and this is the problem: . ! File ended while scanning use of \__siunitx_tmp:w – Isai Sep 01 '18 at 08:25
  • 1
    @Isai - Please see the revised code I just posted. It no longer uses the machinery of the cellspace and makespace packages and hence, by construction, doesn't interfere with anything the siunitx package does. – Mico Sep 01 '18 at 08:27
  • Thanks for your intention, I think that the software has problems because I have the same problem with siunitx, but when I don't use it, everything is right. I have Texpad software. – Isai Sep 01 '18 at 15:48
  • 1
    Done! I had to update the packages. – Isai Sep 01 '18 at 16:03