TransWikia.com

tabularx and multirow

TeX - LaTeX Asked by TylerD007 on December 19, 2020

I’m trying to create a pretty straightforward table with tabularx that should look like this:

A1 A2 A3 MULTIROW
B1 B2 B3
C1 C2 C3

My problem is that I can’t make the text in the multirow cell fit inside the page margin (the text is printed in one single line and does not respect the cell width). Also, I want the text top aligned and not centered. Here is my code:

begin{flushleft}
begingroup
defarraystretch{1.5}
begin{tabularx}{textwidth}{c l l X}
A1 & A2 & A3 & multirow{3}{*}{multirow text}
B1 & B2 & B3 
C1 & C2 & C3 
end{tabularx}
endgroup
end{flushleft}

2 Answers

From your description, I guess you are interested in

  • the t option to top align the contents of the multirow: multirow[t]{3}...

in combination with

  • = instead of * to make sure the width if the multirow cell adapts to the width of the column it is used inside of instead of adapting to the width of its contents: multirow[t]{3}{=}...

Combined into a MWE, this could look like the following:

documentclass{article}
usepackage{tabularx}
usepackage{multirow}
begin{document}

noindent
{defarraystretch{1.5}%
begin{tabularx}{textwidth}{c l l X}
A1 & A2 & A3 & multirow[t]{3}{=}{multirow text multirow text multirow text multirow text multirow text multirow text multirow text}
B1 & B2 & B3 &
C1 & C2 & C3 &
end{tabularx}
}

end{document}

enter image description here


With a nested tabular instead of multirow:

documentclass{article}
usepackage{tabularx}
usepackage{lipsum}
begin{document}

noindent
{defarraystretch{1.5}%
begin{tabularx}{textwidth}{l X}
begin{tabular}[t]{@{}c l l@{}} A1 & A2 & A3 
                           B1 & B2 & B3 
                           C1 & C2 & C3 
end{tabular} & lipsum[1][1-4]
end{tabularx}
}


end{document}

enter image description here

Correct answer by leandriis on December 19, 2020

It is not clear what is your problem, Probably you looking for something like this:

documentclass{article}

usepackage{lipsum}    % for text filler

usepackage{multirow, 
            tabularx}

begin{document}
begingroup
    flushleft
    renewcommandmultirowsetup{}
    defarraystretch{1.5}
begin{tabularx}{textwidth}{c l l X}
A1 & A2 & A3 & multirow[t]{3}{=}{lipsum[1][1-3]}
B1 & B2 & B3 
C1 & C2 & C3 
end{tabularx}
endgroup
end{document}

Note:

  • since you have short text in the last column, you not see that table is stretched to right text border
  • this will be visible, if you column specification would contain vertical lines: begin{tabularx}{textwidth}{|c | l | l | X|}
  • In case, that multirow cells contain longer text, it can be automatic split into more lines, if you use (relatively new) specification multirow[t]{3}{=}{...} as it already mention @leandriis in his comment.

Edit:

  • Default settings for multirow cells is raggedright
  • If you like to change this, you need to renew command multirowsetup, see edited MWE below

enter image description here

(red lines show text borders)

Answered by Zarko on December 19, 2020

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP