I'd like to format a table in which first column has a single line of text, centered vertically across a variable number of rows. Currently, I am using a IfEqCase
and adding an entry in the first column only if some condition is met. This works as long as I have a fixed number of rows, and that number is odd (otherwise, the entry will not be vertically centered) :
\documentclass[11pt]{article}
\usepackage{multirow}
\usepackage{xstring}
\newcommand{\gridsize}[1]{\ensuremath{#1 \times #1}}
\newcommand{\addrowmpi}[4]{%
\IfEqCase{#1}{%
{1} {&} %
{2} {\gridsize{#2} &} %
{4} {&} %
}
#3 & #4 \%}
\begin{document}
\begin{table}[ht]
\caption{Multi-row table}
\begin{center}
\begin{tabular}{ccc}
\hline
\addrowmpi{1}{512}{462.7}{100} \\
\addrowmpi{2}{512}{231.4}{50}\\
\addrowmpi{4}{512}{115.7}{25}\\
\hline
\end{tabular}
\end{center}
\label{tab:multicol}
\end{table}
\end{document}
The result looks like :
But I'd like to have a variable number of rows, formatted ideally with something like addrowmpi
. The first column entry should be centered vertically across the rows.
Is there a way I can use the multirow
environment with a variable number of rows?
\addrowmpi
is doing for you. Why not just type the relevant bit on the relevant line? Why specify it for every row in this complex process? I guess I'm not seeing what is motivating this right now as it just seems like an elaborate way of entering\gridsize{512}
once in one cell of the table.addrowmpi
so that I can change what exactly I present in that row. But I left it here because I wanted to know if I could pass this command that formats the rows as an argument to the multirow command.addrowmpi
is useful because I can rearrange the order in which i present the row entries, do some simple math on the entries to compute the percentages (using the FP package), etc. So it is useful (although perhaps not so obvious is in this example).