Graphics, Figures & TablesVertical alignment in table cells with revtex4

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
charlotte29
Posts: 1
Joined: Mon Dec 14, 2020 11:37 pm

Vertical alignment in table cells with revtex4

Post by charlotte29 »

Hi, I have problem with a table when using revtex4. I need the text to be vertically centered in the cells. If I don't use revtex4 (i.e. using class report), it works using \begin{tabular}{ | m{5em} | m{1cm}| m{1cm} | } but if I use revtex4 it doesn't work anymore. Any ideas ? I really need to keep revtex4. Thanks !

Here a dummy example :

\documentclass[aps,amsmath,showkeys,superscriptaddress]{revtex4}
%\documentclass{report}
\usepackage{booktabs}
\usepackage{array}
\begin{document}

\begin{tabular}{ | m{5em} | m{1cm}| m{1cm} | }
\hline
cell1 dummy text dummy text dummy text& cell2 & cell3 \\
\hline
cell1 dummy text dummy text dummy text & cell5 & cell6 \\
\hline
cell7 & cell8 & cell9 \\
\hline
\end{tabular}

\end{document}
Attachments
problem.png
problem.png (16.8 KiB) Viewed 22435 times
what I want.png
what I want.png (18 KiB) Viewed 22435 times

Recommended reading 2024:

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

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

kaiserkarl13
Posts: 707
Joined: Tue Mar 25, 2008 5:02 pm

Vertical alignment in table cells with revtex4

Post by kaiserkarl13 »

The following line exists in revtex4.cls

Code: Select all

\@ifpackageloaded{array}{\switch@array}{\switch@tabular}
The result is, from what I gathered via a quick glance, something that effectively un-does what array is supposed to be doing regarding table layout (and this is one effect/side-effect).

I was able to fake it out putting \parbox[m]{5em}{...} around the text that should wrap lines, and then it worked:

Code: Select all

\documentclass[aps,amsmath,showkeys,superscriptaddress]{revtex4}
%\documentclass{report}
\usepackage{booktabs}
\usepackage{array}
\begin{document}

\begin{tabular}{ | m{5em} | m{1cm}| m{1cm} | }
\hline
\parbox[m]{5em}{cell1 dummy text dummy text dummy text} & cell2 & cell3 \\
\hline
\parbox[m]{1cm}{cell1 dummy text dummy text dummy text} & cell5 & cell6 \\
\hline
cell7 & cell8 & cell9 \\
\hline
\end{tabular}
Note that booktabs isn't doing any good if you're going to use \hline anyway.
JBClaypool
Posts: 10
Joined: Fri Jul 31, 2020 6:11 pm

Vertical alignment in table cells with revtex4

Post by JBClaypool »

Try \documentclass[aps,amsmath,showkeys,superscriptaddress]{revtex4-2}
Looks like there was an update, and I was able to compile it after doing that.
kaiserkarl13
Posts: 707
Joined: Tue Mar 25, 2008 5:02 pm

Vertical alignment in table cells with revtex4

Post by kaiserkarl13 »

JBClaypool wrote:Try \documentclass[aps,amsmath,showkeys,superscriptaddress]{revtex4-2}
Looks like there was an update, and I was able to compile it after doing that.
revtex4-2 does exactly the same thing. My fix above works with 4, 4-1, and 4-2 (and in fact I tested it with 4-2).
JBClaypool
Posts: 10
Joined: Fri Jul 31, 2020 6:11 pm

Vertical alignment in table cells with revtex4

Post by JBClaypool »

kaiserkarl13 had it right. While I wasn't able to initially able to compile his solution with revtex4, I was successful when using revtex4-2

you might not need the \vspace commands I used, but it made it look a little cleaner with my editor.
\documentclass[aps,amsmath,showkeys,superscriptaddress,a4paper]{revtex4-2}
%\documentclass{report}
\usepackage{array,booktabs}

\begin{document}

	\begin{tabular}{ | m{5em} | m{1cm}| m{1cm} | }
		\hline
		\parbox[m]{1cm}{cell1 dummy text dummy text dummy text \vspace*{1pt}}& {cell2} & cell3 \\
		\hline
		\parbox[m]{1cm}{cell1 dummy text dummy text dummy text \vspace*{1pt}} & cell5 & cell6 \\
		\hline
		cell7 & cell8 & cell9 \\
		\hline
	\end{tabular}
	
\end{document}
Attachments
Capture.JPG
Capture.JPG (23.83 KiB) Viewed 22326 times
Post Reply