正确图像:
LaTeX 的输出:
大家好。有人能帮我解决这个问题吗?我的文字无法换行到表格中,如图 2 所示。
\documentclass{article}
\usepackage{array}
\newcolumntype{L}{>{\centering\arraybackslash}m{3cm}}
\begin{document}
\begin{table}
\begin{tabular}{|c|c|L|L|}\hline
$A$ & $B$ & $A.B$ & $B.A$\\\hline
$\{x^2,x^3,y,xy\}$ & \{$1,x,x^2y,x^3y\}$ & $\{x^2,x^3,y,xy,x^3,1,xy,x^2y,y,x^3y,x^2,x,xy,y,x^3,x^2\}$ & $\{x^2,x^3,y,xy,x^3,1,xy,x^2y,y,x^3y,x^2,x,xy,y,x^3,x^2\}$ \\ \hline
\end{tabular}
\end{table}
\end{document}
这是我的乳胶代码。
感谢您的帮助。
答案1
以下两个解决方案使用tabularx
环境来消除对第 3 列和第 4 列宽度的无意义猜测。这两个解决方案都使用了一个名为 的宏\breakingcomma
,该宏来自先前的答案由@egreg 编写,允许 TeX 在逗号后立即断行。
前一种解决方案使用您设置的垂直和水平规则;第二种解决方案不使用垂直规则,只使用间距适当的水平规则。
\documentclass{article}
\usepackage{tabularx,booktabs,ragged2e,breqn}
\renewcommand{\tabularxcolumn}[1]{m{#1}}
\newcolumntype{C}{>{\Centering\arraybackslash$}X<{$}}
\usepackage[skip=0.333\baselineskip]{caption}
% see https://tex.stackexchange.com/a/60761/5001 for source of \breakingcomma
% (requires the "breqn" package; that's why it's loaded above)
\newcommand{\breakingcomma}{%
\begingroup\lccode`~=`,
\lowercase{\endgroup\expandafter\def\expandafter~\expandafter{~\penalty0 }}}
\begin{document}
\begin{table}
\caption{Using both vertical and horizontal rules}
\breakingcomma
\begin{tabularx}{\textwidth}{|*{2}{>{$}c<{$}|}*{2}{C|}}
\hline
A & B & A.B & B.A\\
\hline
\{x^2,x^3,y,xy\} &
\{1,x,x^2y,x^3y\} &
\{x^2,x^3,y,xy,x^3,1,xy,x^2y,y,x^3y,x^2,x,xy,y,x^3,x^2\} &
\{x^2,x^3,y,xy,x^3,1,xy,x^2y,y,x^3y,x^2,x,xy,y,x^3,x^2\} \\ \hline
\end{tabularx}
\end{table}
\begin{table}[h]
\caption{Using only well-spaced horizontal rules}
\breakingcomma
\begin{tabularx}{\textwidth}{@{}*{2}{>{$}c<{$}}*{2}{C}@{}}
\toprule
A & B & A.B & B.A\\
\midrule
\{x^2,x^3,y,xy\} &
\{1,x,x^2y,x^3y\} &
\{x^2,x^3,y,xy,x^3,1,xy,x^2y,y,x^3y,x^2,x,xy,y,x^3,x^2\} &
\{x^2,x^3,y,xy,x^3,1,xy,x^2y,y,x^3y,x^2,x,xy,y,x^3,x^2\} \\
\bottomrule
\end{tabularx}
\end{table}
\end{document}
答案2
尝试这个:
\documentclass{article}
\usepackage{array}
\newcolumntype{L}{>{\raggedright\arraybackslash}p{3cm}}
\begin{document}
\begin{tabular}{|l|l|L|L|}
\hline
$A$ & $B$ & $A.B$ & $B.A$\\
\hline
$\{x^2$, $x^3$, $y$, $xy\}$ &
\{$1$, $x$, $x^2y$, $x^3y\}$ &
$\{x^2$, $x^3$, $y$, $xy$, $x^3$, $1$, $xy$, $x^2y$, $y$, $x^3y$, $x^2$, $x$, $xy$, $y$, $x^3$, $x^2\}$ &
$\{x^2$, $x^3$, $y$, $xy$, $x^3$, $1$, $xy$, $x^2y$, $y$, $x^3y$, $x^2$, $x$, $xy$, $y$, $x^3$, $x^2\}$ \\
\hline
\end{tabular}
\end{document}
答案3
您可以像这样使用包内split
的环境:amsmath
minipage
\documentclass{article}
\usepackage{array,tabularx,amsmath}
\newcolumntype{C}{>{\centering\arraybackslash}X}
\begin{document}
\begin{table}
\begin{tabularx}{\linewidth}{|c|c|C|C|}\hline
$A$ & $B$ & $A.B$ & $B.A$\\ \hline
$\{x^2,x^3,y,xy\}$ & \{$1,x,x^2y,x^3y\}$ &
\begin{minipage}{\linewidth}
\[\begin{split}
\lbrace x^2,x^3,y,xy,x^3,1, \\
xy,x^2y,y,x^3y,x^2, \\
x,xy,y,x^3,x^2\rbrace
\end{split}\]
\end{minipage}
&
\begin{minipage}{\linewidth}
\[\begin{split}
\lbrace x^2,x^3,y,xy,x^3,1, \\
xy,x^2y,y,x^3y,x^2, \\
x,xy,y,x^3,x^2 \rbrace
\end{split}\]
\end{minipage} \\ \hline
\end{tabularx}
\end{table}
\end{document}