# Vertical alignment in tabular varies depending on compiling environment

I'm having problems (again) with vertical alignements in tables, but apparently, the code is problematic when compiled on my computer, but not when compiled on overleaf. For instance:

Overleaf rendition:

TeXStudio rendition on my PC:

And here is the code:

\documentclass[a4paper, 10pt]{article}
\usepackage{bm}
\usepackage[dvipsnames,table]{xcolor}
\usepackage{cmbright}
\renewcommand{\sfdefault}{cmbr}
\everymath{\displaystyle}

\begin{document}

\begin{tabular}{|
>{\centering\arraybackslash}m{10ex}|
>{\centering\arraybackslash}m{4ex}|
>{\centering\arraybackslash}m{4ex}|
>{\centering\arraybackslash}m{4ex}|
>{\centering\arraybackslash}m{4ex}|
>{\centering\arraybackslash}m{4ex}|
@{}m{0pt}@{}}
\hline
\cellcolor{gray!25}{\textbf{Degrees}}
& \cellcolor{green!15}{$0^{\circ}$}
& \cellcolor{green!15}{$30^{\circ}$}
& \cellcolor{green!15}{$45^{\circ}$}
& \cellcolor{green!15}{$60^{\circ}$}
& \cellcolor{green!15}{$90^{\circ}$}&\\[4ex]
\hline
& \cellcolor{green!15}{$0$}
& \cellcolor{green!15}{ $\frac{\pi}{6}$}
& \cellcolor{green!15}{$\frac{\pi}{4}$}
& \cellcolor{green!15}{$\frac{\pi}{3}$}
& \cellcolor{green!15}{$\frac{\pi}{2}$}&\\[4ex]
\hline
\cellcolor{blue!15}{\textbf{sin}($\bm{\theta}$)}
& $0$
& $\frac{1}{2}$
& $\frac{\sqrt 2}{2}$
& $\frac{\sqrt 3}{2}$
& $1$&\\[4ex]
\hline
\cellcolor{blue!15}{\textbf{cos}($\bm{\theta}$)}
& $1$
& $\frac{\sqrt 3}{2}$
& $\frac{\sqrt 2}{2}$
& $\frac{1}{2}$
& $0$&\\[4ex]
\hline
\cellcolor{blue!15}{\textbf{tan}($\bm{\theta}$)}
& $0$
& $\frac{\sqrt 3}{3}$
& $1$
& $\sqrt 3$
&\cellcolor{black}{}\\[4ex]
\hline
\end{tabular}

\end{document}


I'm using :

• the latest TeXStudio release (TeXstudio 2.12.14 (git 2.12.14) Using Qt Version 5.8.0)

• on windows 7

• pdflatex as default compiler

• latex was implemented on my computer with MiKTeX.

Does anyone know why this is happening?

Thanks

• you are using a newer version of the array package with a fixed m column implementation. Apr 30 '19 at 20:26
• Note that currently Overleaf uses TeX Live 2016, while TeX Live 2019 was released yesterday. A staff member at Overleaf said they're planning to install TeX Live 2018 in the “near future”. If you must use it, you have to make do with what they give you. Apr 30 '19 at 21:12

Actually, you code only needs two modification to compile correctly. If you look at page 6 in the documentation for the package array, the author describes the following change:

Prior to version 2.4f the space added by the optional argument to \ was added inside an m-cell if the last column was of type m. As a result that cell was vertically centered with that space inside, resulting in a strange offset. Since 2.4f, this space is now added after centering the cell.

At the end of all your rows, you have set a spacing of 4ex (\\[4ex]). I assume this is to ensure equal height of all row. However, the simplest solution I found to secure equal height of the rows, is to put a zero width rule of require height into all rows (\rule{0pt}{4ex}). I my MWE, I have added +1\tabcolsep to the height to compensate for the vertical lines in the table (and added the package calc do the maths). This is of cause not absolute necessary. I redefined the last column in your MWE to:

@{}>{\rule{0pt}{4ex+1\tabcolsep}}m{0pt}@{}}


removed [4ex] five places, and loaded calc in the second line

usepackage{bm, calc}


Unfortunately, you have an error in you MWE, which you have to correct to have the last row correctly spaced. You had forgotten to add the last ampersand & in the last row of the table.

&\cellcolor{black}{}
&\\                 % Last & cell was missing


With these three modifications, I was able to compile your code both on my updated local system and on Overleaf, with similar result. A complete MWE:

\documentclass[a4paper, 10pt]{article}
\usepackage{bm, calc}                      % Added the package calc
\usepackage[dvipsnames,table]{xcolor}
\usepackage{cmbright}
\renewcommand{\sfdefault}{cmbr}
\everymath{\displaystyle}

\begin{document}

\begin{tabular}{|
>{\centering\arraybackslash}m{10ex}|
>{\centering\arraybackslash}m{4ex}|
>{\centering\arraybackslash}m{4ex}|
>{\centering\arraybackslash}m{4ex}|
>{\centering\arraybackslash}m{4ex}|
>{\centering\arraybackslash}m{4ex}|
@{}>{\rule{0pt}{4ex+1\tabcolsep}}m{0pt}@{}}  % Zero width rule
\hline
\cellcolor{gray!25}{\textbf{Degrees}}
& \cellcolor{green!15}{$0^{\circ}$}
& \cellcolor{green!15}{$30^{\circ}$}
& \cellcolor{green!15}{$45^{\circ}$}
& \cellcolor{green!15}{$60^{\circ}$}
& \cellcolor{green!15}{$90^{\circ}$}&\\
\hline
& \cellcolor{green!15}{$0$}
& \cellcolor{green!15}{$\frac{\pi}{6}$}
& \cellcolor{green!15}{$\frac{\pi}{4}$}
& \cellcolor{green!15}{$\frac{\pi}{3}$}
& \cellcolor{green!15}{$\frac{\pi}{2}$}&\\
\hline
\cellcolor{blue!15}{\textbf{sin}($\bm{\theta}$)}
& $0$
& $\frac{1}{2}$
& $\frac{\sqrt 2}{2}$
& $\frac{\sqrt 3}{2}$
& $1$&\\
\hline
\cellcolor{blue!15}{\textbf{cos}($\bm{\theta}$)}
& $1$
& $\frac{\sqrt 3}{2}$
& $\frac{\sqrt 2}{2}$
& $\frac{1}{2}$
& $0$&\\
\hline
\cellcolor{blue!15}{\textbf{tan}($\bm{\theta}$)}
& $0$
& $\frac{\sqrt 3}{3}$
& $1$
& $\sqrt 3$
&\cellcolor{black}{}
&\\                         % Last & cell was missing
\hline
\end{tabular}

\end{document}


Overleaf result:

Result from updated MikTEx 2.9:

\def\cals@bgcolor{black}
\alignC\cell{}
\ht\cals@current@row=33pt
\erow\makeatother
\end{calstable}

\end{document}


• Hey, thanks for the input. Though this code doesn't compile on my end.
– Mogu
May 2 '19 at 18:04
• @Chris I assume you are not interested in the updated code, but I manage to have you original code working correctly with only two small modifications. May 4 '19 at 21:07
• @ Sveinung no no, I am. Just very busy at the moment, I'll check it out asap. Thanks
– Mogu
May 5 '19 at 7:43
• @Chris Take your time :) May 5 '19 at 13:38
• @ Sveinung Alright, so thanks a lot for all the work you've invested. I think I'll end up using the latest version you've added (the one before the cals version). Alhought the previous answers have been useful too, I like using tabular instead of tikz in the case, so I'll move the tick to your post.
– Mogu
Jun 10 '19 at 10:59

see, if the following solution gives the same result on your PC and on Overleaf:

\documentclass[tikz]{standalone}
\usetikzlibrary{matrix}
\usepackage{cmbright}
\renewcommand{\sfdefault}{cmbr}
\usepackage{bm}
\usepackage{siunitx}
\usepackage{amsmath}

\begin{document}
\begin{tikzpicture}
\matrix [matrix of math nodes,
nodes={draw, minimum height=6.4ex, minimum width=2.5em,
anchor=center},
column sep=-\pgflinewidth,
row sep=-\pgflinewidth,
column 1/.style = {nodes={fill=blue!15, minimum width=5em}},
row 1/.style = {nodes={preaction={fill=green!15}}},
row 2/.style = {nodes={preaction={fill=green!15}}}
]
{
|[fill=gray!25]| \textbf{Degrees}
& \SI{ 0}{\degree}      & \SI{30}{\degree}
& \SI{45}{\degree}      & \SI{60}{\degree}
& \SI{90}{\degree}                  \\
& 0                     & \dfrac{\pi}{6}
& \dfrac{\pi}{4}        & \dfrac{\pi}{3}
& \dfrac{\pi}{2}                    \\
\textbf{sin}(\bm{\theta})
& 0                     & \dfrac{1}{2}
& \dfrac{\sqrt{2}}{2}   & \dfrac{\sqrt{3}}{2}
& 1                                 \\
\textbf{cos}(\bm{\theta})
& 1                     & \dfrac{\sqrt{3}}{2}
& \dfrac{\sqrt{2}}{2}   & \dfrac{1}{2}
& 0                                 \\
\textbf{tan}(\bm{\theta})
& 0                     & \dfrac{\sqrt{3}}{3}
& 1                     & \sqrt{3}
& |[fill=black]|                    \\
};
\end{tikzpicture}
\end{document}


• Thanks, works fine! I honestly hoped I could manage using the array/tabular environments for all tables, but well, that'll do ;)
– Mogu
May 1 '19 at 9:22
• @Chris, at least for now it is independent on texlive version :-) (i hope) May 1 '19 at 9:27