1

I'm trying to make a table in which several columns contain long text, or at least multiple-line text, and can't seem to figure it out.

I've experimented with using p{width}, tabularx and \makecell, but each one has a problem. \makecell seems ideal as I can add the new lines when I want. However, it doesn't seem to do automatic line breaking when that's required. Conversely, tabularx and p{width} automatically break the lines but don't allow for manual paragraphing within the cell.

\begin{center}
\begin{tabularx}{\linewidth}{ | X | X | X | X |}
  \hline
  \thead{Heading.} & \thead{Heading} & \thead{Heading} & \thead{Heading} \\
  \hline
  S1 &  \makecell[cl]{Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text .  More text text text text. More text text text text text text}  & Text text text & lots of words here, maybe some loooooooooooong words \\
  \hline
\end{tabularx}
\end{center}

This gives the image below: Compiled code

I've made roughly what I'm trying to achieve in Word and attached it here. Using \vspace within the column combined with tabularx kind of works, but seems to put the space in a random place.

Example table

I don't mind if the long text ends up in a narrow column with only a few words per line, essentially I just need to be able to insert spaces between paragraphs/lines. Apologies if there is an easy solution, I've not had to do anything like this before. Am I missing something with these commands, or is there an elegant way of doing it?

2
  • Welcome. // Please add what‘s needed to copy and compile your code, esp. the packages you use.
    – MS-SPO
    Commented Sep 1, 2022 at 11:25
  • Thanks. Please move it to your question.
    – MS-SPO
    Commented Sep 1, 2022 at 11:37

1 Answer 1

0

You could imitate paragraphs like this:

\documentclass{article}

\usepackage{tabularx}
\usepackage{makecell}

\begin{document}

\begin{center}
\begin{tabularx}{\linewidth}{ | X | X | X | X |}
  \hline
  \thead{Heading.} & \thead{Heading} & \thead{Heading} & \thead{Heading} \\
  \hline
  S1 &  Text Text Text Text\medskip\newline  Text Text Text Text Text Text Text Text Text Text Text Text.  More text text text text. More text text text text text text  & Text text text & lots of words here, maybe some loooooooooooong words \\
  \hline
\end{tabularx}
\end{center}

\end{document}

An alternative using the tabularray package:

\documentclass{article}

\usepackage{tabularray}

\begin{document}

\begin{center}
\begin{tblr}{
  colspec={| X | X | X | X[l] |},
  hlines,
  row{1}={halign=c}
}
  Heading. & Heading & Heading & Heading \\
  S1 &  Text Text Text Text\medskip\par  Text Text Text Text Text Text Text Text Text Text Text Text.\medskip\par  More text text text text. More text text text text text text  & Text text text & lots of words here, maybe some loooooooooooong words \\
\end{tblr}
\end{center}

\end{document}
2

You must log in to answer this question.

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