0

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

  • 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) – David Carlisle Feb 20 at 15:27
  • @DavidCarlisle Sorry. I didn't know that I could do this – Daniel Valencia C. Feb 20 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. – David Carlisle Feb 20 at 15:36
1

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

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.