0

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
\def\arraystretch{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}
3
  • Do you not need to define the last column in the other two rows for the multirow one to be able to stretch through them? I.e. put & after B3 and C3? – Plergux Oct 11 '20 at 11:27
  • Waht exactly does "stretch until the end of the page and fit in the page margin" exactly mean here? Unless your textwidth is quite small, the table should already be narrower than the textwidth. Please clarify. Please also make your code compilable by adding the documentclass as well as the relevant packages to your example code. – leandriis Oct 11 '20 at 11:29
  • Regarding the top alignment, you could use the t option as follows. Also, you can replace * with = in order to allow the contents of the multirow to adapt to the width of the surrounding column. With * the multirow cell is as wide as its contents, resulting in an overflow into the right margin if your contents are quite long. \multirow[t]{3}{=}. – leandriis Oct 11 '20 at 11:32
1

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
{\def\arraystretch{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
{\def\arraystretch{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

2
  • Thank you, Mr leandriis, the text now fits inside the multirow cell. However, it is displayed left aligned and I wish it justified. How could I fix that? – TylerD007 Oct 11 '20 at 11:38
  • @TylerD007: I have updated my answer to show an alternative based on nested tabulars instead of \multirow. – leandriis Oct 11 '20 at 11:47
2

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
    \renewcommand\multirowsetup{}
    \def\arraystretch{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)

2
  • Thank you, Mr Zarko, the text now fits inside the multirow cell. However, it is displayed left aligned and I wish it justified. How could I fix that? – TylerD007 Oct 11 '20 at 11:41
  • @TylerD007, see edited answer! – Zarko Oct 11 '20 at 12:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.