![需要将文本换行到一列中](https://linux22.com/image/390201/%E9%9C%80%E8%A6%81%E5%B0%86%E6%96%87%E6%9C%AC%E6%8D%A2%E8%A1%8C%E5%88%B0%E4%B8%80%E5%88%97%E4%B8%AD.png)
列内的某些文本应该换到下一行,但是从下面的代码中我看到,文本长度太大,会干扰最右边的列。
\documentclass[conference]{IEEEtran}
\IEEEoverridecommandlockouts
\usepackage{array}
\usepackage{ragged2e}
\usepackage{multirow}
\begin{document}
The table \ref{label1}
\begin{table}
\centering
\caption{my table}
\label{label1}
\begin{tabular}{ |l|p{4cm}|p{1cm}| }
\hline
A & B & C \\
\hline
\multirow{3}{*}{Gromacs} & \texttt{aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa} & 62\% \\
& \texttt{bbbbbb} & 15 \% \\
& \texttt{cccccccccccccccccccccccccccccc} & 10\% \\
\hline
\end{tabular}
\end{table}
\end{document}
输出如下所示
答案1
这是一个解决方案,使用tabularx
和xurl
。我添加了一个变体,它可以自动在整个列中进行自动换行,以防第二列中的所有单元格(列标题除外)都应以这种方式输入,使用包collcell
。
\documentclass[conference]{IEEEtran}
\IEEEoverridecommandlockouts
\usepackage{tabularx}
\usepackage{seqsplit}
\usepackage{xurl, collcell}
\newcolumntype{U}{>{\collectcell\url}X <{\endcollectcell}}
\usepackage{multirow}
\AtBeginDocument{\def\UrlFont{\tt}}
\begin{document}
\noindent Some text. Some more text. Some more text. Some more text. Some more text. Some more text. Some more text. Some more text. Some more text.
The table \ref{label1}
\begin{table}[!h]
\centering%
\setlength{\extrarowheight}{2pt}
\caption{my table}
\label{label1}
\begin{tabularx}{\columnwidth}{ |l|U|l| }
\hline
A & \multicolumn{1}{l}{B }& C \\
\hline
\multirow{3}{*}{Gromacs} & aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa & 62\% \\
& non_bonded_Elec_uiF_pos_non_bonded_Elec_uiF_pos & 15 \% \\
& cccccccccccccccccccccccccccccc & 10\% \\
\hline
\end{tabularx}
\end{table}
\noindent Some text. Some more text. Some more text. Some more text. Some more text. Some more text. Some more text. Some more text. Some more text.
\begin{table}[!h]
\centering%
\setlength{\extrarowheight}{2pt}
\caption{my table}
\label{label1a}
\begin{tabularx}{\columnwidth}{ |l|X|l| }
\hline
A & B & C \\
\hline
\multirow{3}{*}{Gromacs} & \url{aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa}& 62\% \\
& \url{non_bonded_Elec_uiF_pos_non_bonded_Elec_uiF_pos} & 15 \% \\
& \url{cccccccccccccccccccccccccccccc} & 10\% \\
\hline
\end{tabularx}
\end{table}
noindent Some text. Some more text. Some more text. Some more text. Some more text. Some more text. Some more text. Some more text. Some more text.
\end{document}