Graphics, Figures & Tablesmultirow alignment

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
ihowarth
Posts: 3
Joined: Tue Aug 27, 2013 2:25 pm

multirow alignment

Post by ihowarth »

I'm trying to vertically align some table columns on a "+/-" between numbers; one line in one column needs to span two rows, and I can't get the "+/-" in the right position vertically. Here's my best try:

Code: Select all

\usepackage{multirow}
\usepackage{dcolumn}

\begin{tabular}{l r@{\,$\pm$\,}l r}
\hline
Col1 & \multicolumn{2}{c}{Col2} &Col3\\
\hline
Line 1  & 25.3 & 5.3                                     & 26.6  \\
Line 2  & \multirow{2}{*}{13.50}& \multirow{2}{*}{0.52} & 13.22 \\
Line 3  & \multicolumn{2}{c}{}                           & 14.08 \\
Line 4  & 5.65 & 0.06                                    & 5.641 \\
\hline
\end{tabular}
Of course, this puts a "+/-" on line 2, not mid-way between lines 2 and 3 as required; but this alternative breaks:

Code: Select all

Line 2  & \multirow{2}{*}{13.50&0.52}                    & 13.22 \\
Any ideas? Thanks...

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

Stefan Kottwitz
Site Admin
Posts: 10334
Joined: Mon Mar 10, 2008 9:44 pm

multirow alignment

Post by Stefan Kottwitz »

Hi!

Your table setup is a bit unusual, so it's not really supported by standard features. You could even put \multirow into a \multicolumn argument.

For better alignment options I would use a column for the \pm as it gets difficult with using that @ feature as you noticed.

Code: Select all

\documentclass{article}
\usepackage{multirow}
\usepackage{dcolumn}
\begin{document}
\begin{tabular}{l r @{\,}c@{\,} l r}
\hline
Col1 & \multicolumn{2}{c}{Col2} &Col3\\
\hline
Line 1  & 25.3 & $\pm$ & 5.3     & 26.6  \\
Line 2  & \multirow{2}{*}{13.50} & \multirow{2}{*}{$\pm$}
        & \multirow{2}{*}{0.52} & 13.22 \\
Line 3  & \multicolumn{2}{c}{}   & & 14.08 \\
Line 4  & 5.65 & $\pm$ & 0.06    & 5.641 \\
\hline
\end{tabular}
\end{document}
The table design could be improved, let me know if you would like to improve it. The lines nearly touch the content at the top.

Stefan
LaTeX.org admin
ihowarth
Posts: 3
Joined: Tue Aug 27, 2013 2:25 pm

multirow alignment

Post by ihowarth »

Thanks Stefan, that's a good work-round
Post Reply