我使用tabularx
和makecell
包包來提高我的桌子的美觀。我將X
列類型用於具有長文字的列以及\makecell{...}
單元格中的換行符。但是當我嘗試同時使用兩者時,列的效果X
不起作用。
在 MWE 中,我希望長文 um 第一行和最後一列的第三行自動中斷。有什麼幫助嗎?
\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}