If I insert a math mode environment inside a table cell, then the output will show no vertical space between the borders and the equation, here is an example:
Is there any way that will make the borders have more vertical space from the formula?
If I insert a math mode environment inside a table cell, then the output will show no vertical space between the borders and the equation, here is an example:
Is there any way that will make the borders have more vertical space from the formula?
A rather simple workaround can be constructed using plain TeX/LaTeX boxes handling; since LaTeX's cell vertical space takes no account for the command \displaystyle, one solution is to avoid it "a priori" by inserting the equation inside a parbox environment:
\parbox[⟨alignment⟩][⟨height⟩][⟨arrangement⟩]{⟨width⟩}{⟨contents⟩}
Firstly, the alignment and arrangement parameters are set centered (c); the interesting dimensional arguments are height and width: since the equation will have stored its specific height (above the baseline), depth (below the baseline) and width, these dimensions could be easily substituted inside parbox's optional/mandatory arguments using calc's commands:
total height: \totalheightof{⟨content⟩}+2\fboxsep+2\fboxrule (pt)
total width : \widthof{⟨content⟩} (pt)
noticing that this setting can be applied to both any text or math inside the box, a useful macro \mytabspace{⟨your equation⟩} could be created, defined by:
% implementing more dimension/expression handling control sequences
\usepackage{calc}
%
\newcommand\mytabspace[1]{%
\parbox[c][\totalheightof{#1}+2\fboxsep+2\fboxrule][c]{\widthof{#1}}{#1}%
}
Another equivalent solution would be storing the content of the sub-cell inside a temporary box \@tempboxa; therefore there would be no worries about repetitive implementation inside the document, because if the box dimensions are defined inside a group, once outside the command they reset to the new box contents:
\makeatletter
\newcommand\mytabspace[1]{%
\sbox\@tempboxa{#1}%
\parbox[c][\ht\@tempboxa+\dp\@tempboxa+2\fboxsep+2\fboxrule][c]{\wd\@tempboxa}{%
\usebox\@tempboxa%
}%
}
\makeatother
Seeing it in action with a simple MWE paids off all the work behind:
\documentclass{article}
%
\usepackage{calc}
%
\newcommand\mytabspace[1]{%
\parbox[c][\totalheightof{#1}+2\fboxsep+2\fboxrule][c]{\widthof{#1}}{#1}%
}
% comment out the lines below and comment the beforementioned command,
% you'll see that the output is the same.
%\makeatletter
%\newcommand\mytabspace[1]{%
% \sbox\@tempboxa{#1}%
% \parbox[c][\ht\@tempboxa+\dp\@tempboxa+2\fboxsep+2\fboxrule][c]{\wd\@tempboxa}{%
% \usebox\@tempboxa%
% }%
%}
%\makeatother
%
\begin{document}
%
\begin{table}[ht]
\centering
\begin{tabular}{|c|c|}
\hline
Function & Integral \\
\hline
$-$ & This is not my macro: a \\
\hline
% test if there are unwanted vertical space additions
$-$ & This is my macro: \mytabspace{a} \\
\hline
% now the integral becomes:
$\sin(x)$ & \mytabspace{$\displaystyle{\lim_{n\to+\infty}\sum_{k=1}^n\sin(c_k)\Delta x_k=\int_a^b\sin(x)\,\mathrm{d}x}$} \\
\hline
\end{tabular}
\caption{This is a spaced equation, finally at last!}
\end{table}
%
\end{document}
With the output shown, it can be observed that mytabspace applies no modifications to any vertical spacing, as a demonstration to its versatility:
Moving on with LyX, accessing the menu Document → Settings → LaTeX preamble any \mytabspace macro definition shown can be pasted; because the program itself adds automatically \makeatletter and \makeatother inside the white preamble (the second code should not be pasted with those two commands, they'll be redundant).
At this point, the desired math environment can be delimited by a simple ERT:
Giving the final, expected output:
In addition, I'd like to thank @DavidCarlisle for the useful tips (but, only for the second code =P); and more importantly:
I too encountered this issue when I was just getting started with LyX (as example, I didn't even know what did "control sequence" mean back then); but I've been able to face it just now.
float table, you can see thesettingsmenu via: R-click on table -> Other... -> Settings -> Borders. Here you can add or subtract vertical space below, above the row. The best typographical advice is to switch theformalborder setting, this will automatically set both the looking and the spacing of the entire table. – TheVal Nov 19 '13 at 14:10answer? – landroni Jan 14 '14 at 06:59;)– TheVal Jan 14 '14 at 18:10insert, if you click on it there will be a window showing all the fields you can insert like math, figures andfloating objects; selecting that allows you to choose fromfigure, table. Once selectedtable, you'll have a floating space containing a table. – TheVal Jan 19 '14 at 10:30let us continue this discussion in chat, I'll meet you there:). – TheVal Jan 19 '14 at 19:11\expandafter, the answer is coming out today! – TheVal Mar 09 '14 at 12:56