# Center alignment with multirow package

I have a multirow environment, but it does not center aligned in center environment. What might be wrong?

\documentclass[12pt]{article}

\usepackage{booktabs}
\usepackage{multirow}

\begin{document}

\begin{center}
\begin{table}[ht]
\caption{Virtual Machine Byte Code}\label{tab:vm}
\begin{tabular}{lll}
\toprule
{\bf Group} & {\bf Name} & {\bf Parameters} \\
\midrule\midrule[.1em]

\multirow{4}{2.5cm}{Stack}
& {\tt push}
& {\tt store} \\
\cmidrule(lr){2-3}
& {\tt pop}
& {\tt success} \\
\cmidrule(lr){2-3}
& {\tt success} \\
\cmidrule(lr){2-3}
& {\tt save}
& {\tt success} \\
\midrule[.1em]

\multirow{4}{2.5cm}{Stack}
& {\tt push}
& {\tt store} \\
\cmidrule(lr){2-3}
& {\tt pop}
& {\tt success} \\
\cmidrule(lr){2-3}
& {\tt success} \\
\cmidrule(lr){2-3}
& {\tt save}
& {\tt success} \\

\bottomrule
\end{tabular}
\end{table}
\end{center}
\end{document}

• Change \multirow{4}{2.5cm}{Stack} to \multirow{5}{2.5cm}{Stack}. (The three \cmidrule instructions add extra (vertical) whitespace, amounting to about 1 extra "real" row.) By the way, using \midrule\midrule[.1em] seems overkill. A single \midrule should do just fine. – Mico Jun 22 '16 at 21:15
• Never put table into \begin{center} ... \end{center}. Instead this rather write \begin{table[htb]\centering ... \end{table} – Zarko Jun 22 '16 at 21:15
• The simplest solution is, of course, not using \multirow and letting “Stack” stay where it belong, that is, at the top of the otherwise empty space. Besides, you should know that \bf and \tt have been deprecated more than twenty years ago. – egreg Jun 22 '16 at 22:09

Some suggestions:

• Change \multirow{4}{2.5cm}{Stack} to \multirow{5}{2.5cm}{Stack}

• Replace all \cmidrule directives with \addlinespace

• Use a single \midrule after the header row

• Use a common line width (say, 0.1em) for all \toprule, \midrule, and \bottomrule statements.

• Provide more structure in the setup of the tabular environment, so that you don't have to type all those \tt directives in the body of the table.

• Don't encase the table environment in a center environment. Instead, use a single \centering statement after \begin{table}.

• Optional: Don't use bold for the words in the header row: They already stand out sufficiently by virtue of their placement at the top of the table. :-)

\documentclass[12pt]{article}
\usepackage{booktabs,multirow,array,caption}

\begin{document}
\begin{table}[ht]
\centering
\caption{Virtual Machine Byte Code}\label{tab:vm}
\begin{tabular}{@{} p{2.5cm} *{2}{>{\ttfamily}l} @{}}
\toprule[.1em]
Group & \normalfont Name & \normalfont Parameters \\
\midrule[.1em]
\multirow{5}{*}{Stack} & push & store \\
& pop & success \\
& load& success \\
& save& success \\
\midrule[.1em]
\multirow{5}{*}{Stack}
& push & store \\
& pop  & success \\
& load & success \\
& save & success \\
\bottomrule[.1em]
\end{tabular}
\end{table}
\end{document}

• How about if you added another line, say under the first load-line. Using \multirow{6}{*}{Stack} looks definitely wrong, same width \multirow{5}{*}{Stack}. I think you would need to use the fixup-parameter here. – Runar Jun 22 '16 at 22:23
• @runartrollet - Honestly, my preferred approach would be to get rid of the extra spacing between the short rows. That way -- purely as a (happy) side-effect --\multirow could be used without further ado. Even better (as egreg has hinted as well, see above), don't use \multirow to begin with. :-) – Mico Jun 22 '16 at 22:57

For vertical positioning obey Mico comment, but you use in table commands from TeX not LaTeX, better and simpler code is:

\documentclass[12pt]{article}

\usepackage{booktabs,makecell,multirow}

\begin{document}

\begin{table}[ht]
\centering
\caption{Virtual Machine Byte Code}\label{tab:vm}
\begin{tabular}{p{25mm} >{\ttfamily}l >{\ttfamily}l}
\toprule
\midrule\midrule[.1em]

\multirow{5}*{Stack}
& push
& store \\
\cmidrule(lr){2-3}
& pop
& success \\
\cmidrule(lr){2-3}
& success \\
\cmidrule(lr){2-3}
& save
& success \\
\midrule[.1em]

\multirow{5}*{Stack}
& push
& store \\
\cmidrule(lr){2-3}
& pop
& success \\
\cmidrule(lr){2-3}
& success \\
\cmidrule(lr){2-3}
& save
& success \\
\bottomrule
\end{tabular}
\end{table}
\end{document}


As you can see, I add package makecell for formating column heads with macro \thead{...}. Result is:

You can move the \multirow identifiers into position using a precise \raisebox:

\documentclass{article}

\usepackage{booktabs,array}

\begin{document}

\begin{tabular}{ l >{\ttfamily}l >{\ttfamily}l }
\toprule
\bfseries Group & \rmfamily\bfseries Name & \rmfamily\bfseries Parameters \\
\midrule\midrule[.1em]
& push
& store \\
\cmidrule(lr){2-3}
\raisebox{\dimexpr-.5\normalbaselineskip-.5\cmidrulewidth-.5\aboverulesep}[0pt][0pt]{Stack}
& pop
& success \\
\cmidrule(lr){2-3}
& success \\
\cmidrule(lr){2-3}
& save
& success \\
\midrule[.1em]
& push
& store \\
\cmidrule(lr){2-3}
\raisebox{\dimexpr-.5\normalbaselineskip-.5\cmidrulewidth-.5\aboverulesep}[0pt][0pt]{Stack}
& pop
& success \\
\cmidrule(lr){2-3}
& success \\
\cmidrule(lr){2-3}
& save
& success \\
\bottomrule
\end{tabular}

\end{document}


I've also simplified your input using \bfseries and some array insertions via >{\ttfamily} before each of the last two columns.

From the multirow-documentation:

It’s just about impossible to deal correctly with descenders. The text will be set up centred, but it may then have a baseline that doesn’t match the baseline of the stuff beside it, in particular if the stuff beside it has descenders and text does not. This may result in a small misalignment. About all that can be done is to do a final touchup on text, using the fixup optional argument. (Hint: If you use a measure like .1ex, there’s a reasonable chance that the fixup will still be correct if you change the point size.)

So we need to use the fixup-parameter.

Output

Code

\documentclass[12pt]{article}

\usepackage{booktabs}
\usepackage{multirow}

\begin{document}

\begin{center}
\begin{table}[ht]
\caption{Virtual Machine Byte Code}\label{tab:vm}
\begin{tabular}{lll}
\toprule
{\bf Group} & {\bf Name} & {\bf Parameters} \\
\midrule\midrule[.1em]

\multirow{4}{2.5cm}[-1.5ex]{ Stack}
& {\tt push}
& {\tt store} \\
\cmidrule(lr){2-3}
& {\tt pop}
& {\tt success} \\
\cmidrule(lr){2-3}
& {\tt success} \\
\cmidrule(lr){2-3}
& {\tt save}
& {\tt success} \\
\midrule[.1em]

\multirow{4}{2.5cm}[-1.5ex]{Stack}
& {\tt push}
& {\tt store} \\
\cmidrule(lr){2-3}
& {\tt pop}
& {\tt success} \\
\cmidrule(lr){2-3}
& {\tt success} \\
\cmidrule(lr){2-3}
& {\tt save}
& {\tt success} \\

\bottomrule
\end{tabular}
\end{table}
\end{center}
\end{document}


## Some Suggestions

The look of the table could be improved a bit. Don't use \begin{centering}, it adds some unnecessary vertical space. Also, we probably don't need all of the rules. Especially double rules. To seperate some rows, which might otherwise be difficult to distinguish, it could be better to simply add some space with \addlinespace from booktabs-package. Also, as others have pointed out, use array-package so you don't need to write the same thing so many times. For the header you can add a command which sets the header-format.

Also, is seems, that as I have made the changes with removing the rules and inserting the space, there is no longer any use of the fixup-parameter as it has centered nicely, so I just removed it.

Output

Code

\documentclass[12pt]{article}

\usepackage{booktabs}
\usepackage{multirow}
\usepackage{array}
\begin{document}
\begin{table}[ht]
\centering
\caption{Virtual Machine Byte Code}\label{tab:vm}
\begin{tabular}{>{\ttfamily}lll}
\toprule
\midrule
\multirow{4}{2.5cm}{Stack}
& push
& store \\
& pop
& success \\
& success \\
& save
& success \\
\multirow{4}{2.5cm}{Stack}
& push
& store \\
& pop
& success \\
& success \\
& save
& success \\
\bottomrule
\end{tabular}
\end{table}
\end{document}


Some improvements:

Load caption to have a decent spacing between caption and tabular (LaTeX doesn't swap the values of \abovecaptionskip and \belowcaptionskip when caption is above the float). Don't use a center environment with floats, as it adds unwanted vertical spacing. Use \centering instead, inside the table environment. Don't use \bf, \tt, &c., but \bfseries or \textbf, \ttfamily or \texttt. I added a small correction to \multirow for vertical centring of the contents.

\documentclass[12pt]{article}
\usepackage{caption} \usepackage{booktabs}
\usepackage{multirow}

\begin{document}

\begin{table}[ht]
\centering
\caption{Virtual Machine Byte Code}\label{tab:vm}
\begin{tabular}{lll}
\toprule
\textbf{Group} & \textbf{Name} & \textbf{Parameters} \\
\midrule\midrule[.1em]
\multirow{4}{2.5cm}[-1.5ex]{\centering Stack}
& \texttt{push}
& \texttt{store} \\
\cmidrule(lr){2-3}
& \texttt{pop}
& \texttt{success} \\
\cmidrule(lr){2-3}
& \texttt{success} \\
\cmidrule(lr){2-3}
& \texttt{save}
& \texttt{success} \\
\midrule[.1em]
\multirow{4}{2.5cm}[-1.5ex]{\centering Stack}
& \texttt{push}
& \texttt{store} \\
\cmidrule(lr){2-3}
& \texttt{pop}
& \texttt{success} \\
\cmidrule(lr){2-3}