Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

One problem I've always had is trying to make text and/or math text vertically centered in either the tabular or array environments.

Take this for example:

\documentclass{article}
\usepackage{amsmath}
\newcommand{\firstpartial}[1]{\dfrac{\partial}{\partial {#1}}}
\begin{document}
\[
\begin{array}{|l|l|}
\hline
\firstpartial{x}\left[f(x,y)\right] = 2xy & \text{Differentiate with respect to }x\text{, treating }y \text{ as a constant.}\\[4ex]
\hline 
\end{array}
\]
\end{document}

enter image description here

I would like to vertically center both the math and the text in both columns. How can I do this?

share|improve this question
1  
Why do you have the \\[4ex]? –  azetina Jun 12 at 1:03
    
Not sure if that works with arrays or not, but without it, the length of the array was too small (it covers up some of the \partial symbol). –  Clarinetist Jun 12 at 1:04
add comment

3 Answers 3

up vote 6 down vote accepted

Take a look at the cellspace package which states the following in the abstract:

enter image description here

Here is a MWE:

\documentclass{article}
\usepackage{amsmath}
\usepackage[math]{cellspace}
\cellspacetoplimit5pt
\cellspacebottomlimit5pt
\newcommand{\firstpartial}[1]{\dfrac{\partial}{\partial {#1}}}
\begin{document}
\begin{tabular}{|Sl|l|} % Note the use of the prefix S to the column which needs be modified.
\hline
$\firstpartial{x}\left[f(x,y)\right] = 2xy$ & Differentiate with respect to $x$, treating $y$ as a constant.\\
\hline 
\end{tabular}

\end{document}

enter image description here

Another possible solution is to use a vertical rule as shown in the MWE below:

\documentclass{article}
\usepackage{amsmath}
\newcommand{\addmathvspace}{\vrule width 0pt height 4ex depth 2.5ex} % Adjust height and depth here.
\newcommand{\firstpartial}[1]{\dfrac{\partial}{\partial {#1}}}
\begin{document}
\begin{tabular}{|l|l|}
\hline
\addmathvspace$\firstpartial{x}\left[f(x,y)\right] = 2xy$ & Differentiate with respect to $x$, treating $y$ as a constant.\\
\hline 
\end{tabular}

\end{document}
share|improve this answer
add comment

You could define a "math strut" -- an invisible object with height and depth but no width (and thus invisible) -- and insert it where needed. I suggest using a "large integral with upper and lower limits" as the template for such a strut.

enter image description here

\documentclass{article}
\usepackage{amsmath}
\newcommand{\firstpartial}[1]{\dfrac{\partial}{\partial {#1}}}
%% define a "big" strut using \vphantom:
\newcommand\bstrut{\vphantom{\displaystyle\int\limits_0^1}}
\begin{document}
\[
\begin{array}{|l|l|}
\hline
\bstrut\firstpartial{x}\left[f(x,y)\right] = 2xy & 
   \text{Differentiate with respect to $x$, treating $y$ as a constant.}\\
\hline 
\end{array}
\]
\end{document}
share|improve this answer
add comment

At least in this case, \addstackgap from the stackengine package can add a symmetric gap above and below an object. If the gap to be added is asymmetric (more above than below, for example), the \addvbuffer macro of the verbatimbox package allows for that.

Here is the \addstackgap fix:

\documentclass{article}
\usepackage{amsmath}
\usepackage{stackengine}
\stackMath
\newcommand{\firstpartial}[1]{\dfrac{\partial}{\partial {#1}}}
\begin{document}
\[
\begin{array}{|l|l|}
\hline
\addstackgap[3pt]{\firstpartial{x}\left[f(x,y)\right] = 2xy} & \text{Differentiate with respect to }x\text{, treating }y \text{ as a constant.}\\
\hline 
\end{array}
\]
\end{document}

enter image description here

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.