我使用tabularx
和makecell
包来使表格美观。我使用X
列类型来表示包含长文本的列和\makecell{...}
单元格中的换行符。但是当我尝试同时使用两者时,X
列的效果不起作用。
在 MWE 中,我希望长文本第一行第三行最后一列自动断行。有什么帮助吗?
\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}
答案1
您也可以使用\makecell[Xt]{...}
(尽管如@DavidCarlisle 所说,这实际上没有意义):
\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
\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}
答案3
正如@DavidCarlisle所说,我曾经\newline
解决过这个问题
\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}