5

I'm using the tabularx and makecell packages for the aesthetics of my tables. I used the X column type for columns with long texts and \makecell{...} for line-breaks into the cells. But when I try to use both together, the effect of the X columns doesn't work.

In the MWE I'd like that the long text um the 3rd line of the 1st row and last column breaks automatically. Any help?

\documentclass{article}
\usepackage{tabularx}
\usepackage{blindtext}
\usepackage{booktabs}
\usepackage{makecell}

\begin{document}

\begin{table}[h]
\footnotesize
\centering
\caption{Table's caption}%
\label{tab:Example}%
\begin{tabularx}{\linewidth}{lcX}%
\toprule
\textbf{Head 1} & \textbf{Head 2}   & \textbf{Head 3} \\
\midrule
Row 1           & 1                 & \makecell[lt]{Line 1\\Line 2\\\blindtext} \\
Row 2           & 2                 & \makecell[lt]{Line 1\\Line 2\\Line 3}     \\
\bottomrule
\end{tabularx}
\end{table}

\end{document}

enter image description here

3
  • 1
    X columns allow line breaks anyway, (\newline or a blank line for a new paragraph) why \makecell ? \makecell is for cases like table headings where you only want forced line breaks and there is no automatic breaking) Commented Feb 20, 2019 at 15:27
  • @DavidCarlisle Sorry. I didn't know that I could do this Commented Feb 20, 2019 at 15:31
  • X columns are just p columns so you can do anything in an X column that you can do in a standard tabular p column. Commented Feb 20, 2019 at 15:36

3 Answers 3

3

You could as well use \makecell[Xt]{...} (though, like @DavidCarlisle said, it doesn't really make sense):

\documentclass{article}
\usepackage{tabularx}
\usepackage{blindtext}
\usepackage{booktabs}
\usepackage{makecell}

\begin{document}

\begin{table}
\footnotesize
\centering
\caption{Table's caption}%
\label{tab:Example}%
\begin{tabularx}{\linewidth}{lcX}%
\toprule
\textbf{Head 1} & \textbf{Head 2}   & \textbf{Head 3} \\
\midrule
Row 1           & 1                 & \makecell[Xt]{Line 1\\Line 2\\\blindtext} \\
Row 2           & 2                 & \makecell[lt]{Line 1\\Line 2\\Line 3}     \\
\bottomrule
\end{tabularx}
\end{table}
\end{document}
2

enter image description here

\documentclass{article}
\usepackage{tabularx}
\usepackage{blindtext}
\usepackage{booktabs}
\usepackage{makecell}

\begin{document}

\begin{table}[htp] % not [h]
\footnotesize
\centering
\caption{Table's caption}%
\label{tab:Example}%
\begin{tabularx}{\linewidth}{lcX}%
\toprule
\textbf{Head 1} & \textbf{Head 2}   & \textbf{Head 3} \\
\midrule
Row 1           & 1                 &
Line 1

Line 2

\blindtext
\\
Row 2           & 2                 &
Line 1

Line 2

Line 3
\\
\bottomrule
\end{tabularx}
\end{table}

\end{document}
0

As @DavidCarlisle says, I used \newline to solve it

\documentclass{article}
\usepackage{tabularx}
\usepackage{blindtext}
\usepackage{booktabs}
\usepackage{makecell}

\begin{document}

\begin{table}[h]
\footnotesize
\centering
\caption{Table's caption}%
\label{tab:Example}%
\begin{tabularx}{\linewidth}{lcX}%
\toprule
\textbf{Head 1} & \textbf{Head 2}   & \textbf{Head 3} \\
\midrule
Row 1           & 1                 & Line 1\newline Line 2\newline\blindtext\\
Row 2           & 2                 & \makecell[lt]{Line 1\\Line 2\\Line 3}     \\
\bottomrule
\end{tabularx}
\end{table}

\end{document}

enter image description here

1
  • why use \makecell in row 2? Commented Feb 20, 2019 at 15:35

You must log in to answer this question.

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