0

Dear experienced friends, I am trying to insert a long paragraph into my table. However, I found that no matter I used the p as paragraph or used c, the text cannot be wrapped beautifully. I hope the context can:

  • The words are left aligned.
  • The whole paragraph is in the center&left of the cell.
  • The length of the cell is fixed. (I used w{c}{30mm} but it doesn't work.)

Could you mind giving me some hints? Thank you so much!


Here is my code:

\begin{table}[htbp!]
\caption{Set the content in the middle center of the table}
\centering
\def\arraystretch{1.1}

\begin{tabular}{*{1}{p{30mm}}*{5}{w{c}{10mm}}}

\toprule
\multicolumn{2}{c}{Content} & A & B & C & D \\ [1ex]
 
\midrule
\multicolumn{2}{c}{The content} & & & & \\ [0.5ex]

\cmidrule(lr){1-2}
\multirow{9}{2em}{Here is the text contect that I want to beautifully aligned in the middle center} & A & 0 & 0 & 0 & 0 \\ [0.5ex]
 & A & 0 & 0 & 0 & 0 \\ [0.5ex]
 & A & 0 & 0 & 0 & 0 \\ [0.5ex]
 & A & 0 & 0 & 0 & 0 \\ [0.5ex]
 & A & 0 & 0 & 0 & 0 \\ [0.5ex]
 & A & 0 & 0 & 0 & 0 \\ [0.5ex]
 & A & 0 & 0 & 0 & 0 \\ [0.5ex]
 & A & 0 & 0 & 0 & 0 \\ [0.5ex]
 & A & 0 & 0 & 0 & 0 \\ [0.5ex]

\bottomrule
\end{tabular}

\label{table_main}
\end{table}

Here is what I try to achieve:

enter image description here

And sadly here is what my code can achieve:

enter image description here

5
  • 1
    Replace \multirow{9}{2em} with \multirow{9}{=} since the first column is 30 mm wide
    – Bernard
    Commented Jul 18, 2022 at 17:00
  • @Bernard You are my hero man! Can't believe I ignore this. And the problem is already solved! Thanks a lot! Commented Jul 18, 2022 at 17:04
  • 1
    You're welcome. Always glad when I can help!
    – Bernard
    Commented Jul 18, 2022 at 17:08
  • 1
    You just need to increase a length specified as the second argument of \multirow. 2em is I think an equivalent of two letters m; I guess it's about 1cm. By default, the second argument is usually given as * or = (see documentation)
    – Celdor
    Commented Jul 18, 2022 at 17:10
  • Thank you for the ref @Celdor. Very helpful! Commented Jul 18, 2022 at 17:42

2 Answers 2

2

If you ask to use a textwidth of 2em, TeX will do it. When the \multirow material is in a “fixed width“ column, use = instead.

Don't pollute your table with \\[0.5ex].

\documentclass{article}
\usepackage{array,booktabs}
\usepackage{multirow}

\begin{document}

\begin{table}[htbp!]
\centering
\renewcommand{\arraystretch}{1.1}

\caption{Set the content in the middle center of the table}
\label{table_main}

\medskip % or set the caption below, or load caption

\begin{tabular}{*{1}{p{30mm}}*{5}{w{c}{10mm}}}

\toprule
\multicolumn{2}{c}{Content} & A & B & C & D \\
 
\midrule
\multicolumn{2}{c}{The content} & & & & \\ 

\cmidrule(r){1-2}
\multirow{9}{=}{Here is the text contect that I want to beautifully aligned in the middle center} & A & 0 & 0 & 0 & 0 \\ 
 & A & 0 & 0 & 0 & 0 \\ 
 & A & 0 & 0 & 0 & 0 \\ 
 & A & 0 & 0 & 0 & 0 \\ 
 & A & 0 & 0 & 0 & 0 \\ 
 & A & 0 & 0 & 0 & 0 \\ 
 & A & 0 & 0 & 0 & 0 \\ 
 & A & 0 & 0 & 0 & 0 \\ 
 & A & 0 & 0 & 0 & 0 \\ 

\bottomrule
\end{tabular}

\end{table}

\end{document}

enter image description here

Some points to note.

  1. The standard classes are set up for captions below tables. So either add some vertical space or load caption that changes the parameters for captions above tables.

  2. The label should go after (or inside) the \caption. Placing it after the tabular will make document maintenance more difficult.

  3. Polluting the tabular with \\[0.5ex] makes it impossible for \multirow to guess the right placement; use \arraystretch and never do \def.

  4. (Most important.) I'm not a fan of \multirow and I always look for ways to do without it. In this particular case, it seems that the text is some explanation common for all the rows. As such it should go outside the table. For instance below it, so the text width can be more generous and readers will have less hard time in parsing it.

\documentclass{article}
\usepackage{array,booktabs}
\usepackage{multirow}

\begin{document}

\begin{table}[htbp!]
\centering
\renewcommand{\arraystretch}{1.1}

\caption{Set the content in the middle center of the table}
\label{table_main}

\medskip % or set the caption below, or load caption

\begin{tabular}{*{5}{w{c}{10mm}}}

\toprule
Content & A & B & C & D \\
 
\midrule
 A & 0 & 0 & 0 & 0 \\ 
 A & 0 & 0 & 0 & 0 \\ 
 A & 0 & 0 & 0 & 0 \\ 
 A & 0 & 0 & 0 & 0 \\ 
 A & 0 & 0 & 0 & 0 \\ 
 A & 0 & 0 & 0 & 0 \\ 
 A & 0 & 0 & 0 & 0 \\ 
 A & 0 & 0 & 0 & 0 \\ 
 A & 0 & 0 & 0 & 0 \\ 

\midrule[\heavyrulewidth]

\multicolumn{5}{@{}p{\dimexpr50mm+10\tabcolsep}@{}}{
  Here is the text contect that I want to beautifully aligned in the middle center}

\end{tabular}

\end{table}

\end{document}

enter image description here

1
  • So excellent and comprehensive answer. I really appreciate your solution as well as your suggestions for a beautiful table! Very helpful! Commented Jul 19, 2022 at 17:35
2

Sorry, but it is not entirely clear how should your table looks 😒. I guess that it may be something like this:

enter image description here

In MWE, which produce above table I use tabularray package:

\documentclass{article}
\usepackage[skip=1ex]{caption}
\usepackage{tabularray}
%\UseTblrLibrary{booktabs}

\begin{document}
\begin{table}[htbp!]
\caption{Set the content in the middle center of the table}
\centering

\begin{tblr}{hlines, vlines,
             colspec={Q[j, wd=33mm] *{5}{Q[c,m]}}}
%    \toprule
\SetCell[c=2]{c}{Content}   &   & A & B & C & D     \\ 
%    \midrule
\SetCell[r=9]{m}    Here is the text content that I want to beautifully aligned in the middle center
                            & A & 0 & 0 & 0 & 0 \\
                            & A & 0 & 0 & 0 & 0 \\
                            & A & 0 & 0 & 0 & 0 \\
                            & A & 0 & 0 & 0 & 0 \\
                            & A & 0 & 0 & 0 & 0 \\
                            & A & 0 & 0 & 0 & 0 \\
                            & A & 0 & 0 & 0 & 0 \\
                            & A & 0 & 0 & 0 & 0 \\
                            & A & 0 & 0 & 0 & 0 \\
%    \bottomrule
\end{tblr}
\label{table_main}
    \end{table}
\end{document}

Addendum or something like the following:

enter image description here

\documentclass{article}
\usepackage[skip=1ex]{caption}
\usepackage{tabularray}
\UseTblrLibrary{booktabs}

\begin{document}
\begin{table}[htbp!]
\caption{Set the content in the middle center of the table}
\centering

\begin{tblr}{colspec={Q[l, wd=32mm] *{5}{Q[c, wd=10mm]}}}
    \toprule
\SetCell[c=2]{c}{The Content}   &   & A & B & C & D \\
    \cmidrule[r]{1-2}\cmidrule[l]{3-6}
\SetCell[r=9]{m}    Here is the text content that I want to beautifully aligned in the middle center
                                & A & 0 & 0 & 0 & 0 \\
                                & A & 0 & 0 & 0 & 0 \\
                                & A & 0 & 0 & 0 & 0 \\
                                & A & 0 & 0 & 0 & 0 \\
                                & A & 0 & 0 & 0 & 0 \\
                                & A & 0 & 0 & 0 & 0 \\
                                & A & 0 & 0 & 0 & 0 \\
                                & A & 0 & 0 & 0 & 0 \\
                                & A & 0 & 0 & 0 & 0 \\
    \bottomrule
\end{tblr}
\label{table_main}
    \end{table}

\end{document}
1
  • Thank you for your reply! Yes I found that using = can perfectly solve all the problems. But your answer offers a brand new way to organize table. Really appreciate! Commented Jul 19, 2022 at 17:33

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .