Graphics, Figures & Tables ⇒ Simultaneous alignment in cell of table
Simultaneous alignment in cell of table
I've been making quite a few tables these past few days. Been using the array-package to allow vertical alignment in the tabular-environment, typically;
\begin{tabular}{b{1.5cm}b{1.5cm}b{1.5cm}b{1.5cm}b{1.5cm}}
... bunch of stuff
\end{tabular}
But how on earth does one handle horizontal alignment simultaneously?
Alex
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
Simultaneous alignment in cell of table
Perhaps this will give you the basic idea.
E.g.:
Code: Select all
\begin{tabular}{|>{\raggedright}b{1.5cm}|>{\centering}b{1.5cm}|>{\flushright}b{1.5cm}|b{1.5cm}|}
\hline
left & center & right & here is a bunch of text that I want full justification for.\\
\hline
\end{tabular}
Simultaneous alignment in cell of table

So, I've tried some of that, and received an error.
Code: Select all
\begin{tabular}{>{\centering}b{2cm}>{\centering}b{2cm}>{\centering}b{\cellWidth}>{\centering}b{\cellWidth}>{\centering}b{\cellWidth}>{\centering}b{\cellWidth}>{\centering}b{\cellWidth}>{\centering}b{\cellWidth}>{\centering}b{\cellWidth}>{\centering}b{\cellWidth}}
Series & Number of observations & Mean & Median & Minimum & Maximum & Standard deviation & Skewness & Kurtosis \\ \hline
\end{tabular}
! Misplaced \noalign.
\hline ->\noalign
{\ifnum 0=`}\fi \hrule \@height \arrayrulewidth \futurelet...
l.271 ...deviation & Skewness & Kurtosis \\ \hline
Also, I get a lot of overfull \hbox
PS. \cellWidth is just a variable with a width (and yeah, I tested entering the width directly).
Anyone have a clue?
Simultaneous alignment in cell of table
add \arraybackslash immediately after every \centering (or \raggedright or \raggedleft) command:
Code: Select all
\documentclass{book}
\usepackage{array}
\newcommand\cellWidth{2cm}
\begin{document}
\begin{tabular}%
{*{2}{>{\centering\arraybackslash}b{2cm}}*{8}{>{\centering\arraybackslash}b{\cellWidth}}}
Series & Number of observations & Mean & Median & Minimum & Maximum & Standard deviation & Skewness & Kurtosis \\ \hline
\end{tabular}
\end{document}
- localghost
- Site Moderator
- Posts: 9202
- Joined: Fri Feb 02, 2007 12:06 pm
Simultaneous alignment in cell of table
The \arraybackslash command is only necessary for the last column to restore the \\ command for a new tabular line.Al.x wrote:Awesome. So, I've tried some of that, and received an error.[…]
Best regards and welcome to the board
Thorsten
Board Rules
Avoidable Mistakes
¹ System: TeX Live 2025 (vanilla), TeXworks 0.6.10
Simultaneous alignment in cell of table
localghost wrote:The \arraybackslash command is only necessary for the last column to restore the \\ command for a new tabular line.Al.x wrote:Awesome. So, I've tried some of that, and received an error.[…]
Best regards and welcome to the board
Thorsten
Thank you both! That worked perfectly Do any of you know what's going on in the background? Why does the \\ need to be restored? What is it exactly that \arraybackslash does?gmedina wrote:Hi,
add \arraybackslash immediately after every \centering (or \raggedright or \raggedleft) command:
Code: Select all
\documentclass{book} \usepackage{array} \newcommand\cellWidth{2cm} \begin{document} \begin{tabular}% {*{2}{>{\centering\arraybackslash}b{2cm}}*{8}{>{\centering\arraybackslash}b{\cellWidth}}} Series & Number of observations & Mean & Median & Minimum & Maximum & Standard deviation & Skewness & Kurtosis \\ \hline \end{tabular} \end{document}
Regards,
Alex
- localghost
- Site Moderator
- Posts: 9202
- Joined: Fri Feb 02, 2007 12:06 pm
Simultaneous alignment in cell of table
Code: Select all
texdoc array
Board Rules
Avoidable Mistakes
¹ System: TeX Live 2025 (vanilla), TeXworks 0.6.10