Latex 表格內的公式實現換行的方法
簡單的兩步走:
- 1.先將下面的語句放在latex正文的導言區:
\newcommand{\tabincell}[2]{\begin{tabular}{@{}#1@{}}#2\end{tabular}} %放在導言區
- 2.然后在tabular內的格子內使用 \tabincell{c}{} 插入相應內容, 就可以在表格中自動換行
以下為一例子,可直接存為.tex文件編譯運行:
\documentclass[a4paper,12pt]{article}
\begin{document}
%-------------------------------------------------------------------------------------------------
\begin{table}
\newcommand{\tabincell}[2]{\begin{tabular}{@{}#1@{}}#2\end{tabular}} %導言區
\centering
\begin{tabular}{|c|c|c|}
\hline
1 & \tabincell{c}{the first line \\ the next\\the next\\ last} & \tabincell{c}{one \\ one}\\ %換行,單元格內的每個元素用\tabincell{c}{放表格內容}
\hline
2 & \tabincell{c}{hello\\ aha\\ ok \\yes \\en} & \tabincell{c}{two \\ two \\ two} \\
\hline
\end{tabular}
%--------------------------------------------------------------------------------------------------
\caption{longtitle}
\end{table}
\end{document}
結果如下圖:
