Graphics, Figures & Tablesmultirow | Several Alignment Problems

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
saimike
Posts: 20
Joined: Wed Apr 11, 2012 10:44 pm

multirow | Several Alignment Problems

Post by saimike »

I am having some alignment issues with using multirow.
  1. How do I get the "Age" columns to center vertically and have the numbers in brackets go to the next line? They don't seem to want to wrap.
  2. Is there a macro I can use to center the "Numbers" column?

Code: Select all

\documentclass{article}
\usepackage{array}
\usepackage{booktabs}
\usepackage{multicol}
\usepackage{multirow}
\usepackage{rotating}

\begin{document}

\begin{sidewaystable}[htbp]
  \centering
  \caption{Add caption}
    \begin{tabular}{p{0.5in} | p{1.25in} | p{0.5in} | p{0.5in} | p{1.25in} | p{0.5in} | p{1.25in} | p{0.5in}}
    \toprule
    Age   & Marital Status & Number & Age   & Education Level & Number & Income & Number \\
    \midrule
    \multirow{4}[8]{*}{20-34 [17]} & Nvr Married & 9     & \multirow{4}[8]{*}{18-24 [6]} & HS or less & 3     & less than \$15,000 & 4 \\ \hline
          & Married & 7     &       & BA (some college) & 2     & \$15k -- \$35k & 21 \\ \hline
          & Divorced/Separated & 1     &       & Graduate & 1     & \$35k -- \$65k & 17 \\ \hline
          & Widowed &       &       &       &       & More than \$65k & 8 \\ \hline
    \multirow{4}[8]{*}{35-44 [12]} & Nvr Married & 2     & \multirow{4}[8]{*}{25-34 [11]} & HS or (some college) & 7     &       &  \\ \hline
          & Married & 8     &       & BA    & 3     &       &  \\ \hline
          & Divorced/Separated & 2     &       & Graduate & 1     & Race  & Number \\ \hline
          & Widowed &       &       &       &       & White & 37 \\ \hline
    \multirow{4}[8]{*}{45-54 [12]} & Nvr Married & 1     & \multirow{4}[8]{*}{35-44 [12]} & HS (some college) & 8     & Black/African American & 6 \\  \hline
          & Married & 8     &       & BA    & 3     & American indian or Alaskan native &  \\  \hline
          & Divorced/Separated & 3     &       & Graduate & 1     & Asian & 2 \\ \hline
          & Widowed &       &       &       &       & Native Hawaiian and Pacific Islander &  \\ \hline
    \multirow{4}[8]{*}{55-64 [9]} & Nvr Married & 0    & \multirow{4}[8]{*}{45-64 [21]} & Some college HS or less & 15    & Hispanic or Latino & 1 \\ \hline
          & Married & 6     &       & BA or higher & 6     & Other & 4 \\ \hline
          & Divorced/Separated & 2     &       &       &       &       &  \\ \hline
          & Widowed & 1     &       &       &       &       &  \\ \hline
		\bottomrule
    \end{tabular}
  \label{tab:sample50}
\end{sidewaystable}

\end{document}

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

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

Re: multirow | Several Alignment Problems

Post by kaiserkarl13 »

1. Change the {*} to {0.5in} for your multirow specifier (using * means "use the natural width of the text").

2. The easiest way is to change your table style from "p{0.5in}" to "c" for the appropriate columns. That's what it's there for. If you don't want that (I can't see why not), read the documentation for the array package about inserting things before/after a column (for example, a \begin{center} command).

You will also want to replace \hline with \cline{2-3}\cline{5-8}, I suspect.
Post Reply